include/extensions/PxD6Joint.h

File members: include/extensions/PxD6Joint.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-2023 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_D6_JOINT_H
#define PX_D6_JOINT_H
#include "extensions/PxJoint.h"
#include "extensions/PxJointLimit.h"
#include "foundation/PxFlags.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

class PxD6Joint;

PxD6Joint*  PxD6JointCreate(PxPhysics& physics, PxRigidActor* actor0, const PxTransform& localFrame0, PxRigidActor* actor1, const PxTransform& localFrame1);

struct PxD6Axis
{
    enum Enum
    {
        eX      = 0,
        eY      = 1,
        eZ      = 2,
        eTWIST  = 3,
        eSWING1 = 4,
        eSWING2 = 5,
        eCOUNT  = 6
    };
};

struct PxD6Motion
{
    enum Enum
    {
        eLOCKED,
        eLIMITED,
        eFREE
    };
};

struct PxD6Drive
{
    enum Enum
    {
        eX          = 0,
        eY          = 1,
        eZ          = 2,
        eSWING      = 3,
        eTWIST      = 4,
        eSLERP      = 5,
        eCOUNT      = 6
    };
};

struct PxD6JointDriveFlag
{
    enum Enum
    {
        eACCELERATION   = 1
    };
};
typedef PxFlags<PxD6JointDriveFlag::Enum, PxU32> PxD6JointDriveFlags;
PX_FLAGS_OPERATORS(PxD6JointDriveFlag::Enum, PxU32)

class PxD6JointDrive : public PxSpring
{
public:
    PxReal                  forceLimit;
    PxD6JointDriveFlags     flags;

    PxD6JointDrive(): PxSpring(0,0), forceLimit(PX_MAX_F32), flags(0) {}

    PxD6JointDrive(PxReal driveStiffness, PxReal driveDamping, PxReal driveForceLimit, bool isAcceleration = false)
    : PxSpring(driveStiffness, driveDamping)
    , forceLimit(driveForceLimit)
    , flags(isAcceleration?PxU32(PxD6JointDriveFlag::eACCELERATION) : 0)
    {}

    bool isValid() const
    {
        return PxIsFinite(stiffness) && stiffness>=0 &&
               PxIsFinite(damping) && damping >=0 &&
               PxIsFinite(forceLimit) && forceLimit >=0;
    }
};

class PxD6Joint : public PxJoint
{
public:

    virtual void                setMotion(PxD6Axis::Enum axis, PxD6Motion::Enum type)   = 0;

    virtual PxD6Motion::Enum    getMotion(PxD6Axis::Enum axis)  const   = 0;

    virtual PxReal              getTwistAngle() const   = 0;

    PX_DEPRECATED   PX_FORCE_INLINE PxReal              getTwist()  const   { return getTwistAngle();   }

    virtual PxReal              getSwingYAngle()    const   = 0;

    virtual PxReal              getSwingZAngle()    const   = 0;

    virtual void                setDistanceLimit(const PxJointLinearLimit& limit)   = 0;

    virtual PxJointLinearLimit  getDistanceLimit()  const   = 0;

    PX_DEPRECATED   PX_FORCE_INLINE void                setLinearLimit(const PxJointLinearLimit& limit) { setDistanceLimit(limit);      }

    PX_DEPRECATED   PX_FORCE_INLINE PxJointLinearLimit  getLinearLimit()    const                       { return getDistanceLimit();    }

    virtual void                    setLinearLimit(PxD6Axis::Enum axis, const PxJointLinearLimitPair& limit)    = 0;

    virtual PxJointLinearLimitPair  getLinearLimit(PxD6Axis::Enum axis) const   = 0;

    virtual void                setTwistLimit(const PxJointAngularLimitPair& limit) = 0;

    virtual PxJointAngularLimitPair getTwistLimit() const   = 0;

    virtual void                setSwingLimit(const PxJointLimitCone& limit)    = 0;

    virtual PxJointLimitCone    getSwingLimit() const   = 0;

    virtual void                setPyramidSwingLimit(const PxJointLimitPyramid& limit)  = 0;

    virtual PxJointLimitPyramid getPyramidSwingLimit()  const   = 0;

    virtual void                setDrive(PxD6Drive::Enum index, const PxD6JointDrive& drive)    = 0;

    virtual PxD6JointDrive      getDrive(PxD6Drive::Enum index) const   = 0;

    virtual void                setDrivePosition(const PxTransform& pose, bool autowake = true) = 0;

    virtual PxTransform         getDrivePosition()  const   = 0;

    virtual void                setDriveVelocity(const PxVec3& linear, const PxVec3& angular, bool autowake = true) = 0;

    virtual void                getDriveVelocity(PxVec3& linear, PxVec3& angular)   const   = 0;

    virtual const char*         getConcreteTypeName() const { return "PxD6Joint"; }

protected:

    //serialization

    PX_INLINE                   PxD6Joint(PxType concreteType, PxBaseFlags baseFlags) : PxJoint(concreteType, baseFlags) {}

    PX_INLINE                   PxD6Joint(PxBaseFlags baseFlags) : PxJoint(baseFlags) {}

    virtual bool                isKindOf(const char* name) const { PX_IS_KIND_OF(name, "PxD6Joint", PxJoint); }

    //~serialization
};

#if !PX_DOXYGEN
} // namespace physx
#endif

#endif