00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef PX_EXTENSIONS_JOINT_LIMIT
00031 #define PX_EXTENSIONS_JOINT_LIMIT
00032
00036 #include "foundation/PxMath.h"
00037 #include "PxPhysXConfig.h"
00038 #include "common/PxTolerancesScale.h"
00039 #include "PxJoint.h"
00040
00041 #if !PX_DOXYGEN
00042 namespace physx
00043 {
00044 #endif
00045
00052 class PxJointLimitParameters
00053 {
00054
00055
00056
00057
00058
00059
00060 public:
00080 PxReal restitution;
00081
00085 PxReal bounceThreshold;
00086
00093 PxReal stiffness;
00094
00101 PxReal damping;
00102
00118 PxReal contactDistance;
00119
00120 PxJointLimitParameters() :
00121 restitution (0.0f),
00122 bounceThreshold (0.0f),
00123 stiffness (0.0f),
00124 damping (0.0f),
00125 contactDistance (0.0f)
00126 {
00127 }
00128
00129 PxJointLimitParameters(const PxJointLimitParameters& p) :
00130 restitution (p.restitution),
00131 bounceThreshold (p.bounceThreshold),
00132 stiffness (p.stiffness),
00133 damping (p.damping),
00134 contactDistance (p.contactDistance)
00135 {
00136 }
00137
00143 PX_INLINE bool isValid() const
00144 {
00145 return PxIsFinite(restitution) && restitution >= 0 && restitution <= 1 &&
00146 PxIsFinite(stiffness) && stiffness >= 0 &&
00147 PxIsFinite(damping) && damping >= 0 &&
00148 PxIsFinite(bounceThreshold) && bounceThreshold >= 0 &&
00149 PxIsFinite(contactDistance) && contactDistance >= 0;
00150 }
00151
00152 PX_INLINE bool isSoft() const
00153 {
00154 return damping>0 || stiffness>0;
00155 }
00156
00157 protected:
00158 ~PxJointLimitParameters() {}
00159 };
00160
00161
00165 class PxJointLinearLimit : public PxJointLimitParameters
00166 {
00167
00168
00169
00170
00171
00172
00173 public:
00180 PxReal value;
00181
00191 PxJointLinearLimit(const PxTolerancesScale& scale, PxReal extent, PxReal contactDist = -1.0f)
00192 : value(extent)
00193 {
00194 PxJointLimitParameters::contactDistance = contactDist == -1.0f ? 0.01f*scale.length : contactDist;
00195 }
00196
00205 PxJointLinearLimit(PxReal extent, const PxSpring& spring) : value(extent)
00206 {
00207 stiffness = spring.stiffness;
00208 damping = spring.damping;
00209 }
00210
00216 PX_INLINE bool isValid() const
00217 {
00218 return PxJointLimitParameters::isValid() &&
00219 PxIsFinite(value) &&
00220 value > 0.0f;
00221 }
00222 };
00223
00224
00228 class PxJointLinearLimitPair : public PxJointLimitParameters
00229 {
00230
00231
00232
00233
00234
00235
00236 public:
00244 PxReal upper, lower;
00245
00256 PxJointLinearLimitPair(const PxTolerancesScale& scale, PxReal lowerLimit, PxReal upperLimit, PxReal contactDist = -1.0f) :
00257 upper(upperLimit),
00258 lower(lowerLimit)
00259 {
00260 PxJointLimitParameters::contactDistance = contactDist == -1.0f ? PxMin(scale.length * 0.01f, (upperLimit*0.49f-lowerLimit*0.49f)) : contactDist;
00261 bounceThreshold = 2.0f*scale.length;
00262 }
00263
00273 PxJointLinearLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring) :
00274 upper(upperLimit),
00275 lower(lowerLimit)
00276 {
00277 stiffness = spring.stiffness;
00278 damping = spring.damping;
00279 }
00280
00286 PX_INLINE bool isValid() const
00287 {
00288 return PxJointLimitParameters::isValid() &&
00289 PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower &&
00290 PxIsFinite(upper - lower);
00291 }
00292 };
00293
00294
00295 class PxJointAngularLimitPair : public PxJointLimitParameters
00296 {
00297
00298
00299
00300
00301
00302
00303 public:
00311 PxReal upper, lower;
00312
00324 PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, PxReal contactDist = -1.0f) :
00325 upper(upperLimit),
00326 lower(lowerLimit)
00327 {
00328 PxJointLimitParameters::contactDistance = contactDist ==-1.0f ? PxMin(0.1f, 0.49f*(upperLimit-lowerLimit)) : contactDist;
00329 bounceThreshold = 0.5f;
00330 }
00331
00343 PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring) :
00344 upper(upperLimit),
00345 lower(lowerLimit)
00346 {
00347 stiffness = spring.stiffness;
00348 damping = spring.damping;
00349 }
00350
00356 PX_INLINE bool isValid() const
00357 {
00358 return PxJointLimitParameters::isValid() &&
00359 PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower;
00360 }
00361 };
00362
00369 class PxJointLimitCone : public PxJointLimitParameters
00370 {
00371
00372
00373
00374
00375
00376
00377 public:
00385 PxReal yAngle;
00386
00394 PxReal zAngle;
00395
00405 PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, PxReal contactDist = -1.0f) :
00406 yAngle(yLimitAngle),
00407 zAngle(zLimitAngle)
00408 {
00409 PxJointLimitParameters::contactDistance = contactDist == -1.0f ? PxMin(0.1f, PxMin(yLimitAngle, zLimitAngle)*0.49f) : contactDist;
00410 bounceThreshold = 0.5f;
00411 }
00412
00422 PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, const PxSpring& spring) :
00423 yAngle(yLimitAngle),
00424 zAngle(zLimitAngle)
00425 {
00426 stiffness = spring.stiffness;
00427 damping = spring.damping;
00428 }
00429
00435 PX_INLINE bool isValid() const
00436 {
00437 return PxJointLimitParameters::isValid() &&
00438 PxIsFinite(yAngle) && yAngle>0 && yAngle<PxPi &&
00439 PxIsFinite(zAngle) && zAngle>0 && zAngle<PxPi;
00440 }
00441 };
00442
00448 class PxJointLimitPyramid : public PxJointLimitParameters
00449 {
00450
00451
00452
00453
00454
00455
00456 public:
00464 PxReal yAngleMin;
00465
00473 PxReal yAngleMax;
00474
00482 PxReal zAngleMin;
00483
00491 PxReal zAngleMax;
00492
00504 PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, PxReal contactDist = -1.0f) :
00505 yAngleMin(yLimitAngleMin),
00506 yAngleMax(yLimitAngleMax),
00507 zAngleMin(zLimitAngleMin),
00508 zAngleMax(zLimitAngleMax)
00509 {
00510 if(contactDist == -1.0f)
00511 {
00512 const PxReal contactDistY = PxMin(0.1f, 0.49f*(yLimitAngleMax - yLimitAngleMin));
00513 const PxReal contactDistZ = PxMin(0.1f, 0.49f*(zLimitAngleMax - zLimitAngleMin));
00514 PxJointLimitParameters::contactDistance = contactDist == PxMin(contactDistY, contactDistZ);
00515 }
00516 else
00517 {
00518 PxJointLimitParameters::contactDistance = contactDist;
00519 }
00520
00521 bounceThreshold = 0.5f;
00522 }
00523
00535 PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, const PxSpring& spring) :
00536 yAngleMin(yLimitAngleMin),
00537 yAngleMax(yLimitAngleMax),
00538 zAngleMin(zLimitAngleMin),
00539 zAngleMax(zLimitAngleMax)
00540 {
00541 stiffness = spring.stiffness;
00542 damping = spring.damping;
00543 }
00544
00550 PX_INLINE bool isValid() const
00551 {
00552 return PxJointLimitParameters::isValid() &&
00553 PxIsFinite(yAngleMin) && yAngleMin>-PxPi && yAngleMin<PxPi &&
00554 PxIsFinite(yAngleMax) && yAngleMax>-PxPi && yAngleMax<PxPi &&
00555 PxIsFinite(zAngleMin) && zAngleMin>-PxPi && zAngleMin<PxPi &&
00556 PxIsFinite(zAngleMax) && zAngleMax>-PxPi && zAngleMax<PxPi &&
00557 yAngleMax>=yAngleMin && zAngleMax>=zAngleMin;
00558 }
00559 };
00560
00561 #if !PX_DOXYGEN
00562 }
00563 #endif
00564
00566 #endif