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 | #ifndef PX_PHYSICS_NX_CONSTRAINT |
31 | #define PX_PHYSICS_NX_CONSTRAINT |
32 | |
33 | /** \addtogroup physics |
34 | @{ |
35 | */ |
36 | |
37 | #include "PxPhysXConfig.h" |
38 | #include "PxConstraintDesc.h" |
39 | #include "common/PxBase.h" |
40 | |
41 | #if !PX_DOXYGEN |
42 | namespace physx |
43 | { |
44 | #endif |
45 | |
46 | class PxRigidActor; |
47 | class PxScene; |
48 | class PxConstraintConnector; |
49 | |
50 | /** |
51 | \brief a table of function pointers for a constraint |
52 | |
53 | @see PxConstraint |
54 | */ |
55 | |
56 | /** |
57 | \brief constraint flags |
58 | |
59 | \note eBROKEN is a read only flag |
60 | */ |
61 | |
62 | struct PxConstraintFlag |
63 | { |
64 | enum Enum |
65 | { |
66 | eBROKEN = 1<<0, //!< whether the constraint is broken |
67 | ePROJECT_TO_ACTOR0 = 1<<1, //!< whether actor1 should get projected to actor0 for this constraint (note: projection of a static/kinematic actor to a dynamic actor will be ignored) |
68 | ePROJECT_TO_ACTOR1 = 1<<2, //!< whether actor0 should get projected to actor1 for this constraint (note: projection of a static/kinematic actor to a dynamic actor will be ignored) |
69 | ePROJECTION = ePROJECT_TO_ACTOR0 | ePROJECT_TO_ACTOR1, //!< whether the actors should get projected for this constraint (the direction will be chosen by PhysX) |
70 | eCOLLISION_ENABLED = 1<<3, //!< whether contacts should be generated between the objects this constraint constrains |
71 | eVISUALIZATION = 1<<4, //!< whether this constraint should be visualized, if constraint visualization is turned on |
72 | eDRIVE_LIMITS_ARE_FORCES = 1<<5, //!< limits for drive strength are forces rather than impulses |
73 | eIMPROVED_SLERP = 1<<7, //!< perform preprocessing for improved accuracy on D6 Slerp Drive (this flag will be removed in a future release when preprocessing is no longer required) |
74 | eDISABLE_PREPROCESSING = 1<<8, //!< suppress constraint preprocessing, intended for use with rowResponseThreshold. May result in worse solver accuracy for ill-conditioned constraints. |
75 | eENABLE_EXTENDED_LIMITS = 1<<9, //!< enables extended limit ranges for angular limits (e.g. limit values > PxPi or < -PxPi) |
76 | eGPU_COMPATIBLE = 1<<10 //!< the constraint type is supported by gpu dynamic |
77 | }; |
78 | }; |
79 | |
80 | /** |
81 | \brief constraint flags |
82 | @see PxConstraintFlag |
83 | */ |
84 | |
85 | typedef PxFlags<PxConstraintFlag::Enum, PxU16> PxConstraintFlags; |
86 | PX_FLAGS_OPERATORS(PxConstraintFlag::Enum, PxU16) |
87 | |
88 | struct PxConstraintShaderTable |
89 | { |
90 | enum |
91 | { |
92 | eMAX_SOLVERPRPEP_DATASIZE=400 |
93 | }; |
94 | |
95 | PxConstraintSolverPrep solverPrep; //!< solver constraint generation function |
96 | PxConstraintProject project; //!< constraint projection function |
97 | PxConstraintVisualize visualize; //!< constraint visualization function |
98 | PxConstraintFlag::Enum flag; //!< constraint flags |
99 | }; |
100 | |
101 | |
102 | /** |
103 | \brief A plugin class for implementing constraints |
104 | |
105 | @see PxPhysics.createConstraint |
106 | */ |
107 | |
108 | class PxConstraint : public PxBase |
109 | { |
110 | public: |
111 | |
112 | /** |
113 | \brief Releases a PxConstraint instance. |
114 | |
115 | \note This call does not wake up the connected rigid bodies. |
116 | |
117 | @see PxPhysics.createConstraint, PxBase.release() |
118 | */ |
119 | virtual void release() = 0; |
120 | |
121 | /** |
122 | \brief Retrieves the scene which this constraint belongs to. |
123 | |
124 | \return Owner Scene. NULL if not part of a scene. |
125 | |
126 | @see PxScene |
127 | */ |
128 | virtual PxScene* getScene() const = 0; |
129 | |
130 | /** |
131 | \brief Retrieves the actors for this constraint. |
132 | |
133 | \param[out] actor0 a reference to the pointer for the first actor |
134 | \param[out] actor1 a reference to the pointer for the second actor |
135 | |
136 | @see PxActor |
137 | */ |
138 | virtual void getActors(PxRigidActor*& actor0, PxRigidActor*& actor1) const = 0; |
139 | |
140 | /** |
141 | \brief Sets the actors for this constraint. |
142 | |
143 | \param[in] actor0 a reference to the pointer for the first actor |
144 | \param[in] actor1 a reference to the pointer for the second actor |
145 | |
146 | @see PxActor |
147 | */ |
148 | virtual void setActors(PxRigidActor* actor0, PxRigidActor* actor1) = 0; |
149 | |
150 | /** |
151 | \brief Notify the scene that the constraint shader data has been updated by the application |
152 | */ |
153 | virtual void markDirty() = 0; |
154 | |
155 | /** |
156 | \brief Set the flags for this constraint |
157 | |
158 | \param[in] flags the new constraint flags |
159 | |
160 | default: PxConstraintFlag::eDRIVE_LIMITS_ARE_FORCES |
161 | |
162 | @see PxConstraintFlags |
163 | */ |
164 | virtual void setFlags(PxConstraintFlags flags) = 0; |
165 | |
166 | /** |
167 | \brief Retrieve the flags for this constraint |
168 | |
169 | \return the constraint flags |
170 | @see PxConstraintFlags |
171 | */ |
172 | virtual PxConstraintFlags getFlags() const = 0; |
173 | |
174 | /** |
175 | \brief Set a flag for this constraint |
176 | |
177 | \param[in] flag the constraint flag |
178 | \param[in] value the new value of the flag |
179 | |
180 | @see PxConstraintFlags |
181 | */ |
182 | virtual void setFlag(PxConstraintFlag::Enum flag, bool value) = 0; |
183 | |
184 | /** |
185 | \brief Retrieve the constraint force most recently applied to maintain this constraint. |
186 | |
187 | \param[out] linear the constraint force |
188 | \param[out] angular the constraint torque |
189 | */ |
190 | virtual void getForce(PxVec3& linear, PxVec3& angular) const = 0; |
191 | |
192 | /** |
193 | \brief whether the constraint is valid. |
194 | |
195 | A constraint is valid if it has at least one dynamic rigid body or articulation link. A constraint that |
196 | is not valid may not be inserted into a scene, and therefore a static actor to which an invalid constraint |
197 | is attached may not be inserted into a scene. |
198 | |
199 | Invalid constraints arise only when an actor to which the constraint is attached has been deleted. |
200 | */ |
201 | virtual bool isValid() const = 0; |
202 | |
203 | /** |
204 | \brief Set the break force and torque thresholds for this constraint. |
205 | |
206 | If either the force or torque measured at the constraint exceed these thresholds the constraint will break. |
207 | |
208 | \param[in] linear the linear break threshold |
209 | \param[in] angular the angular break threshold |
210 | */ |
211 | virtual void setBreakForce(PxReal linear, PxReal angular) = 0; |
212 | |
213 | /** |
214 | \brief Retrieve the constraint break force and torque thresholds |
215 | |
216 | \param[out] linear the linear break threshold |
217 | \param[out] angular the angular break threshold |
218 | */ |
219 | virtual void getBreakForce(PxReal& linear, PxReal& angular) const = 0; |
220 | |
221 | /** |
222 | \brief Set the minimum response threshold for a constraint row |
223 | |
224 | When using mass modification for a joint or infinite inertia for a jointed body, very stiff solver constraints can be generated which |
225 | can destabilize simulation. Setting this value to a small positive value (e.g. 1e-8) will cause constraint rows to be ignored if very |
226 | large changes in impulses will generate only small changes in velocity. When setting this value, also set |
227 | PxConstraintFlag::eDISABLE_PREPROCESSING. The solver accuracy for this joint may be reduced. |
228 | |
229 | \param[in] threshold the minimum response threshold |
230 | |
231 | @see PxConstraintFlag::eDISABLE_PREPROCESSING |
232 | */ |
233 | virtual void setMinResponseThreshold(PxReal threshold) = 0; |
234 | |
235 | /** |
236 | \brief Retrieve the constraint break force and torque thresholds |
237 | |
238 | \return the minimum response threshold for a constraint row |
239 | */ |
240 | virtual PxReal getMinResponseThreshold() const = 0; |
241 | |
242 | /** |
243 | \brief Fetch external owner of the constraint. |
244 | |
245 | Provides a reference to the external owner of a constraint and a unique owner type ID. |
246 | |
247 | \param[out] typeID Unique type identifier of the external object. |
248 | \return Reference to the external object which owns the constraint. |
249 | |
250 | @see PxConstraintConnector.getExternalReference() |
251 | */ |
252 | virtual void* getExternalReference(PxU32& typeID) = 0; |
253 | |
254 | /** |
255 | \brief Set the constraint functions for this constraint |
256 | |
257 | \param[in] connector the constraint connector object by which the SDK communicates with the constraint. |
258 | \param[in] shaders the shader table for the constraint |
259 | |
260 | @see PxConstraintConnector PxConstraintSolverPrep PxConstraintProject PxConstraintVisualize |
261 | */ |
262 | virtual void setConstraintFunctions(PxConstraintConnector& connector, |
263 | const PxConstraintShaderTable& shaders) = 0; |
264 | |
265 | virtual const char* getConcreteTypeName() const { return "PxConstraint" ; } |
266 | |
267 | protected: |
268 | PX_INLINE PxConstraint(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags) {} |
269 | PX_INLINE PxConstraint(PxBaseFlags baseFlags) : PxBase(baseFlags) {} |
270 | virtual ~PxConstraint() {} |
271 | virtual bool isKindOf(const char* name) const { return !::strcmp(s1: "PxConstraint" , s2: name) || PxBase::isKindOf(superClass: name); } |
272 | |
273 | }; |
274 | |
275 | #if !PX_DOXYGEN |
276 | } // namespace physx |
277 | #endif |
278 | |
279 | /** @} */ |
280 | #endif |
281 | |