include/extensions/PxJoint.h

File members: include/extensions/PxJoint.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_JOINT_H
#define PX_JOINT_H
#include "foundation/PxTransform.h"
#include "PxRigidActor.h"
#include "PxConstraint.h"
#include "common/PxBase.h"

#if !PX_DOXYGEN
namespace physx
{
#endif

class PxRigidActor;
class PxScene;
class PxPhysics;
class PxConstraint;

struct PxJointConcreteType
{
    enum Enum
    {
        eSPHERICAL = PxConcreteType::eFIRST_PHYSX_EXTENSION,
        eREVOLUTE,
        ePRISMATIC,
        eFIXED,
        eDISTANCE,
        eD6,
        eCONTACT,
        eGEAR,
        eRACK_AND_PINION,
        eLast
    };
};

PX_DEFINE_TYPEINFO(PxJoint,                 PxConcreteType::eUNDEFINED)
PX_DEFINE_TYPEINFO(PxRackAndPinionJoint,    PxJointConcreteType::eRACK_AND_PINION)
PX_DEFINE_TYPEINFO(PxGearJoint,             PxJointConcreteType::eGEAR)
PX_DEFINE_TYPEINFO(PxD6Joint,               PxJointConcreteType::eD6)
PX_DEFINE_TYPEINFO(PxDistanceJoint,         PxJointConcreteType::eDISTANCE)
PX_DEFINE_TYPEINFO(PxContactJoint,          PxJointConcreteType::eCONTACT)
PX_DEFINE_TYPEINFO(PxFixedJoint,            PxJointConcreteType::eFIXED)
PX_DEFINE_TYPEINFO(PxPrismaticJoint,        PxJointConcreteType::ePRISMATIC)
PX_DEFINE_TYPEINFO(PxRevoluteJoint,         PxJointConcreteType::eREVOLUTE)
PX_DEFINE_TYPEINFO(PxSphericalJoint,        PxJointConcreteType::eSPHERICAL)

struct PxJointActorIndex
{
    enum Enum
    {
        eACTOR0,
        eACTOR1,
        COUNT
    };
};

class PxJoint : public PxBase
{
public:

    virtual void                setActors(PxRigidActor* actor0, PxRigidActor* actor1)   = 0;

    virtual void                getActors(PxRigidActor*& actor0, PxRigidActor*& actor1) const   = 0;

    virtual void                setLocalPose(PxJointActorIndex::Enum actor, const PxTransform& localPose) = 0;

    virtual PxTransform         getLocalPose(PxJointActorIndex::Enum actor) const = 0;

    virtual PxTransform         getRelativeTransform()  const   = 0;

    virtual PxVec3              getRelativeLinearVelocity() const   = 0;

    virtual PxVec3              getRelativeAngularVelocity()    const   = 0;

    virtual void                setBreakForce(PxReal force, PxReal torque)  = 0;

    virtual void                getBreakForce(PxReal& force, PxReal& torque)    const   = 0;

    virtual void                setConstraintFlags(PxConstraintFlags flags) = 0;

    virtual void                setConstraintFlag(PxConstraintFlag::Enum flag, bool value)  = 0;

    virtual PxConstraintFlags   getConstraintFlags()    const   = 0;

    virtual void                setInvMassScale0(PxReal invMassScale)   = 0;

    virtual PxReal              getInvMassScale0()  const   = 0;

    virtual void                setInvInertiaScale0(PxReal invInertiaScale) = 0;

    virtual PxReal              getInvInertiaScale0()   const   = 0;

    virtual void                setInvMassScale1(PxReal invMassScale)   = 0;

    virtual PxReal              getInvMassScale1()  const   = 0;

    virtual void                setInvInertiaScale1(PxReal invInertiaScale) = 0;

    virtual PxReal              getInvInertiaScale1()   const   = 0;

    virtual PxConstraint*       getConstraint() const   = 0;

    virtual void                setName(const char* name)   = 0;

    virtual const char*         getName()   const   = 0;

    virtual void                release()   = 0;

    virtual PxScene*            getScene()  const   = 0;

    void*                       userData;

    //serialization

    static  void                getBinaryMetaData(PxOutputStream& stream);

    //~serialization

protected:
    virtual                     ~PxJoint() {}

    //serialization

    PX_INLINE                   PxJoint(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags), userData(NULL) {}

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

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

    //~serialization
};

class PxSpring
{
public:

    PxReal  stiffness;
    PxReal  damping;

    PxSpring(PxReal stiffness_, PxReal damping_): stiffness(stiffness_), damping(damping_) {}
};

#if !PX_DOXYGEN
} // namespace physx
#endif

PX_C_EXPORT void PX_CALL_CONV PxSetJointGlobalFrame(physx::PxJoint& joint, const physx::PxVec3* wsAnchor, const physx::PxVec3* wsAxis);

#endif