Program Listing for include/extensions/PxJointLimit.h

↰ Return to documentation for include/extensions/PxJointLimit.h

// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//  * Redistributions of source code must retain the above copyright
//    notice, this list of conditions and the following disclaimer.
//  * Redistributions in binary form must reproduce the above copyright
//    notice, this list of conditions and the following disclaimer in the
//    documentation and/or other materials provided with the distribution.
//  * Neither the name of NVIDIA CORPORATION nor the names of its
//    contributors may be used to endorse or promote products derived
//    from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.

#ifndef PX_JOINT_LIMIT_H
#define PX_JOINT_LIMIT_H

#include "foundation/PxMath.h"
#include "common/PxTolerancesScale.h"
#include "extensions/PxJoint.h"
#include "PxPhysXConfig.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

class PxJointLimitParameters
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format.  See comments for
// PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData
// function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
    PxReal restitution;

    PxReal bounceThreshold;

    PxReal stiffness;

    PxReal damping;

    PxReal contactDistance_deprecated;

    PxJointLimitParameters() :
        restitution     (0.0f),
        bounceThreshold (0.0f),
        stiffness       (0.0f),
        damping         (0.0f),
        contactDistance_deprecated  (0.0f)
    {
    }

    PxJointLimitParameters(const PxJointLimitParameters& p) :
        restitution     (p.restitution),
        bounceThreshold (p.bounceThreshold),
        stiffness       (p.stiffness),
        damping         (p.damping),
        contactDistance_deprecated  (p.contactDistance_deprecated)
    {
    }

    PX_INLINE bool isValid() const
    {
        return  PxIsFinite(restitution) && restitution >= 0 && restitution <= 1 &&
                PxIsFinite(stiffness) && stiffness >= 0 &&
                PxIsFinite(damping) && damping >= 0 &&
                PxIsFinite(bounceThreshold) && bounceThreshold >= 0 &&
                PxIsFinite(contactDistance_deprecated) && contactDistance_deprecated >= 0;
    }

    PX_INLINE bool isSoft() const
    {
        return damping>0 || stiffness>0;
    }

protected:
    ~PxJointLimitParameters() {}
};


class PxJointLinearLimit : public PxJointLimitParameters
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format.  See comments for
// PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData
// function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
    PxReal value;

    PxJointLinearLimit(const PxTolerancesScale& scale, PxReal extent, PxReal contactDist_deprecated = -1.0f)
    : value(extent)
    {
        PxJointLimitParameters::contactDistance_deprecated = contactDist_deprecated == -1.0f ? 0.01f*scale.length : contactDist_deprecated;
    }

    PxJointLinearLimit(PxReal extent, const PxSpring& spring) : value(extent)
    {
        stiffness = spring.stiffness;
        damping = spring.damping;
    }

    PX_INLINE bool isValid() const
    {
        return PxJointLimitParameters::isValid() &&
               PxIsFinite(value) &&
               value > 0.0f;
    }
};


class PxJointLinearLimitPair : public PxJointLimitParameters
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format.  See comments for
// PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData
// function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
    PxReal upper, lower;

    PxJointLinearLimitPair(const PxTolerancesScale& scale, PxReal lowerLimit = -PX_MAX_F32/3.0f, PxReal upperLimit = PX_MAX_F32/3.0f, PxReal contactDist_deprecated = -1.0f) :
        upper(upperLimit),
        lower(lowerLimit)
    {
        PxJointLimitParameters::contactDistance_deprecated = contactDist_deprecated == -1.0f ? PxMin(scale.length * 0.01f, (upperLimit*0.49f-lowerLimit*0.49f)) : contactDist_deprecated;
        bounceThreshold = 2.0f*scale.length;
    }

    PxJointLinearLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring) :
        upper(upperLimit),
        lower(lowerLimit)
    {
        stiffness = spring.stiffness;
        damping = spring.damping;
    }

    PX_INLINE bool isValid() const
    {
        return PxJointLimitParameters::isValid() &&
               PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower &&
               PxIsFinite(upper - lower);
    }
};


