PxJointLimit.h

Go to the documentation of this file.
00001 // This code contains NVIDIA Confidential Information and is disclosed to you
00002 // under a form of NVIDIA software license agreement provided separately to you.
00003 //
00004 // Notice
00005 // NVIDIA Corporation and its licensors retain all intellectual property and
00006 // proprietary rights in and to this software and related documentation and
00007 // any modifications thereto. Any use, reproduction, disclosure, or
00008 // distribution of this software and related documentation without an express
00009 // license agreement from NVIDIA Corporation is strictly prohibited.
00010 //
00011 // ALL NVIDIA DESIGN SPECIFICATIONS, CODE ARE PROVIDED "AS IS.". NVIDIA MAKES
00012 // NO WARRANTIES, EXPRESSED, IMPLIED, STATUTORY, OR OTHERWISE WITH RESPECT TO
00013 // THE MATERIALS, AND EXPRESSLY DISCLAIMS ALL IMPLIED WARRANTIES OF NONINFRINGEMENT,
00014 // MERCHANTABILITY, AND FITNESS FOR A PARTICULAR PURPOSE.
00015 //
00016 // Information and code furnished is believed to be accurate and reliable.
00017 // However, NVIDIA Corporation assumes no responsibility for the consequences of use of such
00018 // information or for any infringement of patents or other rights of third parties that may
00019 // result from its use. No license is granted by implication or otherwise under any patent
00020 // or patent rights of NVIDIA Corporation. Details are subject to change without notice.
00021 // This code supersedes and replaces all information previously supplied.
00022 // NVIDIA Corporation products are not authorized for use as critical
00023 // components in life support devices or systems without express written approval of
00024 // NVIDIA Corporation.
00025 //
00026 // Copyright (c) 2008-2018 NVIDIA Corporation. All rights reserved.
00027 // Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
00028 // Copyright (c) 2001-2004 NovodeX AG. All rights reserved.  
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 //= ATTENTION! =====================================================================================
00055 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00056 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00057 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00058 // accordingly.
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 //= ATTENTION! =====================================================================================
00168 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00169 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00170 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00171 // accordingly.
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 //= ATTENTION! =====================================================================================
00231 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00232 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00233 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00234 // accordingly.
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 //= ATTENTION! =====================================================================================
00298 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00299 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00300 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00301 // accordingly.
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 //= ATTENTION! =====================================================================================
00372 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00373 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00374 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00375 // accordingly.
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 //= ATTENTION! =====================================================================================
00451 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00452 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00453 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00454 // accordingly.
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 } // namespace physx
00563 #endif
00564 
00566 #endif


Copyright © 2008-2018 NVIDIA Corporation, 2701 San Tomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. www.nvidia.com