PxJointLimit.h
Go to the documentation of this file.
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_EXTENSIONS_JOINT_LIMIT
31 #define PX_EXTENSIONS_JOINT_LIMIT
32 
36 #include "foundation/PxMath.h"
38 #include "extensions/PxJoint.h"
39 #include "PxPhysXConfig.h"
40 
41 #if !PX_DOXYGEN
42 namespace physx
43 {
44 #endif
45 
53 {
54 //= ATTENTION! =====================================================================================
55 // Changing the data layout of this class breaks the binary serialization format. See comments for
56 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
57 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
58 // accordingly.
59 //==================================================================================================
60 public:
81 
86 
94 
102 
119 
121  restitution (0.0f),
122  bounceThreshold (0.0f),
123  stiffness (0.0f),
124  damping (0.0f),
125  contactDistance (0.0f)
126  {
127  }
128 
131  bounceThreshold (p.bounceThreshold),
132  stiffness (p.stiffness),
133  damping (p.damping),
134  contactDistance (p.contactDistance)
135  {
136  }
137 
143  PX_INLINE bool isValid() const
144  {
145  return PxIsFinite(restitution) && restitution >= 0 && restitution <= 1 &&
146  PxIsFinite(stiffness) && stiffness >= 0 &&
147  PxIsFinite(damping) && damping >= 0 &&
148  PxIsFinite(bounceThreshold) && bounceThreshold >= 0 &&
149  PxIsFinite(contactDistance) && contactDistance >= 0;
150  }
151 
152  PX_INLINE bool isSoft() const
153  {
154  return damping>0 || stiffness>0;
155  }
156 
157 protected:
159 };
160 
161 
166 {
167 //= ATTENTION! =====================================================================================
168 // Changing the data layout of this class breaks the binary serialization format. See comments for
169 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
170 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
171 // accordingly.
172 //==================================================================================================
173 public:
181 
191  PxJointLinearLimit(const PxTolerancesScale& scale, PxReal extent, PxReal contactDist = -1.0f)
192  : value(extent)
193  {
194  PxJointLimitParameters::contactDistance = contactDist == -1.0f ? 0.01f*scale.length : contactDist;
195  }
196 
205  PxJointLinearLimit(PxReal extent, const PxSpring& spring) : value(extent)
206  {
207  stiffness = spring.stiffness;
208  damping = spring.damping;
209  }
210 
216  PX_INLINE bool isValid() const
217  {
219  PxIsFinite(value) &&
220  value > 0.0f;
221  }
222 };
223 
224 
229 {
230 //= ATTENTION! =====================================================================================
231 // Changing the data layout of this class breaks the binary serialization format. See comments for
232 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
233 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
234 // accordingly.
235 //==================================================================================================
236 public:
244  PxReal upper, lower;
245 
256  PxJointLinearLimitPair(const PxTolerancesScale& scale, PxReal lowerLimit = -PX_MAX_F32/3.0f, PxReal upperLimit = PX_MAX_F32/3.0f, PxReal contactDist = -1.0f) :
257  upper(upperLimit),
258  lower(lowerLimit)
259  {
260  PxJointLimitParameters::contactDistance = contactDist == -1.0f ? PxMin(scale.length * 0.01f, (upperLimit*0.49f-lowerLimit*0.49f)) : contactDist;
261  bounceThreshold = 2.0f*scale.length;
262  }
263 
273  PxJointLinearLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring) :
274  upper(upperLimit),
275  lower(lowerLimit)
276  {
277  stiffness = spring.stiffness;
278  damping = spring.damping;
279  }
280 
286  PX_INLINE bool isValid() const
287  {
289  PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower &&
290  PxIsFinite(upper - lower);
291  }
292 };
293 
294 
296 {
297 //= ATTENTION! =====================================================================================
298 // Changing the data layout of this class breaks the binary serialization format. See comments for
299 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
300 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
301 // accordingly.
302 //==================================================================================================
303 public:
311  PxReal upper, lower;
312 
324  PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, PxReal contactDist = -1.0f) :
325  upper(upperLimit),
326  lower(lowerLimit)
327  {
328  PxJointLimitParameters::contactDistance = contactDist ==-1.0f ? PxMin(0.1f, 0.49f*(upperLimit-lowerLimit)) : contactDist;
329  bounceThreshold = 0.5f;
330  }
331 
343  PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring) :
344  upper(upperLimit),
345  lower(lowerLimit)
346  {
347  stiffness = spring.stiffness;
348  damping = spring.damping;
349  }
350 
356  PX_INLINE bool isValid() const
357  {
359  PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower;
360  }
361 };
362 
370 {
371 //= ATTENTION! =====================================================================================
372 // Changing the data layout of this class breaks the binary serialization format. See comments for
373 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
374 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
375 // accordingly.
376 //==================================================================================================
377 public:
386 
395 
405  PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, PxReal contactDist = -1.0f) :
406  yAngle(yLimitAngle),
407  zAngle(zLimitAngle)
408  {
409  PxJointLimitParameters::contactDistance = contactDist == -1.0f ? PxMin(0.1f, PxMin(yLimitAngle, zLimitAngle)*0.49f) : contactDist;
410  bounceThreshold = 0.5f;
411  }
412 
422  PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, const PxSpring& spring) :
423  yAngle(yLimitAngle),
424  zAngle(zLimitAngle)
425  {
426  stiffness = spring.stiffness;
427  damping = spring.damping;
428  }
429 
435  PX_INLINE bool isValid() const
436  {
438  PxIsFinite(yAngle) && yAngle>0 && yAngle<PxPi &&
439  PxIsFinite(zAngle) && zAngle>0 && zAngle<PxPi;
440  }
441 };
442 
449 {
450 //= ATTENTION! =====================================================================================
451 // Changing the data layout of this class breaks the binary serialization format. See comments for
452 // PX_BINARY_SERIAL_VERSION. If a modification is required, please adjust the getBinaryMetaData
453 // function. If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
454 // accordingly.
455 //==================================================================================================
456 public:
465 
474 
483 
492 
504  PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, PxReal contactDist = -1.0f) :
505  yAngleMin(yLimitAngleMin),
506  yAngleMax(yLimitAngleMax),
507  zAngleMin(zLimitAngleMin),
508  zAngleMax(zLimitAngleMax)
509  {
510  if(contactDist == -1.0f)
511  {
512  const PxReal contactDistY = PxMin(0.1f, 0.49f*(yLimitAngleMax - yLimitAngleMin));
513  const PxReal contactDistZ = PxMin(0.1f, 0.49f*(zLimitAngleMax - zLimitAngleMin));
514  PxJointLimitParameters::contactDistance = contactDist == PxMin(contactDistY, contactDistZ);
515  }
516  else
517  {
519  }
520 
521  bounceThreshold = 0.5f;
522  }
523 
535  PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, const PxSpring& spring) :
536  yAngleMin(yLimitAngleMin),
537  yAngleMax(yLimitAngleMax),
538  zAngleMin(zLimitAngleMin),
539  zAngleMax(zLimitAngleMax)
540  {
541  stiffness = spring.stiffness;
542  damping = spring.damping;
543  }
544 
550  PX_INLINE bool isValid() const
551  {
553  PxIsFinite(yAngleMin) && yAngleMin>-PxPi && yAngleMin<PxPi &&
554  PxIsFinite(yAngleMax) && yAngleMax>-PxPi && yAngleMax<PxPi &&
555  PxIsFinite(zAngleMin) && zAngleMin>-PxPi && zAngleMin<PxPi &&
556  PxIsFinite(zAngleMax) && zAngleMax>-PxPi && zAngleMax<PxPi &&
557  yAngleMax>=yAngleMin && zAngleMax>=zAngleMin;
558  }
559 };
560 
561 #if !PX_DOXYGEN
562 } // namespace physx
563 #endif
564 
566 #endif
Definition: GuContactBuffer.h:37
PX_INLINE bool isValid() const
Returns true if the current settings are valid.
Definition: PxJointLimit.h:143
PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, const PxSpring &spring)
Construct a cone soft limit.
Definition: PxJointLimit.h:422
PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, PxReal contactDist=-1.0f)
Construct a pyramid hard limit.
Definition: PxJointLimit.h:504
PxJointLinearLimitPair(const PxTolerancesScale &scale, PxReal lowerLimit=-PX_MAX_F32/3.0f, PxReal upperLimit=PX_MAX_F32/3.0f, PxReal contactDist=-1.0f)
Construct a linear hard limit pair. The lower distance value must be less than the upper distance val...
Definition: PxJointLimit.h:256
PxReal yAngleMax
the maximum angle from the Y axis of the constraint frame.
Definition: PxJointLimit.h:473
PxReal zAngleMin
the minimum angle from the Z-axis of the constraint frame.
Definition: PxJointLimit.h:482
PX_INLINE bool isValid() const
Returns true if the limit is valid.
Definition: PxJointLimit.h:286
PxReal restitution
restitution parameter for determining additional "bounce"
Definition: PxConstraintDesc.h:104
PxReal bounceThreshold
Definition: PxJointLimit.h:85
static const float PxPi
Definition: PxMath.h:58
PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, const PxSpring &spring)
Construct a pyramid soft limit.
Definition: PxJointLimit.h:535
float PxReal
Definition: PxSimpleTypes.h:78
struct @6::SpringModifiers spring
PxReal restitution
Controls the amount of bounce when the joint hits a limit.
Definition: PxJointLimit.h:80
PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, PxReal contactDist=-1.0f)
construct an angular hard limit pair.
Definition: PxJointLimit.h:324
Describes a one-sided linear limit.
Definition: PxJointLimit.h:165
PxJointLinearLimit(PxReal extent, const PxSpring &spring)
construct a linear soft limit
Definition: PxJointLimit.h:205
PX_INLINE bool isValid() const
Returns true if the limit is valid.
Definition: PxJointLimit.h:356
PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, PxReal contactDist=-1.0f)
Construct a cone hard limit.
Definition: PxJointLimit.h:405
Describes the parameters for a joint limit.
Definition: PxJointLimit.h:52
PxReal stiffness
spring parameter, for spring constraints
Definition: PxConstraintDesc.h:99
~PxJointLimitParameters()
Definition: PxJointLimit.h:158
PX_INLINE bool isSoft() const
Definition: PxJointLimit.h:152
PxJointLimitParameters(const PxJointLimitParameters &p)
Definition: PxJointLimit.h:129
Definition: PxJointLimit.h:295
PX_CUDA_CALLABLE PX_FORCE_INLINE T PxMin(T a, T b)
The return value is the lesser of the two specified values.
Definition: PxMath.h:86
PxReal upper
the range of the limit. The upper limit must be no lower than the lower limit, and if they are equal ...
Definition: PxJointLimit.h:244
Describes a pyramidal joint limit.
Definition: PxJointLimit.h:448
Describes a two-sided limit.
Definition: PxJointLimit.h:228
Definition: PxJoint.h:381
#define PX_MAX_F32
Definition: PxSimpleTypes.h:86
PxReal damping
damping parameter, for spring constraints
Definition: PxConstraintDesc.h:100
PxReal length
Definition: PxTolerancesScale.h:67
PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring &spring)
construct an angular soft limit pair.
Definition: PxJointLimit.h:343
Class to define the scale at which simulation runs. Most simulation tolerances are calculated in term...
Definition: PxTolerancesScale.h:56
PxJointLinearLimit(const PxTolerancesScale &scale, PxReal extent, PxReal contactDist=-1.0f)
construct a linear hard limit
Definition: PxJointLimit.h:191
PxReal contactDistance
the distance inside the limit value at which the limit will be considered to be active by the solver...
Definition: PxJointLimit.h:118
PxReal zAngleMax
the maximum angle from the Z-axis of the constraint frame.
Definition: PxJointLimit.h:491
PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(float f)
returns true if the passed number is a finite floating point number as opposed to INF...
Definition: PxMath.h:292
PxJointLinearLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring &spring)
construct a linear soft limit pair
Definition: PxJointLimit.h:273
PxReal yAngle
the maximum angle from the Y axis of the constraint frame.
Definition: PxJointLimit.h:385
PxReal yAngleMin
the minimum angle from the Y axis of the constraint frame.
Definition: PxJointLimit.h:464
Describes an elliptical conical joint limit. Note that very small or highly elliptical limit cones ma...
Definition: PxJointLimit.h:369
PX_INLINE bool isValid() const
Returns true if the limit is valid.
Definition: PxJointLimit.h:216
PxReal zAngle
the maximum angle from the Z-axis of the constraint frame.
Definition: PxJointLimit.h:394
PxReal value
the extent of the limit.
Definition: PxJointLimit.h:180
PxReal upper
the range of the limit. The upper limit must be no lower than the lower limit.
Definition: PxJointLimit.h:311
PxJointLimitParameters()
Definition: PxJointLimit.h:120
#define PX_INLINE
Definition: PxPreprocessor.h:336
PxReal damping
if spring is greater than zero, this is the damping of the limit spring
Definition: PxJointLimit.h:101
PX_INLINE bool isValid() const
Returns true if the limit is valid.
Definition: PxJointLimit.h:435
PxReal stiffness
if greater than zero, the limit is soft, i.e. a spring pulls the joint back to the limit ...
Definition: PxJointLimit.h:93
PX_INLINE bool isValid() const
Returns true if the limit is valid.
Definition: PxJointLimit.h:550