1 | // |
2 | // Redistribution and use in source and binary forms, with or without |
3 | // modification, are permitted provided that the following conditions |
4 | // are met: |
5 | // * Redistributions of source code must retain the above copyright |
6 | // notice, this list of conditions and the following disclaimer. |
7 | // * Redistributions in binary form must reproduce the above copyright |
8 | // notice, this list of conditions and the following disclaimer in the |
9 | // documentation and/or other materials provided with the distribution. |
10 | // * Neither the name of NVIDIA CORPORATION nor the names of its |
11 | // contributors may be used to endorse or promote products derived |
12 | // from this software without specific prior written permission. |
13 | // |
14 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY |
15 | // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
16 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
17 | // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
18 | // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
19 | // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
20 | // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
21 | // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
22 | // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
23 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
24 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
25 | // |
26 | // Copyright (c) 2008-2021 NVIDIA Corporation. All rights reserved. |
27 | // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved. |
28 | // Copyright (c) 2001-2004 NovodeX AG. All rights reserved. |
29 | |
30 | |
31 | #ifndef PX_PHYSICS_CONSTRAINTCORE |
32 | #define PX_PHYSICS_CONSTRAINTCORE |
33 | |
34 | #include "CmPhysXCommon.h" |
35 | #include "PxConstraintDesc.h" |
36 | #include "PsAllocator.h" |
37 | #include "PxConstraint.h" |
38 | |
39 | namespace physx |
40 | { |
41 | |
42 | class PxConstraint; |
43 | |
44 | namespace Sc |
45 | { |
46 | class ConstraintCore; |
47 | class ConstraintSim; |
48 | class RigidCore; |
49 | |
50 | |
51 | class ConstraintCore : public Ps::UserAllocated |
52 | { |
53 | //= ATTENTION! ===================================================================================== |
54 | // Changing the data layout of this class breaks the binary serialization format. See comments for |
55 | // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData |
56 | // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION |
57 | // accordingly. |
58 | //================================================================================================== |
59 | public: |
60 | // PX_SERIALIZATION |
61 | ConstraintCore(const PxEMPTY) : mFlags(PxEmpty), mConnector(NULL), mSim(NULL) {} |
62 | PX_FORCE_INLINE void setConstraintFunctions(PxConstraintConnector& n, |
63 | const PxConstraintShaderTable& shaders) |
64 | { |
65 | mConnector = &n; |
66 | mSolverPrep = shaders.solverPrep; |
67 | mProject = shaders.project; |
68 | mVisualize = shaders.visualize; |
69 | } |
70 | static void getBinaryMetaData(PxOutputStream& stream); |
71 | //~PX_SERIALIZATION |
72 | ConstraintCore(PxConstraintConnector& connector, const PxConstraintShaderTable& shaders, PxU32 dataSize); |
73 | ~ConstraintCore(); |
74 | |
75 | // The two-step protocol here allows us to unlink the constraint prior to deleting |
76 | // the actors when synchronizing the scene, then set the bodies after new actors have been inserted |
77 | |
78 | void prepareForSetBodies(); |
79 | void setBodies(RigidCore* r0v, RigidCore* r1v); |
80 | |
81 | PxConstraint* getPxConstraint(); |
82 | const PxConstraint* getPxConstraint() const; |
83 | PX_FORCE_INLINE PxConstraintConnector* getPxConnector() const { return mConnector; } |
84 | |
85 | PX_FORCE_INLINE PxConstraintFlags getFlags() const { return mFlags; } |
86 | void setFlags(PxConstraintFlags flags); |
87 | |
88 | void getForce(PxVec3& force, PxVec3& torque) const; |
89 | |
90 | bool updateConstants(void* addr); |
91 | |
92 | void setBreakForce(PxReal linear, PxReal angular); |
93 | void getBreakForce(PxReal& linear, PxReal& angular) const; |
94 | |
95 | void setMinResponseThreshold(PxReal threshold); |
96 | PxReal getMinResponseThreshold() const { return mMinResponseThreshold; } |
97 | |
98 | void breakApart(); |
99 | |
100 | PX_FORCE_INLINE PxConstraintVisualize getVisualize() const { return mVisualize; } |
101 | PX_FORCE_INLINE PxConstraintProject getProject() const { return mProject; } |
102 | PX_FORCE_INLINE PxConstraintSolverPrep getSolverPrep() const { return mSolverPrep; } |
103 | PX_FORCE_INLINE PxU32 getConstantBlockSize() const { return mDataSize; } |
104 | |
105 | PX_FORCE_INLINE void setSim(ConstraintSim* sim) |
106 | { |
107 | PX_ASSERT((sim==0) ^ (mSim == 0)); |
108 | mSim = sim; |
109 | } |
110 | PX_FORCE_INLINE ConstraintSim* getSim() const { return mSim; } |
111 | private: |
112 | PxConstraintFlags mFlags; |
113 | PxU16 mPaddingFromFlags; // PT: because flags are PxU16 |
114 | |
115 | PxVec3 mAppliedForce; |
116 | PxVec3 mAppliedTorque; |
117 | |
118 | PxConstraintConnector* mConnector; |
119 | PxConstraintProject mProject; |
120 | PxConstraintSolverPrep mSolverPrep; |
121 | PxConstraintVisualize mVisualize; |
122 | PxU32 mDataSize; |
123 | PxReal mLinearBreakForce; |
124 | PxReal mAngularBreakForce; |
125 | PxReal mMinResponseThreshold; |
126 | |
127 | ConstraintSim* mSim; |
128 | }; |
129 | |
130 | } // namespace Sc |
131 | |
132 | } |
133 | |
134 | #endif |
135 | |