class PxJointAngularLimitPair : public PxJointLimitParameters
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format.  See comments for
// PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData
// function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
    PxReal upper, lower;

    PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, PxReal contactDist_deprecated = -1.0f) :
        upper(upperLimit),
        lower(lowerLimit)
    {
        PxJointLimitParameters::contactDistance_deprecated = contactDist_deprecated ==-1.0f ? PxMin(0.1f, 0.49f*(upperLimit-lowerLimit)) : contactDist_deprecated;
        bounceThreshold = 0.5f;
    }

    PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring) :
        upper(upperLimit),
        lower(lowerLimit)
    {
        stiffness = spring.stiffness;
        damping = spring.damping;
    }

    PX_INLINE bool isValid() const
    {
        return PxJointLimitParameters::isValid() &&
               PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower;
    }
};

class PxJointLimitCone : public PxJointLimitParameters
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format.  See comments for
// PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData
// function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
    PxReal yAngle;

    PxReal zAngle;

    PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, PxReal contactDist_deprecated = -1.0f) :
        yAngle(yLimitAngle),
        zAngle(zLimitAngle)
    {
        PxJointLimitParameters::contactDistance_deprecated = contactDist_deprecated == -1.0f ? PxMin(0.1f, PxMin(yLimitAngle, zLimitAngle)*0.49f) : contactDist_deprecated;
        bounceThreshold = 0.5f;
    }

    PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, const PxSpring& spring) :
        yAngle(yLimitAngle),
        zAngle(zLimitAngle)
    {
        stiffness = spring.stiffness;
        damping = spring.damping;
    }

    PX_INLINE bool isValid() const
    {
        return PxJointLimitParameters::isValid() &&
               PxIsFinite(yAngle) && yAngle>0 && yAngle<PxPi &&
               PxIsFinite(zAngle) && zAngle>0 && zAngle<PxPi;
    }
};

class PxJointLimitPyramid : public PxJointLimitParameters
{
//= ATTENTION! =====================================================================================
// Changing the data layout of this class breaks the binary serialization format.  See comments for
// PX_BINARY_SERIAL_VERSION.  If a modification is required, please adjust the getBinaryMetaData
// function.  If the modification is made on a custom branch, please change PX_BINARY_SERIAL_VERSION
// accordingly.
//==================================================================================================
public:
    PxReal yAngleMin;

    PxReal yAngleMax;

    PxReal zAngleMin;

    PxReal zAngleMax;

    PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, PxReal contactDist_deprecated = -1.0f) :
        yAngleMin(yLimitAngleMin),
        yAngleMax(yLimitAngleMax),
        zAngleMin(zLimitAngleMin),
        zAngleMax(zLimitAngleMax)
    {
        if(contactDist_deprecated == -1.0f)
        {
            const PxReal contactDistY = PxMin(0.1f, 0.49f*(yLimitAngleMax - yLimitAngleMin));
            const PxReal contactDistZ = PxMin(0.1f, 0.49f*(zLimitAngleMax - zLimitAngleMin));
            PxJointLimitParameters::contactDistance_deprecated = contactDist_deprecated == PxMin(contactDistY, contactDistZ);
        }
        else
        {
            PxJointLimitParameters::contactDistance_deprecated = contactDist_deprecated;
        }

        bounceThreshold = 0.5f;
    }

    PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, const PxSpring& spring) :
        yAngleMin(yLimitAngleMin),
        yAngleMax(yLimitAngleMax),
        zAngleMin(zLimitAngleMin),
        zAngleMax(zLimitAngleMax)
    {
        stiffness = spring.stiffness;
        damping = spring.damping;
    }

    PX_INLINE bool isValid() const
    {
        return PxJointLimitParameters::isValid() &&
                PxIsFinite(yAngleMin) && yAngleMin>-PxPi && yAngleMin<PxPi &&
                PxIsFinite(yAngleMax) && yAngleMax>-PxPi && yAngleMax<PxPi &&
                PxIsFinite(zAngleMin) && zAngleMin>-PxPi && zAngleMin<PxPi &&
                PxIsFinite(zAngleMax) && zAngleMax>-PxPi && zAngleMax<PxPi &&
                yAngleMax>=yAngleMin && zAngleMax>=zAngleMin;
    }
};

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif