#ifndef PX_SOLVER_DEFS_H
#define PX_SOLVER_DEFS_H
#include "PxPhysXConfig.h"
#include "foundation/PxVec3.h"
#include "foundation/PxMat33.h"
#include "foundation/PxTransform.h"
#include "PxConstraintDesc.h"
#include "geomutils/GuContactPoint.h"
#if PX_VC
#pragma warning(push)
#pragma warning(disable : 4324)
#endif
#if !PX_DOXYGEN
namespace physx
{
#endif
struct PxTGSSolverBodyVel;
namespace Dy
{
class ArticulationV;
typedef size_t ArticulationLinkHandle;
}
namespace Sc
{
class ShapeInteraction;
}
struct PxSolverBody
{
PX_ALIGN(16, PxVec3) linearVelocity; PxU16 maxSolverNormalProgress; PxU16 maxSolverFrictionProgress;
PxVec3 angularState;
PxU32 solverProgress;
PxSolverBody() : linearVelocity(0.f), maxSolverNormalProgress(0), maxSolverFrictionProgress(0), angularState(0), solverProgress(0)
{
}
};
PX_COMPILE_TIME_ASSERT(sizeof(PxSolverBody) == 32);
struct PxSolverBodyData
{
PX_ALIGN(16, PxVec3 linearVelocity); PxReal invMass; PxVec3 angularVelocity; PxReal reportThreshold; PxMat33 sqrtInvInertia; PxReal penBiasClamp; PxU32 nodeIndex; PxReal maxContactImpulse; PxTransform body2World; PxU16 lockFlags; PxU16 pad;
PX_FORCE_INLINE PxReal projectVelocity(const PxVec3& lin, const PxVec3& ang) const
{
return linearVelocity.dot(lin) + angularVelocity.dot(ang);
}
};
struct PxConstraintBatchHeader
{
PxU32 startIndex; PxU16 stride; PxU16 constraintType; };
struct PxSolverConstraintDesc
{
static const PxU16 NO_LINK = 0xffff;
enum ConstraintType
{
eCONTACT_CONSTRAINT, eJOINT_CONSTRAINT };
union
{
PxSolverBody* bodyA; PxTGSSolverBodyVel* tgsBodyA; Dy::ArticulationV* articulationA;
};
union
{
PxSolverBody* bodyB; PxTGSSolverBodyVel* tgsBodyB; Dy::ArticulationV* articulationB; };
PxU16 linkIndexA; PxU16 linkIndexB; PxU32 bodyADataIndex; PxU32 bodyBDataIndex; PxU16 writeBackLengthOver4; PxU16 constraintLengthOver16; PxU8* constraint; void* writeBack; };
struct PxSolverConstraintPrepDescBase
{
enum BodyState
{
eDYNAMIC_BODY = 1 << 0,
eSTATIC_BODY = 1 << 1,
eKINEMATIC_BODY = 1 << 2,
eARTICULATION = 1 << 3
};
PxConstraintInvMassScale invMassScales;
PxSolverConstraintDesc* desc;
const PxSolverBody* body0; const PxSolverBody* body1;
const PxSolverBodyData* data0; const PxSolverBodyData* data1;
PxTransform bodyFrame0; PxTransform bodyFrame1;
BodyState bodyState0; BodyState bodyState1; };
struct PxSolverConstraintPrepDesc : public PxSolverConstraintPrepDescBase
{
PX_ALIGN(16, Px1DConstraint* rows); PxU32 numRows;
PxReal linBreakForce, angBreakForce; PxReal minResponseThreshold; void* writeback; bool disablePreprocessing; bool improvedSlerp; bool driveLimitsAreForces; bool extendedLimits;
PxVec3 body0WorldOffset; };
struct PxSolverContactDesc : public PxSolverConstraintPrepDescBase
{
PX_ALIGN(16, Sc::ShapeInteraction* shapeInteraction); Gu::ContactPoint* contacts; PxU32 numContacts;
bool hasMaxImpulse; bool disableStrongFriction; bool hasForceThresholds;
PxReal restDistance; PxReal maxCCDSeparation;
PxU8* frictionPtr; PxU8 frictionCount;
PxReal* contactForces;
PxU32 startFrictionPatchIndex; PxU32 numFrictionPatches;
PxU32 startContactPatchIndex; PxU16 numContactPatches; PxU16 axisConstraintCount;
PxU8 pad[16 - sizeof(void*)];
};
class PxConstraintAllocator
{
public:
virtual PxU8* reserveConstraintData(const PxU32 byteSize) = 0;
virtual PxU8* reserveFrictionData(const PxU32 byteSize) = 0;
virtual ~PxConstraintAllocator() {}
};
struct PxArticulationAxis
{
enum Enum
{
eTWIST = 0,
eSWING1 = 1,
eSWING2 = 2,
eX = 3,
eY = 4,
eZ = 5,
eCOUNT = 6
};
};
PX_FLAGS_OPERATORS(PxArticulationAxis::Enum, PxU8)
struct PxArticulationMotion
{
enum Enum
{
eLOCKED = 0,
eLIMITED = 1,
eFREE = 2
};
};
typedef PxFlags<PxArticulationMotion::Enum, PxU8> PxArticulationMotions;
PX_FLAGS_OPERATORS(PxArticulationMotion::Enum, PxU8)
struct PxArticulationJointType
{
enum Enum
{
ePRISMATIC = 0,
eREVOLUTE = 1,
eSPHERICAL = 2,
eFIX = 3,
eUNDEFINED = 4
};
};
struct PxArticulationFlag
{
enum Enum
{
eFIX_BASE = (1 << 0),
eDRIVE_LIMITS_ARE_FORCES = (1<<1)
};
};
typedef PxFlags<PxArticulationFlag::Enum, PxU8> PxArticulationFlags;
PX_FLAGS_OPERATORS(PxArticulationFlag::Enum, PxU8)
struct PxArticulationDriveType
{
enum Enum
{
eFORCE = 0,
eACCELERATION = 1,
eTARGET = 2,
eVELOCITY = 3,
eNONE = 4
};
};
struct PxArticulationLimit
{
PxReal low, high;
};
struct PxArticulationDrive
{
PxReal stiffness, damping, maxForce;
PxArticulationDriveType::Enum driveType;
};
struct PxTGSSolverBodyVel
{
PX_ALIGN(16, PxVec3) linearVelocity; PxU16 nbStaticInteractions; PxU16 maxDynamicPartition; PxVec3 angularVelocity; PxU32 partitionMask; PxVec3 deltaAngDt; PxReal maxAngVel; PxVec3 deltaLinDt; PxU16 lockFlags; bool isKinematic; PxU8 pad;
PX_FORCE_INLINE PxReal projectVelocity(const PxVec3& lin, const PxVec3& ang) const
{
return linearVelocity.dot(lin) + angularVelocity.dot(ang);
}
};
struct PxTGSSolverBodyTxInertia
{
PxTransform deltaBody2World;
PxMat33 sqrtInvInertia;
};
struct PxTGSSolverBodyData
{
PX_ALIGN(16, PxVec3) originalLinearVelocity;
PxReal maxContactImpulse;
PxVec3 originalAngularVelocity;
PxReal penBiasClamp;
PxReal invMass;
PxU32 nodeIndex;
PxReal reportThreshold;
PxU32 pad;
PxReal projectVelocity(const PxVec3& linear, const PxVec3& angular) const
{
return originalLinearVelocity.dot(linear) + originalAngularVelocity.dot(angular);
}
};
struct PxTGSSolverConstraintPrepDescBase
{
PxConstraintInvMassScale invMassScales;
PxSolverConstraintDesc* desc;
const PxTGSSolverBodyVel* body0; const PxTGSSolverBodyVel *body1;
const PxTGSSolverBodyTxInertia* body0TxI;
const PxTGSSolverBodyTxInertia* body1TxI;
const PxTGSSolverBodyData* bodyData0;
const PxTGSSolverBodyData* bodyData1;
PxTransform bodyFrame0; PxTransform bodyFrame1;
PxSolverContactDesc::BodyState bodyState0; PxSolverContactDesc::BodyState bodyState1;
};
struct PxTGSSolverConstraintPrepDesc : public PxTGSSolverConstraintPrepDescBase
{
Px1DConstraint* rows; PxU32 numRows;
PxReal linBreakForce, angBreakForce; PxReal minResponseThreshold; void* writeback; bool disablePreprocessing; bool improvedSlerp; bool driveLimitsAreForces; bool extendedLimits;
PxVec3 body0WorldOffset; PxVec3 cA2w; PxVec3 cB2w; };
struct PxTGSSolverContactDesc : public PxTGSSolverConstraintPrepDescBase
{
Sc::ShapeInteraction* shapeInteraction; Gu::ContactPoint* contacts; PxU32 numContacts;
bool hasMaxImpulse; bool disableStrongFriction; bool hasForceThresholds;
PxReal restDistance; PxReal maxCCDSeparation;
PxU8* frictionPtr; PxU8 frictionCount;
PxReal* contactForces;
PxU32 startFrictionPatchIndex; PxU32 numFrictionPatches;
PxU32 startContactPatchIndex; PxU16 numContactPatches; PxU16 axisConstraintCount;
PxReal maxImpulse;
PxReal torsionalPatchRadius;
PxReal minTorsionalPatchRadius;
};
#if !PX_DOXYGEN
}
#endif
#if PX_VC
#pragma warning(pop)
#endif
#endif