PxJointLimit.h

Go to the documentation of this file.
00001 //
00002 // Redistribution and use in source and binary forms, with or without
00003 // modification, are permitted provided that the following conditions
00004 // are met:
00005 //  * Redistributions of source code must retain the above copyright
00006 //    notice, this list of conditions and the following disclaimer.
00007 //  * Redistributions in binary form must reproduce the above copyright
00008 //    notice, this list of conditions and the following disclaimer in the
00009 //    documentation and/or other materials provided with the distribution.
00010 //  * Neither the name of NVIDIA CORPORATION nor the names of its
00011 //    contributors may be used to endorse or promote products derived
00012 //    from this software without specific prior written permission.
00013 //
00014 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
00015 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00016 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00017 // PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
00018 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00019 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00020 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00021 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00022 // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00024 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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 
00031 #ifndef PX_EXTENSIONS_JOINT_LIMIT
00032 #define PX_EXTENSIONS_JOINT_LIMIT
00033 
00037 #include "foundation/PxMath.h"
00038 #include "PxPhysXConfig.h"
00039 #include "common/PxTolerancesScale.h"
00040 #include "PxJoint.h"
00041 
00042 #if !PX_DOXYGEN
00043 namespace physx
00044 {
00045 #endif
00046 
00055 class PxJointLimitParameters
00056 {
00057 //= ATTENTION! =====================================================================================
00058 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00059 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00060 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00061 // accordingly.
00062 //==================================================================================================
00063 public:
00083     PxReal restitution;
00084 
00085 
00090     PxReal bounceThreshold;
00097     PxReal stiffness;
00098 
00105     PxReal damping;
00106 
00123     PxReal contactDistance;
00124 
00125 
00126 
00127     PxJointLimitParameters()
00128     : restitution(0)
00129     , bounceThreshold(0)
00130     , stiffness(0)
00131     , damping(0)
00132     , contactDistance(0)
00133     {
00134     }   
00135 
00141     PX_INLINE bool isValid() const
00142     {
00143         return  PxIsFinite(restitution) && restitution >= 0 && restitution <= 1 && 
00144                 PxIsFinite(stiffness) && stiffness >= 0 && 
00145                 PxIsFinite(damping) && damping >= 0 &&
00146                 PxIsFinite(bounceThreshold) && bounceThreshold >= 0 &&
00147                 PxIsFinite(contactDistance) && contactDistance >= 0;
00148     }
00149 
00150     PX_INLINE bool isSoft() const
00151     {
00152         return damping>0 || stiffness>0;
00153     }
00154 
00155 protected:
00156     ~PxJointLimitParameters() {}
00157 };
00158 
00159 
00163 class PxJointLinearLimit : public PxJointLimitParameters
00164 {
00165 //= ATTENTION! =====================================================================================
00166 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00167 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00168 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00169 // accordingly.
00170 //==================================================================================================
00171 public:
00178     PxReal value;
00179 
00190     PxJointLinearLimit(const PxTolerancesScale& scale, PxReal extent, PxReal contactDist = -1)
00191     : value(extent)
00192     {
00193         PxJointLimitParameters::contactDistance = contactDist == -1 ? 0.01f*scale.length : contactDist; 
00194     }
00195 
00196 
00206     PxJointLinearLimit(PxReal extent, const PxSpring& spring)
00207     : value(extent)
00208     {
00209         stiffness = spring.stiffness;
00210         damping = spring.damping;
00211     }
00212 
00213 
00214 
00220     PX_INLINE bool isValid() const
00221     {
00222         return PxJointLimitParameters::isValid() &&
00223                PxIsFinite(value) && 
00224                value > 0;
00225     }
00226 };
00227 
00228 
00233 class PxJointLinearLimitPair : public PxJointLimitParameters
00234 {
00235 //= ATTENTION! =====================================================================================
00236 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00237 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00238 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00239 // accordingly.
00240 //==================================================================================================
00241 public:
00250     PxReal upper, lower;
00251 
00252 
00264     PxJointLinearLimitPair(const PxTolerancesScale& scale, PxReal lowerLimit, PxReal upperLimit, PxReal contactDist = -1)
00265     : upper(upperLimit)
00266     , lower(lowerLimit)
00267     {
00268         PxJointLimitParameters::contactDistance = contactDist == -1 ? PxMin(scale.length * 0.01f, (upperLimit*0.49f-lowerLimit*0.49f)) : contactDist; 
00269         bounceThreshold = 2*scale.length;
00270     }
00271 
00272 
00283     PxJointLinearLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring)
00284     : upper(upperLimit)
00285     , lower(lowerLimit)
00286     {
00287         stiffness = spring.stiffness;
00288         damping = spring.damping;
00289     }
00290 
00291 
00297     PX_INLINE bool isValid() const
00298     {
00299         return PxJointLimitParameters::isValid() &&
00300                PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower &&
00301                PxIsFinite(upper - lower) && 
00302                PxIsFinite(contactDistance) && contactDistance <= upper - lower;
00303     }
00304 };
00305 
00306 
00307 class PxJointAngularLimitPair : public PxJointLimitParameters
00308 {
00309 //= ATTENTION! =====================================================================================
00310 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00311 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00312 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00313 // accordingly.
00314 //==================================================================================================
00315 public:
00323     PxReal upper, lower;
00324 
00325 
00338     PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, PxReal contactDist = -1)
00339     : upper(upperLimit)
00340     , lower(lowerLimit)
00341     {
00342         PxJointLimitParameters::contactDistance = contactDist ==-1 ? PxMin(0.1f, 0.49f*(upperLimit-lowerLimit)) : contactDist;
00343         bounceThreshold = 0.5f;
00344     }
00345 
00346 
00359     PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring)
00360     : upper(upperLimit)
00361     , lower(lowerLimit)
00362     {
00363         stiffness = spring.stiffness;
00364         damping = spring.damping;
00365     }
00366 
00367 
00373     PX_INLINE bool isValid() const
00374     {
00375         return PxJointLimitParameters::isValid() &&
00376                PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower &&
00377                PxIsFinite(contactDistance) && contactDistance <= upper - lower;
00378     }
00379 };
00380 
00381 
00382 
00390 class PxJointLimitCone : public PxJointLimitParameters
00391 {
00392 //= ATTENTION! =====================================================================================
00393 // Changing the data layout of this class breaks the binary serialization format.  See comments for 
00394 // PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData 
00395 // function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
00396 // accordingly.
00397 //==================================================================================================
00398 public:
00406     PxReal yAngle;
00407 
00408 
00416     PxReal zAngle;
00417 
00428     PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, PxReal contactDist = -1):
00429       yAngle(yLimitAngle),
00430       zAngle(zLimitAngle)
00431       {
00432             PxJointLimitParameters::contactDistance = contactDist == -1 ? PxMin(0.1f, PxMin(yLimitAngle, zLimitAngle)*0.49f) : contactDist;
00433             bounceThreshold = 0.5f;
00434       }
00435 
00436 
00437     
00448       PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, const PxSpring& spring):
00449       yAngle(yLimitAngle),
00450       zAngle(zLimitAngle)
00451       {
00452           stiffness = spring.stiffness;
00453           damping = spring.damping;
00454       }
00455 
00456 
00462     PX_INLINE bool isValid() const
00463     {
00464         return PxJointLimitParameters::isValid() &&
00465                PxIsFinite(yAngle) && yAngle>0 && yAngle<PxPi && 
00466                PxIsFinite(zAngle) && zAngle>0 && zAngle<PxPi;
00467     }
00468 };
00469 
00470 #if !PX_DOXYGEN
00471 } // namespace physx
00472 #endif
00473 
00475 #endif


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