RavEngine
Loading...
Searching...
No Matches
NpRigidDynamic.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#ifndef NP_RIGID_DYNAMIC_H
30#define NP_RIGID_DYNAMIC_H
31
32#include "common/PxMetaData.h"
33#include "PxRigidDynamic.h"
34#include "NpRigidBodyTemplate.h"
35
36namespace physx
37{
38typedef NpRigidBodyTemplate<PxRigidDynamic> NpRigidDynamicT;
39
41{
42//= ATTENTION! =====================================================================================
43// Changing the data layout of this class breaks the binary serialization format. See comments for
44// PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
45// function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
46// accordingly.
47//==================================================================================================
48public:
49// PX_SERIALIZATION
50 NpRigidDynamic(PxBaseFlags baseFlags) : NpRigidDynamicT(baseFlags) {}
51
52 void preExportDataReset();
53 virtual void requiresObjects(PxProcessPxBaseCallback& c);
54
55 static NpRigidDynamic* createObject(PxU8*& address, PxDeserializationContext& context);
56 static void getBinaryMetaData(PxOutputStream& stream);
57//~PX_SERIALIZATION
58 virtual ~NpRigidDynamic();
59
60 //---------------------------------------------------------------------------------
61 // PxActor implementation
62 //---------------------------------------------------------------------------------
63
64 virtual void release() PX_OVERRIDE;
65
66 //---------------------------------------------------------------------------------
67 // PxRigidDynamic implementation
68 //---------------------------------------------------------------------------------
69
70 virtual PxActorType::Enum getType() const PX_OVERRIDE { return PxActorType::eRIGID_DYNAMIC; }
71
72 // Pose
73 virtual void setGlobalPose(const PxTransform& pose, bool autowake) PX_OVERRIDE;
74
75 PX_FORCE_INLINE PxTransform getGlobalPoseFast() const
76 {
77 const Sc::BodyCore& body = getCore();
78 return body.getBody2World() * body.getBody2Actor().getInverse();
79 }
80 virtual PxTransform getGlobalPose() const PX_OVERRIDE
81 {
82 NP_READ_CHECK(getNpScene());
83 PX_CHECK_SCENE_API_READ_FORBIDDEN_EXCEPT_COLLIDE_AND_RETURN_VAL(getNpScene(), "PxRigidDynamic::getGlobalPose() not allowed while simulation is running (except during PxScene::collide()).", PxTransform(PxIdentity));
84 return getGlobalPoseFast();
85 }
86
87 virtual void setKinematicTarget(const PxTransform& destination) PX_OVERRIDE;
88 virtual bool getKinematicTarget(PxTransform& target) const PX_OVERRIDE;
89
90 // Center of mass pose
91 virtual void setCMassLocalPose(const PxTransform&) PX_OVERRIDE;
92
93 // Velocity
94 virtual void setLinearVelocity(const PxVec3&, bool autowake) PX_OVERRIDE;
95 virtual void setAngularVelocity(const PxVec3&, bool autowake) PX_OVERRIDE;
96
97 // Force/Torque modifiers
98 virtual void addForce(const PxVec3&, PxForceMode::Enum mode, bool autowake) PX_OVERRIDE;
99 virtual void clearForce(PxForceMode::Enum mode) PX_OVERRIDE;
100 virtual void addTorque(const PxVec3&, PxForceMode::Enum mode, bool autowake) PX_OVERRIDE;
101 virtual void clearTorque(PxForceMode::Enum mode) PX_OVERRIDE;
102 virtual void setForceAndTorque(const PxVec3& force, const PxVec3& torque, PxForceMode::Enum mode = PxForceMode::eFORCE) PX_OVERRIDE;
103
104 // Sleeping
105 virtual bool isSleeping() const PX_OVERRIDE;
106 virtual PxReal getSleepThreshold() const PX_OVERRIDE;
107 virtual void setSleepThreshold(PxReal threshold) PX_OVERRIDE;
108 virtual PxReal getStabilizationThreshold() const PX_OVERRIDE;
109 virtual void setStabilizationThreshold(PxReal threshold) PX_OVERRIDE;
110 virtual void setWakeCounter(PxReal wakeCounterValue) PX_OVERRIDE;
111 virtual PxReal getWakeCounter() const PX_OVERRIDE;
112 virtual void wakeUp() PX_OVERRIDE;
113 virtual void putToSleep() PX_OVERRIDE;
114
115 virtual void setSolverIterationCounts(PxU32 positionIters, PxU32 velocityIters) PX_OVERRIDE;
116 virtual void getSolverIterationCounts(PxU32 & positionIters, PxU32 & velocityIters) const PX_OVERRIDE;
117
118 virtual void setContactReportThreshold(PxReal threshold) PX_OVERRIDE;
119 virtual PxReal getContactReportThreshold() const PX_OVERRIDE;
120
121 virtual PxRigidDynamicLockFlags getRigidDynamicLockFlags() const PX_OVERRIDE;
122 virtual void setRigidDynamicLockFlags(PxRigidDynamicLockFlags flags) PX_OVERRIDE;
123 virtual void setRigidDynamicLockFlag(PxRigidDynamicLockFlag::Enum flag, bool value) PX_OVERRIDE;
124
125 //---------------------------------------------------------------------------------
126 // Miscellaneous
127 //---------------------------------------------------------------------------------
128 NpRigidDynamic(const PxTransform& bodyPose);
129
130 virtual void switchToNoSim() PX_OVERRIDE;
131 virtual void switchFromNoSim() PX_OVERRIDE;
132
133 PX_FORCE_INLINE void wakeUpInternal();
134 void wakeUpInternalNoKinematicTest(bool forceWakeUp, bool autowake);
135
136 static PX_FORCE_INLINE size_t getCoreOffset() { return PX_OFFSET_OF_RT(NpRigidDynamic, mCore); }
137 static PX_FORCE_INLINE size_t getNpShapeManagerOffset() { return PX_OFFSET_OF_RT(NpRigidDynamic, mShapeManager); }
138
139#if PX_CHECKED
140 PX_FORCE_INLINE bool checkConstraintValidity() const { return true; }
141#endif
142
143private:
144 PX_FORCE_INLINE void setKinematicTargetInternal(const PxTransform& destination);
145
146#if PX_ENABLE_DEBUG_VISUALIZATION
147public:
148 void visualize(PxRenderOutput& out, NpScene& scene, float scale) const;
149#else
150 PX_CATCH_UNDEFINED_ENABLE_DEBUG_VISUALIZATION
151#endif
152};
153
154PX_FORCE_INLINE void NpRigidDynamic::wakeUpInternal()
155{
156 PX_ASSERT(getNpScene());
157
158 const Sc::BodyCore& body = getCore();
159
160 const PxRigidBodyFlags currentFlags = body.getFlags();
161
162 if (!(currentFlags & PxRigidBodyFlag::eKINEMATIC)) // kinematics are only awake when a target is set, else they are asleep
163 wakeUpInternalNoKinematicTest(false, true);
164}
165
166
167}
168
169#endif
Definition base.h:1940
Definition NpRigidBodyTemplate.h:80
Definition NpRigidDynamic.h:41
Definition NpScene.h:130
Binary deserialization context class.
Definition PxSerialFramework.h:174
Output stream class for I/O.
Definition PxIO.h:114
Callback class used to process PxBase objects.
Definition PxSerialFramework.h:81
Definition PxRenderOutput.h:50
class representing a rigid euclidean transform as a quaternion and a vector
Definition PxTransform.h:49
3 Element vector class.
Definition PxVec3.h:50
Definition ScBodyCore.h:49
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
#define PX_OVERRIDE
Definition PxPreprocessor.h:375
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
Enum
Definition PxActor.h:121
@ eRIGID_DYNAMIC
A dynamic rigid body.
Definition PxActor.h:132
Enum
Definition PxForceMode.h:51
@ eFORCE
parameter has unit of mass * length / time^2, i.e., a force
Definition PxForceMode.h:52
@ eKINEMATIC
Enables kinematic mode for the actor.
Definition PxRigidBody.h:74