You're breathtaking!

This commit is contained in:
Wojtek Figat
2020-12-07 23:40:54 +01:00
commit 6fb9eee74c
5143 changed files with 1153594 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
//
// 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-2019 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_BINARY_CONVERTER_H
#define PX_BINARY_CONVERTER_H
/** \addtogroup extensions
@{
*/
#include "common/PxPhysXCommonConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
struct PxConverterReportMode
{
enum Enum
{
eNONE, //!< Silent mode. If enabled, no information is sent to the error stream.
eNORMAL, //!< Normal mode. If enabled, only important information is sent to the error stream.
eVERBOSE //!< Verbose mode. If enabled, detailed information is sent to the error stream.
};
};
/**
\brief Binary converter for serialized streams.
The binary converter class is targeted at converting binary streams from authoring platforms,
such as windows, osx or linux to any game runtime platform supported by PhysX. Particularly
it is currently not supported to run the converter on a platforms that has an endian mismatch
with the platform corresponding to the source binary file and source meta data.
If you want to use multiple threads for batch conversions, please create one instance
of this class for each thread.
@see PxSerialization.createBinaryConverter
*/
class PxBinaryConverter
{
public:
/**
\brief Releases binary converter
*/
virtual void release() = 0;
/**
\brief Sets desired report mode.
\param[in] mode Report mode
*/
virtual void setReportMode(PxConverterReportMode::Enum mode) = 0;
/**
\brief Setups source and target meta-data streams
The source meta data provided needs to have the same endianness as the platform the converter is run on.
The meta data needs to be set before calling the conversion method.
\param[in] srcMetaData Source platform's meta-data stream
\param[in] dstMetaData Target platform's meta-data stream
\return True if success
@see PxSerialization::dumpBinaryMetaData
*/
virtual bool setMetaData(PxInputStream& srcMetaData, PxInputStream& dstMetaData) = 0;
/**
\brief Test utility function to compare two sets of meta data.
The meta data needs to be set before calling the compareMetaData method.
This method will issue PxErrorCode::eDEBUG_INFO messages if mismatches are encountered.
\return True if meta data is equivalend
*/
virtual bool compareMetaData() const = 0;
/**
\brief Converts binary stream from source platform to target platform
The converter needs to be configured with source and destination meta data before calling the conversion method.
The source meta data needs to correspond to the same platform as the source binary data.
\param[in] srcStream Source stream
\param[in] srcSize Number of bytes to convert
\param[in] targetStream Target stream
\return True if success
*/
virtual bool convert(PxInputStream& srcStream, PxU32 srcSize, PxOutputStream& targetStream) = 0;
protected:
PxBinaryConverter() {}
virtual ~PxBinaryConverter() {}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,75 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_BROAD_PHASE_H
#define PX_PHYSICS_EXTENSIONS_BROAD_PHASE_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "common/PxPhysXCommonConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxBroadPhaseExt
{
public:
/**
\brief Creates regions for PxSceneDesc, from a global box.
This helper simply subdivides the given global box into a 2D grid of smaller boxes. Each one of those smaller boxes
is a region of interest for the broadphase. There are nbSubdiv*nbSubdiv regions in the 2D grid. The function does not
subdivide along the given up axis.
This is the simplest setup one can use with PxBroadPhaseType::eMBP. A more sophisticated setup would try to cover
the game world with a non-uniform set of regions (i.e. not just a grid).
\param[out] regions Regions computed from the input global box
\param[in] globalBounds World-space box covering the game world
\param[in] nbSubdiv Grid subdivision level. The function will create nbSubdiv*nbSubdiv regions.
\param[in] upAxis Up axis (0 for X, 1 for Y, 2 for Z).
\return number of regions written out to the 'regions' array
@see PxSceneDesc PxBroadPhaseType
*/
static PxU32 createRegionsFromWorldBounds(PxBounds3* regions, const PxBounds3& globalBounds, PxU32 nbSubdiv, PxU32 upAxis=1);
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,119 @@
//
// 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-2019 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_COLLECTION_EXT_H
#define PX_COLLECTION_EXT_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "common/PxCollection.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxCollectionExt
{
public:
/**
\brief Removes and releases all object from a collection.
The Collection itself is not released.
If the releaseExclusiveShapes flag is not set to true, release() will not be called on exclusive shapes.
It is assumed that the application holds a reference to each of the objects in the collection, with the exception of objects that are not releasable
(PxBase::isReleasable()). In general, objects that violate this assumption need to be removed from the collection prior to calling releaseObjects.
\note when a shape is created with PxRigidActor::createShape() or PxRigidActorExt::createExclusiveShape(), the only counted reference is held by the actor.
If such a shape and its actor are present in the collection, the reference count will be decremented once when the actor is released, and once when the
shape is released, resulting in undefined behavior. Shape reference counts can be incremented with PxShape::acquireReference().
\param[in] collection to remove and release all object from.
\param[in] releaseExclusiveShapes if this parameter is set to false, release() will not be called on exclusive shapes.
*/
static void releaseObjects(PxCollection& collection, bool releaseExclusiveShapes = true);
/**
\brief Removes objects of a given type from a collection, potentially adding them to another collection.
\param[in,out] collection Collection from which objects are removed
\param[in] concreteType PxConcreteType of sdk objects that should be removed
\param[in,out] to Optional collection to which the removed objects are added
@see PxCollection, PxConcreteType
*/
static void remove(PxCollection& collection, PxType concreteType, PxCollection* to = NULL);
/**
\brief Collects all objects in PxPhysics that are shareable across multiple scenes.
This function creates a new collection from all objects that are shareable across multiple
scenes. Instances of the following types are included: PxConvexMesh, PxTriangleMesh,
PxHeightField, PxShape and PxMaterial.
This is a helper function to ease the creation of collections for serialization.
\param[in] physics The physics SDK instance from which objects are collected. See #PxPhysics
\return Collection to which objects are added. See #PxCollection
@see PxCollection, PxPhysics
*/
static PxCollection* createCollection(PxPhysics& physics);
/**
\brief Collects all objects from a PxScene.
This function creates a new collection from all objects that where added to the specified
PxScene. Instances of the following types are included: PxActor, PxAggregate,
PxArticulation and PxJoint (other PxConstraint types are not included).
This is a helper function to ease the creation of collections for serialization.
The function PxSerialization.complete() can be used to complete the collection with required objects prior to
serialization.
\param[in] scene The PxScene instance from which objects are collected. See #PxScene
\return Collection to which objects are added. See #PxCollection
@see PxCollection, PxScene, PxSerialization.complete()
*/
static PxCollection* createCollection(PxScene& scene);
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,70 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_CONSTRAINT_H
#define PX_PHYSICS_EXTENSIONS_CONSTRAINT_H
#include "foundation/PxPreprocessor.h"
/** \addtogroup extensions
@{
*/
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Unique identifiers for extensions classes which implement a constraint based on PxConstraint.
\note Users which want to create their own custom constraint types should choose an ID larger or equal to eNEXT_FREE_ID
and not eINVALID_ID.
@see PxConstraint PxSimulationEventCallback.onConstraintBreak()
*/
struct PxConstraintExtIDs
{
enum Enum
{
eJOINT,
eVEHICLE_SUSP_LIMIT,
eVEHICLE_STICKY_TYRE,
eNEXT_FREE_ID,
eINVALID_ID = 0x7fffffff
};
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,168 @@
//
// 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-2019 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_CONTACTJOINT_H
#define PX_CONTACTJOINT_H
#include "extensions/PxJoint.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxContactJoint;
/**
\brief Create a distance Joint.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame0 The position and orientation of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame1 The position and orientation of the joint relative to actor1
@see PxContactJoint
*/
PxContactJoint* PxContactJointCreate(PxPhysics& physics, PxRigidActor* actor0, const PxTransform& localFrame0, PxRigidActor* actor1, const PxTransform& localFrame1);
/**
\brief a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
@see PxContactJointCreate PxJoint
*/
struct PxJacobianRow
{
PxVec3 linear0;
PxVec3 linear1;
PxVec3 angular0;
PxVec3 angular1;
PxJacobianRow(){}
PxJacobianRow(const PxVec3& lin0, const PxVec3& lin1, const PxVec3& ang0, const PxVec3& ang1) :
linear0(lin0), linear1(lin1), angular0(ang0), angular1(ang1)
{
}
void operator *= (const PxReal scale)
{
linear0 *= scale;
linear1 *= scale;
angular0 *= scale;
angular1 *= scale;
}
PxJacobianRow operator * (const PxReal scale) const
{
return PxJacobianRow(linear0*scale, linear1*scale, angular0*scale, angular1*scale);
}
};
/**
\brief a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
@see PxContactJointCreate PxJoint
*/
class PxContactJoint : public PxJoint
{
public:
/**
\brief Set the current contact of the joint
*/
virtual void setContact(const PxVec3& contact) = 0;
/**
\brief Set the current contact normal of the joint
*/
virtual void setContactNormal(const PxVec3& contactNormal) = 0;
/**
\brief Set the current penetration of the joint
*/
virtual void setPenetration(const PxReal penetration) = 0;
/**
\brief Return the current contact of the joint
*/
virtual PxVec3 getContact() const = 0;
/**
\brief Return the current contact normal of the joint
*/
virtual PxVec3 getContactNormal() const = 0;
/**
\brief Return the current penetration value of the joint
*/
virtual PxReal getPenetration() const = 0;
virtual PxReal getResititution() const = 0;
virtual void setResititution(const PxReal resititution) = 0;
virtual PxReal getBounceThreshold() const = 0;
virtual void setBounceThreshold(const PxReal bounceThreshold) = 0;
/**
\brief Returns string name of PxContactJoint, used for serialization
*/
virtual const char* getConcreteTypeName() const { return "PxContactJoint"; }
virtual void computeJacobians(PxJacobianRow* jacobian) const = 0;
virtual PxU32 getNbJacobianRows() const = 0;
protected:
//serialization
/**
\brief Constructor
*/
PX_INLINE PxContactJoint(PxType concreteType, PxBaseFlags baseFlags) : PxJoint(concreteType, baseFlags) {}
/**
\brief Deserialization constructor
*/
PX_INLINE PxContactJoint(PxBaseFlags baseFlags) : PxJoint(baseFlags) {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* name) const { return !::strcmp("PxContactJoint", name) || PxJoint::isKindOf(name); }
//~serialization
};
#if !PX_DOXYGEN
}
#endif
#endif

View File

@@ -0,0 +1,73 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_CONVEX_MESH_H
#define PX_PHYSICS_EXTENSIONS_CONVEX_MESH_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "common/PxPhysXCommonConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxConvexMeshGeometry;
/**
\brief Computes closest polygon of the convex hull geometry for a given impact point
and impact direction. When doing sweeps against a scene, one might want to delay
the rather expensive computation of the hit face index for convexes until it is clear
the information is really needed and then use this method to get the corresponding
face index.
\param[in] convexGeom The convex mesh geometry.
\param[in] geomPose Pose for the geometry object.
\param[in] impactPos Impact position.
\param[in] unitDir Normalized impact direction.
\return Closest face index of the convex geometry.
@see PxTransform PxConvexMeshGeometry
*/
PxU32 PxFindFaceIndex(const PxConvexMeshGeometry& convexGeom,
const PxTransform& geomPose,
const PxVec3& impactPos,
const PxVec3& unitDir);
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,561 @@
//
// 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-2019 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_D6JOINT_H
#define PX_D6JOINT_H
/** \addtogroup extensions
@{
*/
#include "extensions/PxJoint.h"
#include "extensions/PxJointLimit.h"
#include "foundation/PxFlags.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxD6Joint;
/**
\brief Create a D6 joint.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame0 The position and orientation of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame1 The position and orientation of the joint relative to actor1
@see PxD6Joint
*/
PxD6Joint* PxD6JointCreate(PxPhysics& physics, PxRigidActor* actor0, const PxTransform& localFrame0, PxRigidActor* actor1, const PxTransform& localFrame1);
/**
\brief Used to specify one of the degrees of freedom of a D6 joint.
@see PxD6Joint
*/
struct PxD6Axis
{
enum Enum
{
eX = 0, //!< motion along the X axis
eY = 1, //!< motion along the Y axis
eZ = 2, //!< motion along the Z axis
eTWIST = 3, //!< motion around the X axis
eSWING1 = 4, //!< motion around the Y axis
eSWING2 = 5, //!< motion around the Z axis
eCOUNT = 6
};
};
/**
\brief Used to specify the range of motions allowed for a degree of freedom in a D6 joint.
@see PxD6Joint
*/
struct PxD6Motion
{
enum Enum
{
eLOCKED, //!< The DOF is locked, it does not allow relative motion.
eLIMITED, //!< The DOF is limited, it only allows motion within a specific range.
eFREE //!< The DOF is free and has its full range of motion.
};
};
/**
\brief Used to specify which axes of a D6 joint are driven.
Each drive is an implicit force-limited damped spring:
force = spring * (target position - position) + damping * (targetVelocity - velocity)
Alternatively, the spring may be configured to generate a specified acceleration instead of a force.
A linear axis is affected by drive only if the corresponding drive flag is set. There are two possible models
for angular drive: swing/twist, which may be used to drive one or more angular degrees of freedom, or slerp,
which may only be used to drive all three angular degrees simultaneously.
@see PxD6Joint
*/
struct PxD6Drive
{
enum Enum
{
eX = 0, //!< drive along the X-axis
eY = 1, //!< drive along the Y-axis
eZ = 2, //!< drive along the Z-axis
eSWING = 3, //!< drive of displacement from the X-axis
eTWIST = 4, //!< drive of the displacement around the X-axis
eSLERP = 5, //!< drive of all three angular degrees along a SLERP-path
eCOUNT = 6
};
};
/**
\brief flags for configuring the drive model of a PxD6Joint
@see PxD6JointDrive PxD6Joint
*/
struct PxD6JointDriveFlag
{
enum Enum
{
eACCELERATION = 1 //!< drive spring is for the acceleration at the joint (rather than the force)
};
};
typedef PxFlags<PxD6JointDriveFlag::Enum, PxU32> PxD6JointDriveFlags;
PX_FLAGS_OPERATORS(PxD6JointDriveFlag::Enum, PxU32)
/**
\brief parameters for configuring the drive model of a PxD6Joint
@see PxD6Joint
*/
class PxD6JointDrive : public PxSpring
{
//= 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 forceLimit; //!< the force limit of the drive - may be an impulse or a force depending on PxConstraintFlag::eDRIVE_LIMITS_ARE_FORCES
PxD6JointDriveFlags flags; //!< the joint drive flags
/**
\brief default constructor for PxD6JointDrive.
*/
PxD6JointDrive(): PxSpring(0,0), forceLimit(PX_MAX_F32), flags(0) {}
/**
\brief constructor a PxD6JointDrive.
\param[in] driveStiffness The stiffness of the drive spring.
\param[in] driveDamping The damping of the drive spring
\param[in] driveForceLimit The maximum impulse or force that can be exerted by the drive
\param[in] isAcceleration Whether the drive is an acceleration drive or a force drive
*/
PxD6JointDrive(PxReal driveStiffness, PxReal driveDamping, PxReal driveForceLimit, bool isAcceleration = false)
: PxSpring(driveStiffness, driveDamping)
, forceLimit(driveForceLimit)
, flags(isAcceleration?PxU32(PxD6JointDriveFlag::eACCELERATION) : 0)
{}
/**
\brief returns true if the drive is valid
*/
bool isValid() const
{
return PxIsFinite(stiffness) && stiffness>=0 &&
PxIsFinite(damping) && damping >=0 &&
PxIsFinite(forceLimit) && forceLimit >=0;
}
};
/**
\brief A D6 joint is a general constraint between two actors.
It allows the application to individually define the linear and rotational degrees of freedom,
and also to configure a variety of limits and driven degrees of freedom.
By default all degrees of freedom are locked. So to create a prismatic joint with free motion
along the x-axis:
\code
...
joint->setMotion(PxD6Axis::eX, PxD6JointMotion::eFREE);
...
\endcode
Or a Revolute joint with motion free allowed around the x-axis:
\code
...
joint->setMotion(PxD6Axis::eTWIST, PxD6JointMotion::eFREE);
...
\endcode
Degrees of freedom may also be set to limited instead of locked.
There are two different kinds of linear limits available. The first kind is a single limit value
for all linear degrees of freedom, which may act as a linear, circular, or spherical limit depending
on which degrees of freedom are limited. This is similar to a distance limit. Then, the second kind
supports a pair of limit values for each linear axis, which can be used to implement a traditional
prismatic joint for example.
If the twist degree of freedom is limited, is supports upper and lower limits. The two swing degrees
of freedom are limited with a cone limit.
@see PxD6JointCreate() PxJoint
*/
class PxD6Joint : public PxJoint
{
public:
/**
\brief Set the motion type around the specified axis.
Each axis may independently specify that the degree of freedom is locked (blocking relative movement
along or around this axis), limited by the corresponding limit, or free.
\param[in] axis the axis around which motion is specified
\param[in] type the motion type around the specified axis
<b>Default:</b> all degrees of freedom are locked
@see getMotion() PxD6Axis PxD6Motion
*/
virtual void setMotion(PxD6Axis::Enum axis, PxD6Motion::Enum type) = 0;
/**
\brief Get the motion type around the specified axis.
@see setMotion() PxD6Axis PxD6Motion
\param[in] axis the degree of freedom around which the motion type is specified
\return the motion type around the specified axis
*/
virtual PxD6Motion::Enum getMotion(PxD6Axis::Enum axis) const = 0;
/**
\brief get the twist angle of the joint, in the range (-2*Pi, 2*Pi]
*/
virtual PxReal getTwistAngle() const = 0;
/**
\brief get the twist angle of the joint
\deprecated Use getTwistAngle instead. Deprecated since PhysX version 4.0
*/
PX_DEPRECATED PX_FORCE_INLINE PxReal getTwist() const { return getTwistAngle(); }
/**
\brief get the swing angle of the joint from the Y axis
*/
virtual PxReal getSwingYAngle() const = 0;
/**
\brief get the swing angle of the joint from the Z axis
*/
virtual PxReal getSwingZAngle() const = 0;
/**
\brief Set the distance limit for the joint.
A single limit constraints all linear limited degrees of freedom, forming a linear, circular
or spherical constraint on motion depending on the number of limited degrees. This is similar
to a distance limit.
\param[in] limit the distance limit structure
@see getDistanceLimit() PxJointLinearLimit
*/
virtual void setDistanceLimit(const PxJointLinearLimit& limit) = 0;
/**
\brief Get the distance limit for the joint.
\return the distance limit structure
@see setDistanceLimit() PxJointLinearLimit
*/
virtual PxJointLinearLimit getDistanceLimit() const = 0;
/**
\deprecated Use setDistanceLimit instead. Deprecated since PhysX version 4.0
*/
PX_DEPRECATED PX_FORCE_INLINE void setLinearLimit(const PxJointLinearLimit& limit) { setDistanceLimit(limit); }
/**
\deprecated Use getDistanceLimit instead. Deprecated since PhysX version 4.0
*/
PX_DEPRECATED PX_FORCE_INLINE PxJointLinearLimit getLinearLimit() const { return getDistanceLimit(); }
/**
\brief Set the linear limit for a given linear axis.
This function extends the previous setDistanceLimit call with the following features:
- there can be a different limit for each linear axis
- each limit is defined by two values, i.e. it can now be asymmetric
This can be used to create prismatic joints similar to PxPrismaticJoint, or point-in-quad joints,
or point-in-box joints.
\param[in] axis The limited linear axis (must be PxD6Axis::eX, PxD6Axis::eY or PxD6Axis::eZ)
\param[in] limit The linear limit pair structure
@see getLinearLimit()
*/
virtual void setLinearLimit(PxD6Axis::Enum axis, const PxJointLinearLimitPair& limit) = 0;
/**
\brief Get the linear limit for a given linear axis.
\param[in] axis The limited linear axis (must be PxD6Axis::eX, PxD6Axis::eY or PxD6Axis::eZ)
\return the linear limit pair structure from desired axis
@see setLinearLimit() PxJointLinearLimit
*/
virtual PxJointLinearLimitPair getLinearLimit(PxD6Axis::Enum axis) const = 0;
/**
\brief Set the twist limit for the joint.
The twist limit controls the range of motion around the twist axis.
The limit angle range is (-2*Pi, 2*Pi).
\param[in] limit the twist limit structure
@see getTwistLimit() PxJointAngularLimitPair
*/
virtual void setTwistLimit(const PxJointAngularLimitPair& limit) = 0;
/**
\brief Get the twist limit for the joint.
\return the twist limit structure
@see setTwistLimit() PxJointAngularLimitPair
*/
virtual PxJointAngularLimitPair getTwistLimit() const = 0;
/**
\brief Set the swing cone limit for the joint.
The cone limit is used if either or both swing axes are limited. The extents are
symmetrical and measured in the frame of the parent. If only one swing degree of freedom
is limited, the corresponding value from the cone limit defines the limit range.
\param[in] limit the cone limit structure
@see getLimitCone() PxJointLimitCone
*/
virtual void setSwingLimit(const PxJointLimitCone& limit) = 0;
/**
\brief Get the cone limit for the joint.
\return the swing limit structure
@see setLimitCone() PxJointLimitCone
*/
virtual PxJointLimitCone getSwingLimit() const = 0;
/**
\brief Set a pyramidal swing limit for the joint.
The pyramid limits will only be used in the following cases:
- both swing Y and Z are limited. The limit shape is then a pyramid.
- Y is limited and Z is locked, or vice versa. The limit shape is an asymmetric angular section, similar to
what is supported for the twist axis.
The remaining cases (Y limited and Z is free, or vice versa) are not supported.
\param[in] limit the cone limit structure
@see getLimitCone() PxJointLimitPyramid
*/
virtual void setPyramidSwingLimit(const PxJointLimitPyramid& limit) = 0;
/**
\brief Get the pyramidal swing limit for the joint.
\return the swing limit structure
@see setLimitCone() PxJointLimitPyramid
*/
virtual PxJointLimitPyramid getPyramidSwingLimit() const = 0;
/**
\brief Set the drive parameters for the specified drive type.
\param[in] index the type of drive being specified
\param[in] drive the drive parameters
@see getDrive() PxD6JointDrive
<b>Default</b> The default drive spring and damping values are zero, the force limit is zero, and no flags are set.
*/
virtual void setDrive(PxD6Drive::Enum index, const PxD6JointDrive& drive) = 0;
/**
\brief Get the drive parameters for the specified drive type.
\param[in] index the specified drive type
@see setDrive() PxD6JointDrive
*/
virtual PxD6JointDrive getDrive(PxD6Drive::Enum index) const = 0;
/**
\brief Set the drive goal pose
The goal is relative to the constraint frame of actor[0]
<b>Default</b> the identity transform
\param[in] pose The goal drive pose if positional drive is in use.
\param[in] autowake Whether to wake the joint rigids up if it is asleep.
@see setDrivePosition()
*/
virtual void setDrivePosition(const PxTransform& pose, bool autowake = true) = 0;
/**
\brief Get the drive goal pose.
@see getDrivePosition()
*/
virtual PxTransform getDrivePosition() const = 0;
/**
\brief Set the target goal velocity for drive.
The velocity is measured in the constraint frame of actor[0]
\param[in] linear The goal velocity for linear drive
\param[in] angular The goal velocity for angular drive
\param[in] autowake Whether to wake the joint rigids up if it is asleep.
@see getDriveVelocity()
*/
virtual void setDriveVelocity(const PxVec3& linear, const PxVec3& angular, bool autowake = true) = 0;
/**
\brief Get the target goal velocity for joint drive.
\param[in] linear The goal velocity for linear drive
\param[in] angular The goal velocity for angular drive
@see setDriveVelocity()
*/
virtual void getDriveVelocity(PxVec3& linear, PxVec3& angular) const = 0;
/**
\brief Set the linear tolerance threshold for projection. Projection is enabled if PxConstraintFlag::ePROJECTION
is set for the joint.
If the joint separates by more than this distance along its locked degrees of freedom, the solver
will move the bodies to close the distance.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 1e10f
\param[in] tolerance the linear tolerance threshold
@see getProjectionLinearTolerance() PxJoint::setConstraintFlags() PxConstraintFlag::ePROJECTION
*/
virtual void setProjectionLinearTolerance(PxReal tolerance) = 0;
/**
\brief Get the linear tolerance threshold for projection.
\return the linear tolerance threshold
@see setProjectionLinearTolerance()
*/
virtual PxReal getProjectionLinearTolerance() const = 0;
/**
\brief Set the angular tolerance threshold for projection. Projection is enabled if
PxConstraintFlag::ePROJECTION is set for the joint.
If the joint deviates by more than this angle around its locked angular degrees of freedom,
the solver will move the bodies to close the angle.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
<b>Range:</b> [0,Pi] <br>
<b>Default:</b> Pi
\param[in] tolerance the angular tolerance threshold in radians
\note
Angular projection is implemented only for the case of two or three locked angular degrees of freedom.
@see getProjectionAngularTolerance() PxJoint::setConstraintFlag() PxConstraintFlag::ePROJECTION
*/
virtual void setProjectionAngularTolerance(PxReal tolerance) = 0;
/**
\brief Get the angular tolerance threshold for projection.
\return tolerance the angular tolerance threshold in radians
@see setProjectionAngularTolerance()
*/
virtual PxReal getProjectionAngularTolerance() const = 0;
/**
\brief Returns string name of PxD6Joint, used for serialization
*/
virtual const char* getConcreteTypeName() const { return "PxD6Joint"; }
protected:
//serialization
/**
\brief Constructor
*/
PX_INLINE PxD6Joint(PxType concreteType, PxBaseFlags baseFlags) : PxJoint(concreteType, baseFlags) {}
/**
\brief Deserialization constructor
*/
PX_INLINE PxD6Joint(PxBaseFlags baseFlags) : PxJoint(baseFlags) {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* name) const { return !::strcmp("PxD6Joint", name) || PxJoint::isKindOf(name); }
//~serialization
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,255 @@
//
// 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-2019 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_D6JOINT_CREATE_H
#define PX_D6JOINT_CREATE_H
#include "common/PxPhysXCommonConfig.h"
/** \addtogroup extensions
@{
*/
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxPhysics;
class PxRigidActor;
class PxJoint;
/**
\brief Helper function to create a fixed joint, using either a PxD6Joint or PxFixedJoint.
For fixed joints it is important that the joint frames have the same orientation. This helper function uses an identity rotation for both.
It is also important that the joint frames have an equivalent position in world space. The function does not check this, so it is up to users
to ensure that this is the case.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos0 The position of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos1 The position of the joint relative to actor1
\param[in] useD6 True to use a PxD6Joint, false to use a PxFixedJoint;
\return The created joint.
@see PxD6Joint PxFixedJoint
*/
PxJoint* PxD6JointCreate_Fixed(PxPhysics& physics, PxRigidActor* actor0, const PxVec3& localPos0, PxRigidActor* actor1, const PxVec3& localPos1, bool useD6);
/**
\brief Helper function to create a distance joint, using either a PxD6Joint or PxDistanceJoint.
This helper function only supports a maximum distance constraint, because PxD6Joint does not support a minimum distance constraint (contrary
to PxDistanceJoint).
The distance is computed between the joint frames' world-space positions. The joint frames' orientations are irrelevant here so the function
sets them to identity.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos0 The position of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos1 The position of the joint relative to actor1
\param[in] maxDist The maximum allowed distance
\param[in] useD6 True to use a PxD6Joint, false to use a PxDistanceJoint;
\return The created joint.
@see PxD6Joint PxDistanceJoint
*/
PxJoint* PxD6JointCreate_Distance(PxPhysics& physics, PxRigidActor* actor0, const PxVec3& localPos0, PxRigidActor* actor1, const PxVec3& localPos1, float maxDist, bool useD6);
/**
\brief Helper function to create a prismatic joint, using either a PxD6Joint or PxPrismaticJoint.
This function enforces that the joint frames have the same orientation, which is a local frame whose X is the desired translation axis.
This orientation is computed by the function, so users only have to define the desired translation axis (typically 1;0;0 or 0;1;0 or 0;0;1).
The translation can be limited. Limits are enforced if minLimit<maxLimit. If minLimit=maxLimit the axis is locked. If minLimit>maxLimit the
limits are not enforced and the axis is free. The limit values are computed relative to the position of actor0's joint frame.
The function creates hard limits, and uses PhysX's default contact distance parameter.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos0 The position of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos1 The position of the joint relative to actor1
\param[in] axis The axis along which objects are allowed to move, expressed in the actors' local space
\param[in] minLimit The minimum allowed position along the axis
\param[in] maxLimit The maximum allowed position along the axis
\param[in] useD6 True to use a PxD6Joint, false to use a PxPrismaticJoint;
\return The created joint.
@see PxD6Joint PxPrismaticJoint
*/
PxJoint* PxD6JointCreate_Prismatic(PxPhysics& physics, PxRigidActor* actor0, const PxVec3& localPos0, PxRigidActor* actor1, const PxVec3& localPos1, const PxVec3& axis, float minLimit, float maxLimit, bool useD6);
/**
\brief Helper function to create a revolute joint, using either a PxD6Joint or PxRevoluteJoint.
This function enforces that the joint frames have the same orientation, which is a local frame whose X is the desired rotation axis.
This orientation is computed by the function, so users only have to define the desired rotation axis (typically 1;0;0 or 0;1;0 or 0;0;1).
The rotation can be limited. Limits are enforced if minLimit<maxLimit. If minLimit=maxLimit the axis is locked. If minLimit>maxLimit the
limits are not enforced and the axis is free. The limit values are computed relative to the rotation of actor0's joint frame.
The function creates hard limits, and uses PhysX's default contact distance parameter.
Limits are expressed in radians. Allowed range is ]-2*PI;+2*PI[
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos0 The position of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos1 The position of the joint relative to actor1
\param[in] axis The axis around which objects are allowed to move, expressed in the actors' local space
\param[in] minLimit The minimum allowed rotation along the axis
\param[in] maxLimit The maximum allowed rotation along the axis
\param[in] useD6 True to use a PxD6Joint, false to use a PxRevoluteJoint;
\return The created joint.
@see PxD6Joint PxRevoluteJoint
*/
PxJoint* PxD6JointCreate_Revolute(PxPhysics& physics, PxRigidActor* actor0, const PxVec3& localPos0, PxRigidActor* actor1, const PxVec3& localPos1, const PxVec3& axis, float minLimit, float maxLimit, bool useD6);
/**
\brief Helper function to create a spherical joint, using either a PxD6Joint or PxSphericalJoint.
This function supports a cone limit shape, defined by a cone axis and two angular limit values.
This function enforces that the joint frames have the same orientation, which is a local frame whose X is the desired cone axis.
This orientation is computed by the function, so users only have to define the desired cone axis (typically 1;0;0 or 0;1;0 or 0;0;1).
The rotations can be limited. Limits are enforced if limit1>0 and limit2>0. Otherwise the motion is free. The limit values define an ellipse,
which is the cross-section of the cone limit shape.
The function creates hard limits, and uses PhysX's default contact distance parameter.
Limits are expressed in radians. Allowed range is ]0;PI[. Limits are symmetric around the cone axis.
The cone axis is equivalent to the twist axis for the D6 joint. The twist motion is not limited.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos0 The position of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos1 The position of the joint relative to actor1
\param[in] axis The cone axis, expressed in the actors' local space
\param[in] limit1 Max angular limit for the ellipse along the joint frame's second axis (first axis = cone axis)
\param[in] limit2 Max angular limit for the ellipse along the joint frame's third axis (first axis = cone axis)
\param[in] useD6 True to use a PxD6Joint, false to use a PxSphericalJoint;
\return The created joint.
@see PxD6Joint PxSphericalJoint
*/
PxJoint* PxD6JointCreate_Spherical(PxPhysics& physics, PxRigidActor* actor0, const PxVec3& localPos0, PxRigidActor* actor1, const PxVec3& localPos1, const PxVec3& axis, float limit1, float limit2, bool useD6);
/**
\brief Helper function to create a spherical joint, using either a PxD6Joint or PxSphericalJoint.
This function supports a cone limit shape, defined by two pairs of angular limit values. This can be used to create an asymmetric cone. If the
angular limit values are symmetric (i.e. minLimit1=-maxLimit1 and minLimit2=-maxLimit2) then the cone axis is the X axis in actor0's space.
If the limits are not symmetric, the function rotates the cone axis accordingly so that limits remain symmetric for PhysX. If this happens,
the initial joint frames will be different for both actors. By default minLimit1/maxLimit1 are limits around the joint's Y axis, and
minLimit2/maxLimit2 are limits around the joint's Z axis.
The function creates hard limits, and uses PhysX's default contact distance parameter.
Limits are expressed in radians. Allowed range is ]-PI;PI[.
The cone axis is equivalent to the twist axis for the D6 joint. The twist motion is not limited.
The returned apiroty and apirotz values can later be added to retrieved Y and Z swing angle values (from the joint), to remap
angle values to the given input range.
\param[out] apiroty Amount of rotation around Y used to setup actor0's joint frame
\param[out] apirotz Amount of rotation around Z used to setup actor0's joint frame
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos0 The position of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos1 The position of the joint relative to actor1
\param[in] minLimit1 Min angular limit along the joint frame's second axis (first axis = cone axis)
\param[in] maxLimit1 Max angular limit along the joint frame's second axis (first axis = cone axis)
\param[in] minLimit2 Min angular limit along the joint frame's third axis (first axis = cone axis)
\param[in] maxLimit2 Max angular limit along the joint frame's third axis (first axis = cone axis)
\param[in] useD6 True to use a PxD6Joint, false to use a PxSphericalJoint;
\return The created joint.
@see PxD6Joint PxSphericalJoint
*/
PxJoint* PxD6JointCreate_GenericCone(float& apiroty, float& apirotz, PxPhysics& physics, PxRigidActor* actor0, const PxVec3& localPos0, PxRigidActor* actor1, const PxVec3& localPos1, float minLimit1, float maxLimit1, float minLimit2, float maxLimit2, bool useD6);
/**
\brief Helper function to create a D6 joint with pyramidal swing limits.
This function supports a pyramid limit shape, defined by two pairs of angular limit values. This can be used to create an asymmetric pyramid. If the
angular limit values are symmetric (i.e. minLimit1=-maxLimit1 and minLimit2=-maxLimit2) then the pyramid axis is the X axis in actor0's space.
By default minLimit1/maxLimit1 are limits around the joint's Y axis, and minLimit2/maxLimit2 are limits around the joint's Z axis.
The function creates hard limits, and uses PhysX's default contact distance parameter.
Limits are expressed in radians. Allowed range is ]-PI;PI[.
The pyramid axis is equivalent to the twist axis for the D6 joint. The twist motion is not limited.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos0 The position of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localPos1 The position of the joint relative to actor1
\param[in] axis The pyramid axis, expressed in the actors' local space
\param[in] minLimit1 Min angular limit along the joint frame's second axis (first axis = pyramid axis)
\param[in] maxLimit1 Max angular limit along the joint frame's second axis (first axis = pyramid axis)
\param[in] minLimit2 Min angular limit along the joint frame's third axis (first axis = pyramid axis)
\param[in] maxLimit2 Max angular limit along the joint frame's third axis (first axis = pyramid axis)
\return The created joint.
@see PxD6Joint
*/
PxJoint* PxD6JointCreate_Pyramid(PxPhysics& physics, PxRigidActor* actor0, const PxVec3& localPos0, PxRigidActor* actor1, const PxVec3& localPos1, const PxVec3& axis,
float minLimit1, float maxLimit1, float minLimit2, float maxLimit2);
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,110 @@
//
// 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-2019 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_DEFAULT_ALLOCATOR_H
#define PX_DEFAULT_ALLOCATOR_H
/** \addtogroup extensions
@{
*/
#include "foundation/PxAllocatorCallback.h"
#include "foundation/PxAssert.h"
#include "common/PxPhysXCommonConfig.h"
#include <stdlib.h>
#if PX_WINDOWS_FAMILY || PX_LINUX_FAMILY || PX_SWITCH
#include <malloc.h>
#endif
#if !PX_DOXYGEN
namespace physx
{
#endif
#if PX_WINDOWS_FAMILY
// on win32 we only have 8-byte alignment guaranteed, but the CRT provides special aligned allocation fns
PX_FORCE_INLINE void* platformAlignedAlloc(size_t size)
{
return _aligned_malloc(size, 16);
}
PX_FORCE_INLINE void platformAlignedFree(void* ptr)
{
_aligned_free(ptr);
}
#elif PX_LINUX_FAMILY || PX_SWITCH
PX_FORCE_INLINE void* platformAlignedAlloc(size_t size)
{
return ::memalign(16, size);
}
PX_FORCE_INLINE void platformAlignedFree(void* ptr)
{
::free(ptr);
}
#else
// on all other platforms we get 16-byte alignment by default
PX_FORCE_INLINE void* platformAlignedAlloc(size_t size)
{
return ::malloc(size);
}
PX_FORCE_INLINE void platformAlignedFree(void* ptr)
{
::free(ptr);
}
#endif
/**
\brief default implementation of the allocator interface required by the SDK
*/
class PxDefaultAllocator : public PxAllocatorCallback
{
public:
void* allocate(size_t size, const char*, const char*, int)
{
void* ptr = platformAlignedAlloc(size);
PX_ASSERT((reinterpret_cast<size_t>(ptr) & 15)==0);
return ptr;
}
void deallocate(void* ptr)
{
platformAlignedFree(ptr);
}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,98 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_DEFAULT_CPU_DISPATCHER_H
#define PX_PHYSICS_EXTENSIONS_DEFAULT_CPU_DISPATCHER_H
/** \addtogroup extensions
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "task/PxCpuDispatcher.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief A default implementation for a CPU task dispatcher.
@see PxDefaultCpuDispatcherCreate() PxCpuDispatcher
*/
class PxDefaultCpuDispatcher: public PxCpuDispatcher
{
public:
/**
\brief Deletes the dispatcher.
Do not keep a reference to the deleted instance.
@see PxDefaultCpuDispatcherCreate()
*/
virtual void release() = 0;
/**
\brief Enables profiling at task level.
\note By default enabled only in profiling builds.
\param[in] runProfiled True if tasks should be profiled.
*/
virtual void setRunProfiled(bool runProfiled) = 0;
/**
\brief Checks if profiling is enabled at task level.
\return True if tasks should be profiled.
*/
virtual bool getRunProfiled() const = 0;
};
/**
\brief Create default dispatcher, extensions SDK needs to be initialized first.
\param[in] numThreads Number of worker threads the dispatcher should use.
\param[in] affinityMasks Array with affinity mask for each thread. If not defined, default masks will be used.
\note numThreads may be zero in which case no worker thread are initialized and
simulation tasks will be executed on the thread that calls PxScene::simulate()
@see PxDefaultCpuDispatcher
*/
PxDefaultCpuDispatcher* PxDefaultCpuDispatcherCreate(PxU32 numThreads, PxU32* affinityMasks = NULL);
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,62 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_DEFAULT_ERROR_CALLBACK_H
#define PX_PHYSICS_EXTENSIONS_DEFAULT_ERROR_CALLBACK_H
#include "foundation/PxErrorCallback.h"
#include "PxPhysXConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief default implementation of the error callback
This class is provided in order to enable the SDK to be started with the minimum of user code. Typically an application
will use its own error callback, and log the error to file or otherwise make it visible. Warnings and error messages from
the SDK are usually indicative that changes are required in order for PhysX to function correctly, and should not be ignored.
*/
class PxDefaultErrorCallback : public PxErrorCallback
{
public:
PxDefaultErrorCallback();
~PxDefaultErrorCallback();
virtual void reportError(PxErrorCode::Enum code, const char* message, const char* file, int line);
};
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,263 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_DEFAULTSIMULATIONFILTERSHADER_H
#define PX_PHYSICS_EXTENSIONS_DEFAULTSIMULATIONFILTERSHADER_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "PxFiltering.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxActor;
/**
\brief 64-bit mask used for collision filtering.
The collision filtering equation for 2 objects o0 and o1 is:
<pre> (G0 op0 K0) op2 (G1 op1 K1) == b </pre>
with
<ul>
<li> G0 = PxGroupsMask for object o0. See PxSetGroupsMask </li>
<li> G1 = PxGroupsMask for object o1. See PxSetGroupsMask </li>
<li> K0 = filtering constant 0. See PxSetFilterConstants </li>
<li> K1 = filtering constant 1. See PxSetFilterConstants </li>
<li> b = filtering boolean. See PxSetFilterBool </li>
<li> op0, op1, op2 = filtering operations. See PxSetFilterOps </li>
</ul>
If the filtering equation is true, collision detection is enabled.
@see PxSetFilterOps()
*/
class PxGroupsMask
{
public:
PX_INLINE PxGroupsMask():bits0(0),bits1(0),bits2(0),bits3(0) {}
PX_INLINE ~PxGroupsMask() {}
PxU16 bits0, bits1, bits2, bits3;
};
/**
\brief Collision filtering operations.
@see PxGroupsMask
*/
struct PxFilterOp
{
enum Enum
{
PX_FILTEROP_AND,
PX_FILTEROP_OR,
PX_FILTEROP_XOR,
PX_FILTEROP_NAND,
PX_FILTEROP_NOR,
PX_FILTEROP_NXOR,
PX_FILTEROP_SWAP_AND
};
};
/**
\brief Implementation of a simple filter shader that emulates PhysX 2.8.x filtering
This shader provides the following logic:
\li If one of the two filter objects is a trigger, the pair is acccepted and #PxPairFlag::eTRIGGER_DEFAULT will be used for trigger reports
\li Else, if the filter mask logic (see further below) discards the pair it will be suppressed (#PxFilterFlag::eSUPPRESS)
\li Else, the pair gets accepted and collision response gets enabled (#PxPairFlag::eCONTACT_DEFAULT)
Filter mask logic:
Given the two #PxFilterData structures fd0 and fd1 of two collision objects, the pair passes the filter if the following
conditions are met:
1) Collision groups of the pair are enabled
2) Collision filtering equation is satisfied
@see PxSimulationFilterShader
*/
PxFilterFlags PxDefaultSimulationFilterShader(
PxFilterObjectAttributes attributes0,
PxFilterData filterData0,
PxFilterObjectAttributes attributes1,
PxFilterData filterData1,
PxPairFlags& pairFlags,
const void* constantBlock,
PxU32 constantBlockSize);
/**
\brief Determines if collision detection is performed between a pair of groups
\note Collision group is an integer between 0 and 31.
\param[in] group1 First Group
\param[in] group2 Second Group
\return True if the groups could collide
@see PxSetGroupCollisionFlag
*/
bool PxGetGroupCollisionFlag(const PxU16 group1, const PxU16 group2);
/**
\brief Specifies if collision should be performed by a pair of groups
\note Collision group is an integer between 0 and 31.
\param[in] group1 First Group
\param[in] group2 Second Group
\param[in] enable True to enable collision between the groups
@see PxGetGroupCollisionFlag
*/
void PxSetGroupCollisionFlag(const PxU16 group1, const PxU16 group2, const bool enable);
/**
\brief Retrieves the value set with PxSetGroup()
\note Collision group is an integer between 0 and 31.
\param[in] actor The actor
\return The collision group this actor belongs to
@see PxSetGroup
*/
PxU16 PxGetGroup(const PxActor& actor);
/**
\brief Sets which collision group this actor is part of
\note Collision group is an integer between 0 and 31.
\param[in] actor The actor
\param[in] collisionGroup Collision group this actor belongs to
@see PxGetGroup
*/
void PxSetGroup(PxActor& actor, const PxU16 collisionGroup);
/**
\brief Retrieves filtering operation. See comments for PxGroupsMask
\param[out] op0 First filter operator.
\param[out] op1 Second filter operator.
\param[out] op2 Third filter operator.
@see PxSetFilterOps PxSetFilterBool PxSetFilterConstants
*/
void PxGetFilterOps(PxFilterOp::Enum& op0, PxFilterOp::Enum& op1, PxFilterOp::Enum& op2);
/**
\brief Setups filtering operations. See comments for PxGroupsMask
\param[in] op0 Filter op 0.
\param[in] op1 Filter op 1.
\param[in] op2 Filter op 2.
@see PxSetFilterBool PxSetFilterConstants
*/
void PxSetFilterOps(const PxFilterOp::Enum& op0, const PxFilterOp::Enum& op1, const PxFilterOp::Enum& op2);
/**
\brief Retrieves filtering's boolean value. See comments for PxGroupsMask
\return flag Boolean value for filter.
@see PxSetFilterBool PxSetFilterConstants
*/
bool PxGetFilterBool();
/**
\brief Setups filtering's boolean value. See comments for PxGroupsMask
\param[in] enable Boolean value for filter.
@see PxSetFilterOps PxSsetFilterConstants
*/
void PxSetFilterBool(const bool enable);
/**
\brief Gets filtering constant K0 and K1. See comments for PxGroupsMask
\param[out] c0 the filtering constants, as a mask. See #PxGroupsMask.
\param[out] c1 the filtering constants, as a mask. See #PxGroupsMask.
@see PxSetFilterOps PxSetFilterBool PxSetFilterConstants
*/
void PxGetFilterConstants(PxGroupsMask& c0, PxGroupsMask& c1);
/**
\brief Setups filtering's K0 and K1 value. See comments for PxGroupsMask
\param[in] c0 The new group mask. See #PxGroupsMask.
\param[in] c1 The new group mask. See #PxGroupsMask.
@see PxSetFilterOps PxSetFilterBool PxGetFilterConstants
*/
void PxSetFilterConstants(const PxGroupsMask& c0, const PxGroupsMask& c1);
/**
\brief Gets 64-bit mask used for collision filtering. See comments for PxGroupsMask
\param[in] actor The actor
\return The group mask for the actor.
@see PxSetGroupsMask()
*/
PxGroupsMask PxGetGroupsMask(const PxActor& actor);
/**
\brief Sets 64-bit mask used for collision filtering. See comments for PxGroupsMask
\param[in] actor The actor
\param[in] mask The group mask to set for the actor.
@see PxGetGroupsMask()
*/
void PxSetGroupsMask(PxActor& actor, const PxGroupsMask& mask);
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,149 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_DEFAULT_STREAMS_H
#define PX_PHYSICS_EXTENSIONS_DEFAULT_STREAMS_H
/** \addtogroup extensions
@{
*/
#include <stdio.h>
#include "common/PxPhysXCommonConfig.h"
#include "foundation/PxIO.h"
#include "PxFoundation.h"
typedef FILE* PxFileHandle;
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief default implementation of a memory write stream
@see PxOutputStream
*/
class PxDefaultMemoryOutputStream: public PxOutputStream
{
public:
PxDefaultMemoryOutputStream(PxAllocatorCallback &allocator = PxGetFoundation().getAllocatorCallback());
virtual ~PxDefaultMemoryOutputStream();
virtual PxU32 write(const void* src, PxU32 count);
virtual PxU32 getSize() const { return mSize; }
virtual PxU8* getData() const { return mData; }
private:
PxDefaultMemoryOutputStream(const PxDefaultMemoryOutputStream&);
PxDefaultMemoryOutputStream& operator=(const PxDefaultMemoryOutputStream&);
PxAllocatorCallback& mAllocator;
PxU8* mData;
PxU32 mSize;
PxU32 mCapacity;
};
/**
\brief default implementation of a memory read stream
@see PxInputData
*/
class PxDefaultMemoryInputData: public PxInputData
{
public:
PxDefaultMemoryInputData(PxU8* data, PxU32 length);
virtual PxU32 read(void* dest, PxU32 count);
virtual PxU32 getLength() const;
virtual void seek(PxU32 pos);
virtual PxU32 tell() const;
private:
PxU32 mSize;
const PxU8* mData;
PxU32 mPos;
};
/**
\brief default implementation of a file write stream
@see PxOutputStream
*/
class PxDefaultFileOutputStream: public PxOutputStream
{
public:
PxDefaultFileOutputStream(const char* name);
virtual ~PxDefaultFileOutputStream();
virtual PxU32 write(const void* src, PxU32 count);
virtual bool isValid();
private:
PxFileHandle mFile;
};
/**
\brief default implementation of a file read stream
@see PxInputData
*/
class PxDefaultFileInputData: public PxInputData
{
public:
PxDefaultFileInputData(const char* name);
virtual ~PxDefaultFileInputData();
virtual PxU32 read(void* dest, PxU32 count);
virtual void seek(PxU32 pos);
virtual PxU32 tell() const;
virtual PxU32 getLength() const;
bool isValid() const;
private:
PxFileHandle mFile;
PxU32 mLength;
};
#if !PX_DOXYGEN
}
#endif
/** @} */
#endif

View File

@@ -0,0 +1,269 @@
//
// 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-2019 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_DISTANCEJOINT_H
#define PX_DISTANCEJOINT_H
/** \addtogroup extensions
@{
*/
#include "extensions/PxJoint.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxDistanceJoint;
/**
\brief Create a distance Joint.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame0 The position and orientation of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame1 The position and orientation of the joint relative to actor1
@see PxDistanceJoint
*/
PxDistanceJoint* PxDistanceJointCreate(PxPhysics& physics, PxRigidActor* actor0, const PxTransform& localFrame0, PxRigidActor* actor1, const PxTransform& localFrame1);
/**
\brief flags for configuring the drive of a PxDistanceJoint
@see PxDistanceJoint
*/
struct PxDistanceJointFlag
{
enum Enum
{
eMAX_DISTANCE_ENABLED = 1<<1,
eMIN_DISTANCE_ENABLED = 1<<2,
eSPRING_ENABLED = 1<<3
};
};
typedef PxFlags<PxDistanceJointFlag::Enum, PxU16> PxDistanceJointFlags;
PX_FLAGS_OPERATORS(PxDistanceJointFlag::Enum, PxU16)
/**
\brief a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
@see PxDistanceJointCreate PxJoint
*/
class PxDistanceJoint : public PxJoint
{
public:
/**
\brief Return the current distance of the joint
*/
virtual PxReal getDistance() const = 0;
/**
\brief Set the allowed minimum distance for the joint.
The minimum distance must be no more than the maximum distance
<b>Default</b> 0.0f
<b>Range</b> [0, PX_MAX_F32)
\param[in] distance the minimum distance
@see PxDistanceJoint::minDistance, PxDistanceJointFlag::eMIN_DISTANCE_ENABLED getMinDistance()
*/
virtual void setMinDistance(PxReal distance) = 0;
/**
\brief Get the allowed minimum distance for the joint.
\return the allowed minimum distance
@see PxDistanceJoint::minDistance, PxDistanceJointFlag::eMIN_DISTANCE_ENABLED setMinDistance()
*/
virtual PxReal getMinDistance() const = 0;
/**
\brief Set the allowed maximum distance for the joint.
The maximum distance must be no less than the minimum distance.
<b>Default</b> 0.0f
<b>Range</b> [0, PX_MAX_F32)
\param[in] distance the maximum distance
@see PxDistanceJoint::maxDistance, PxDistanceJointFlag::eMAX_DISTANCE_ENABLED getMinDistance()
*/
virtual void setMaxDistance(PxReal distance) = 0;
/**
\brief Get the allowed maximum distance for the joint.
\return the allowed maximum distance
@see PxDistanceJoint::maxDistance, PxDistanceJointFlag::eMAX_DISTANCE_ENABLED setMaxDistance()
*/
virtual PxReal getMaxDistance() const = 0;
/**
\brief Set the error tolerance of the joint.
\param[in] tolerance the distance beyond the allowed range at which the joint becomes active
@see PxDistanceJoint::tolerance, getTolerance()
*/
virtual void setTolerance(PxReal tolerance) = 0;
/**
\brief Get the error tolerance of the joint.
the distance beyond the joint's [min, max] range before the joint becomes active.
<b>Default</b> 0.25f * PxTolerancesScale::length
<b>Range</b> (0, PX_MAX_F32)
This value should be used to ensure that if the minimum distance is zero and the
spring function is in use, the rest length of the spring is non-zero.
@see PxDistanceJoint::tolerance, setTolerance()
*/
virtual PxReal getTolerance() const = 0;
/**
\brief Set the strength of the joint spring.
The spring is used if enabled, and the distance exceeds the range [min-error, max+error].
<b>Default</b> 0.0f
<b>Range</b> [0, PX_MAX_F32)
\param[in] stiffness the spring strength of the joint
@see PxDistanceJointFlag::eSPRING_ENABLED getStiffness()
*/
virtual void setStiffness(PxReal stiffness) = 0;
/**
\brief Get the strength of the joint spring.
\return stiffness the spring strength of the joint
@see PxDistanceJointFlag::eSPRING_ENABLED setStiffness()
*/
virtual PxReal getStiffness() const = 0;
/**
\brief Set the damping of the joint spring.
The spring is used if enabled, and the distance exceeds the range [min-error, max+error].
<b>Default</b> 0.0f
<b>Range</b> [0, PX_MAX_F32)
\param[in] damping the degree of damping of the joint spring of the joint
@see PxDistanceJointFlag::eSPRING_ENABLED setDamping()
*/
virtual void setDamping(PxReal damping) = 0;
/**
\brief Get the damping of the joint spring.
\return the degree of damping of the joint spring of the joint
@see PxDistanceJointFlag::eSPRING_ENABLED setDamping()
*/
virtual PxReal getDamping() const = 0;
/**
\brief Set the flags specific to the Distance Joint.
<b>Default</b> PxDistanceJointFlag::eMAX_DISTANCE_ENABLED
\param[in] flags The joint flags.
@see PxDistanceJointFlag setFlag() getFlags()
*/
virtual void setDistanceJointFlags(PxDistanceJointFlags flags) = 0;
/**
\brief Set a single flag specific to a Distance Joint to true or false.
\param[in] flag The flag to set or clear.
\param[in] value the value to which to set the flag
@see PxDistanceJointFlag, getFlags() setFlags()
*/
virtual void setDistanceJointFlag(PxDistanceJointFlag::Enum flag, bool value) = 0;
/**
\brief Get the flags specific to the Distance Joint.
\return the joint flags
@see PxDistanceJoint::flags, PxDistanceJointFlag setFlag() setFlags()
*/
virtual PxDistanceJointFlags getDistanceJointFlags() const = 0;
/**
\brief Returns string name of PxDistanceJoint, used for serialization
*/
virtual const char* getConcreteTypeName() const { return "PxDistanceJoint"; }
protected:
//serialization
/**
\brief Constructor
*/
PX_INLINE PxDistanceJoint(PxType concreteType, PxBaseFlags baseFlags) : PxJoint(concreteType, baseFlags) {}
/**
\brief Deserialization constructor
*/
PX_INLINE PxDistanceJoint(PxBaseFlags baseFlags) : PxJoint(baseFlags) {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* name) const { return !::strcmp("PxDistanceJoint", name) || PxJoint::isKindOf(name); }
//~serialization
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,88 @@
//
// 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-2019 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_EXTENSIONS_API_H
#define PX_EXTENSIONS_API_H
/** \addtogroup extensions
@{
*/
#include "foundation/PxErrorCallback.h"
#include "extensions/PxDefaultAllocator.h"
#include "extensions/PxConstraintExt.h"
#include "extensions/PxDistanceJoint.h"
#include "extensions/PxContactJoint.h"
#include "extensions/PxFixedJoint.h"
#include "extensions/PxPrismaticJoint.h"
#include "extensions/PxRevoluteJoint.h"
#include "extensions/PxSphericalJoint.h"
#include "extensions/PxD6Joint.h"
#include "extensions/PxDefaultSimulationFilterShader.h"
#include "extensions/PxDefaultErrorCallback.h"
#include "extensions/PxDefaultStreams.h"
#include "extensions/PxRigidActorExt.h"
#include "extensions/PxRigidBodyExt.h"
#include "extensions/PxShapeExt.h"
#include "extensions/PxTriangleMeshExt.h"
#include "extensions/PxSerialization.h"
#include "extensions/PxDefaultCpuDispatcher.h"
#include "extensions/PxSmoothNormals.h"
#include "extensions/PxSimpleFactory.h"
#include "extensions/PxStringTableExt.h"
#include "extensions/PxBroadPhaseExt.h"
#include "extensions/PxMassProperties.h"
#include "extensions/PxSceneQueryExt.h"
/** \brief Initialize the PhysXExtensions library.
This should be called before calling any functions or methods in extensions which may require allocation.
\note This function does not need to be called before creating a PxDefaultAllocator object.
\param physics a PxPhysics object
\param pvd an PxPvd (PhysX Visual Debugger) object
@see PxCloseExtensions PxFoundation PxPhysics
*/
PX_C_EXPORT bool PX_CALL_CONV PxInitExtensions(physx::PxPhysics& physics, physx::PxPvd* pvd);
/** \brief Shut down the PhysXExtensions library.
This function should be called to cleanly shut down the PhysXExtensions library before application exit.
\note This function is required to be called to release foundation usage.
@see PxInitExtensions
*/
PX_C_EXPORT void PX_CALL_CONV PxCloseExtensions();
/** @} */
#endif // PX_EXTENSIONS_API_H

View File

@@ -0,0 +1,159 @@
//
// 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-2019 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_FIXEDJOINT_H
#define PX_FIXEDJOINT_H
/** \addtogroup extensions
@{
*/
#include "extensions/PxJoint.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxFixedJoint;
/**
\brief Create a fixed joint.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame0 The position and orientation of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame1 The position and orientation of the joint relative to actor1
@see PxFixedJoint
*/
PxFixedJoint* PxFixedJointCreate(PxPhysics& physics, PxRigidActor* actor0, const PxTransform& localFrame0, PxRigidActor* actor1, const PxTransform& localFrame1);
/**
\brief A fixed joint permits no relative movement between two bodies. ie the bodies are glued together.
\image html fixedJoint.png
@see PxFixedJointCreate() PxJoint
*/
class PxFixedJoint : public PxJoint
{
public:
/**
\brief Set the linear tolerance threshold for projection. Projection is enabled if PxConstraintFlag::ePROJECTION
is set for the joint.
If the joint separates by more than this distance along its locked degrees of freedom, the solver
will move the bodies to close the distance.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 1e10f
\param[in] tolerance the linear tolerance threshold
@see getProjectionLinearTolerance() PxJoint::setConstraintFlags() PxConstraintFlag::ePROJECTION
*/
virtual void setProjectionLinearTolerance(PxReal tolerance) = 0;
/**
\brief Get the linear tolerance threshold for projection.
\return the linear tolerance threshold
@see setProjectionLinearTolerance() PxJoint::setConstraintFlag()
*/
virtual PxReal getProjectionLinearTolerance() const = 0;
/**
\brief Set the angular tolerance threshold for projection. Projection is enabled if
PxConstraintFlag::ePROJECTION is set for the joint.
If the joint deviates by more than this angle around its locked angular degrees of freedom,
the solver will move the bodies to close the angle.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
<b>Range:</b> [0,Pi] <br>
<b>Default:</b> Pi
\param[in] tolerance the angular tolerance threshold in radians
@see getProjectionAngularTolerance() PxJoint::setConstraintFlag() PxConstraintFlag::ePROJECTION
*/
virtual void setProjectionAngularTolerance(PxReal tolerance) = 0;
/**
\brief Get the angular tolerance threshold for projection.
\return the angular tolerance threshold in radians
@see setProjectionAngularTolerance()
*/
virtual PxReal getProjectionAngularTolerance() const = 0;
/**
\brief Returns string name of PxFixedJoint, used for serialization
*/
virtual const char* getConcreteTypeName() const { return "PxFixedJoint"; }
protected:
//serialization
/**
\brief Constructor
*/
PX_INLINE PxFixedJoint(PxType concreteType, PxBaseFlags baseFlags) : PxJoint(concreteType, baseFlags) {}
/**
\brief Deserialization constructor
*/
PX_INLINE PxFixedJoint(PxBaseFlags baseFlags) : PxJoint(baseFlags) {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* name) const { return !::strcmp("PxFixedJoint", name) || PxJoint::isKindOf(name); }
//~serialization
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,419 @@
//
// 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-2019 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_JOINTCONSTRAINT_H
#define PX_JOINTCONSTRAINT_H
/** \addtogroup extensions
@{
*/
#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;
/**
\brief an enumeration of PhysX' built-in joint types
@see PxJoint
*/
struct PxJointConcreteType
{
enum Enum
{
eSPHERICAL = PxConcreteType::eFIRST_PHYSX_EXTENSION,
eREVOLUTE,
ePRISMATIC,
eFIXED,
eDISTANCE,
eD6,
eCONTACT,
eLast
};
};
PX_DEFINE_TYPEINFO(PxJoint, PxConcreteType::eUNDEFINED)
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)
/**
\brief an enumeration for specifying one or other of the actors referenced by a joint
@see PxJoint
*/
struct PxJointActorIndex
{
enum Enum
{
eACTOR0,
eACTOR1,
COUNT
};
};
/**
\brief a base interface providing common functionality for PhysX joints
*/
class PxJoint : public PxBase
{
//= 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:
/**
\brief Set the actors for this joint.
An actor may be NULL to indicate the world frame. At most one of the actors may be NULL.
\param[in] actor0 the first actor.
\param[in] actor1 the second actor
@see getActors()
*/
virtual void setActors(PxRigidActor* actor0, PxRigidActor* actor1) = 0;
/**
\brief Get the actors for this joint.
\param[out] actor0 the first actor.
\param[out] actor1 the second actor
@see setActors()
*/
virtual void getActors(PxRigidActor*& actor0, PxRigidActor*& actor1) const = 0;
/**
\brief Set the joint local pose for an actor.
This is the relative pose which locates the joint frame relative to the actor.
\param[in] actor 0 for the first actor, 1 for the second actor.
\param[in] localPose the local pose for the actor this joint
@see getLocalPose()
*/
virtual void setLocalPose(PxJointActorIndex::Enum actor, const PxTransform& localPose) = 0;
/**
\brief get the joint local pose for an actor.
\param[in] actor 0 for the first actor, 1 for the second actor.
return the local pose for this joint
@see setLocalPose()
*/
virtual PxTransform getLocalPose(PxJointActorIndex::Enum actor) const = 0;
/**
\brief get the relative pose for this joint
This function returns the pose of the joint frame of actor1 relative to actor0
*/
virtual PxTransform getRelativeTransform() const = 0;
/**
\brief get the relative linear velocity of the joint
This function returns the linear velocity of the origin of the constraint frame of actor1, relative to the origin of the constraint
frame of actor0. The value is returned in the constraint frame of actor0
*/
virtual PxVec3 getRelativeLinearVelocity() const = 0;
/**
\brief get the relative angular velocity of the joint
This function returns the angular velocity of actor1 relative to actor0. The value is returned in the constraint frame of actor0
*/
virtual PxVec3 getRelativeAngularVelocity() const = 0;
/**
\brief set the break force for this joint.
if the constraint force or torque on the joint exceeds the specified values, the joint will break,
at which point it will not constrain the two actors and the flag PxConstraintFlag::eBROKEN will be set. The
force and torque are measured in the joint frame of the first actor
\param[in] force the maximum force the joint can apply before breaking
\param[in] torque the maximum torque the joint can apply before breaking
*/
virtual void setBreakForce(PxReal force, PxReal torque) = 0;
/**
\brief get the break force for this joint.
\param[out] force the maximum force the joint can apply before breaking
\param[out] torque the maximum torque the joint can apply before breaking
@see setBreakForce()
*/
virtual void getBreakForce(PxReal& force, PxReal& torque) const = 0;
/**
\brief set the constraint flags for this joint.
\param[in] flags the constraint flags
@see PxConstraintFlag
*/
virtual void setConstraintFlags(PxConstraintFlags flags) = 0;
/**
\brief set a constraint flags for this joint to a specified value.
\param[in] flag the constraint flag
\param[in] value the value to which to set the flag
@see PxConstraintFlag
*/
virtual void setConstraintFlag(PxConstraintFlag::Enum flag, bool value) = 0;
/**
\brief get the constraint flags for this joint.
\return the constraint flags
@see PxConstraintFlag
*/
virtual PxConstraintFlags getConstraintFlags() const = 0;
/**
\brief set the inverse mass scale for actor0.
\param[in] invMassScale the scale to apply to the inverse mass of actor 0 for resolving this constraint
@see getInvMassScale0
*/
virtual void setInvMassScale0(PxReal invMassScale) = 0;
/**
\brief get the inverse mass scale for actor0.
\return inverse mass scale for actor0
@see setInvMassScale0
*/
virtual PxReal getInvMassScale0() const = 0;
/**
\brief set the inverse inertia scale for actor0.
\param[in] invInertiaScale the scale to apply to the inverse inertia of actor0 for resolving this constraint
@see getInvMassScale0
*/
virtual void setInvInertiaScale0(PxReal invInertiaScale) = 0;
/**
\brief get the inverse inertia scale for actor0.
\return inverse inertia scale for actor0
@see setInvInertiaScale0
*/
virtual PxReal getInvInertiaScale0() const = 0;
/**
\brief set the inverse mass scale for actor1.
\param[in] invMassScale the scale to apply to the inverse mass of actor 1 for resolving this constraint
@see getInvMassScale1
*/
virtual void setInvMassScale1(PxReal invMassScale) = 0;
/**
\brief get the inverse mass scale for actor1.
\return inverse mass scale for actor1
@see setInvMassScale1
*/
virtual PxReal getInvMassScale1() const = 0;
/**
\brief set the inverse inertia scale for actor1.
\param[in] invInertiaScale the scale to apply to the inverse inertia of actor1 for resolving this constraint
@see getInvInertiaScale1
*/
virtual void setInvInertiaScale1(PxReal invInertiaScale) = 0;
/**
\brief get the inverse inertia scale for actor1.
\return inverse inertia scale for actor1
@see setInvInertiaScale1
*/
virtual PxReal getInvInertiaScale1() const = 0;
/**
\brief Retrieves the PxConstraint corresponding to this joint.
This can be used to determine, among other things, the force applied at the joint.
\return the constraint
*/
virtual PxConstraint* getConstraint() const = 0;
/**
\brief Sets a name string for the object that can be retrieved with getName().
This is for debugging and is not used by the SDK. The string is not copied by the SDK,
only the pointer is stored.
\param[in] name String to set the objects name to.
@see getName()
*/
virtual void setName(const char* name) = 0;
/**
\brief Retrieves the name string set with setName().
\return Name string associated with object.
@see setName()
*/
virtual const char* getName() const = 0;
/**
\brief Deletes the joint.
\note This call does not wake up the connected rigid bodies.
*/
virtual void release() = 0;
/**
\brief Retrieves the scene which this joint belongs to.
\return Owner Scene. NULL if not part of a scene.
@see PxScene
*/
virtual PxScene* getScene() const = 0;
void* userData; //!< user can assign this to whatever, usually to create a 1:1 relationship with a user object.
//serialization
/**
\brief Put class meta data in stream, used for serialization
*/
static void getBinaryMetaData(PxOutputStream& stream);
//~serialization
protected:
virtual ~PxJoint() {}
//serialization
/**
\brief Constructor
*/
PX_INLINE PxJoint(PxType concreteType, PxBaseFlags baseFlags) : PxBase(concreteType, baseFlags), userData(NULL) {}
/**
\brief Deserialization constructor
*/
PX_INLINE PxJoint(PxBaseFlags baseFlags) : PxBase(baseFlags) {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* name) const { return !::strcmp("PxJoint", name) || PxBase::isKindOf(name); }
//~serialization
};
class PxSpring
{
//= 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 stiffness; //!< the spring strength of the drive: that is, the force proportional to the position error
PxReal damping; //!< the damping strength of the drive: that is, the force proportional to the velocity error
PxSpring(PxReal stiffness_, PxReal damping_): stiffness(stiffness_), damping(damping_) {}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** \brief Helper function to setup a joint's global frame
This replaces the following functions from previous SDK versions:
void NxJointDesc::setGlobalAnchor(const NxVec3& wsAnchor);
void NxJointDesc::setGlobalAxis(const NxVec3& wsAxis);
The function sets the joint's localPose using world-space input parameters.
\param[in] wsAnchor Global frame anchor point. <b>Range:</b> position vector
\param[in] wsAxis Global frame axis. <b>Range:</b> direction vector
\param[in,out] joint Joint having its global frame set.
*/
PX_C_EXPORT void PX_CALL_CONV PxSetJointGlobalFrame(physx::PxJoint& joint, const physx::PxVec3* wsAnchor, const physx::PxVec3* wsAxis);
/** @} */
#endif

View File

@@ -0,0 +1,566 @@
//
// 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-2019 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_EXTENSIONS_JOINT_LIMIT
#define PX_EXTENSIONS_JOINT_LIMIT
/** \addtogroup extensions
@{
*/
#include "foundation/PxMath.h"
#include "common/PxTolerancesScale.h"
#include "extensions/PxJoint.h"
#include "PxPhysXConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Describes the parameters for a joint limit.
Limits are enabled or disabled by setting flags or other configuration parameters joints, see the
documentation for specific joint types for details.
*/
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:
/**
\brief Controls the amount of bounce when the joint hits a limit.
A restitution value of 1.0 causes the joint to bounce back with the velocity which it hit the limit.
A value of zero causes the joint to stop dead.
In situations where the joint has many locked DOFs (e.g. 5) the restitution may not be applied
correctly. This is due to a limitation in the solver which causes the restitution velocity to become zero
as the solver enforces constraints on the other DOFs.
This limitation applies to both angular and linear limits, however it is generally most apparent with limited
angular DOFs. Disabling joint projection and increasing the solver iteration count may improve this behavior
to some extent.
Also, combining soft joint limits with joint drives driving against those limits may affect stability.
<b>Range:</b> [0,1]<br>
<b>Default:</b> 0.0
*/
PxReal restitution;
/**
determines the minimum impact velocity which will cause the joint to bounce
*/
PxReal bounceThreshold;
/**
\brief if greater than zero, the limit is soft, i.e. a spring pulls the joint back to the limit
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 0.0
*/
PxReal stiffness;
/**
\brief if spring is greater than zero, this is the damping of the limit spring
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 0.0
*/
PxReal damping;
/**
\brief the distance inside the limit value at which the limit will be considered to be active by the
solver. As this value is made larger, the limit becomes active more quickly. It thus becomes less
likely to violate the extents of the limit, but more expensive.
The contact distance should be less than the limit angle or distance, and in the case of a pair limit,
less than half the distance between the upper and lower bounds. Exceeding this value will result in
the limit being active all the time.
Making this value too small can result in jitter around the limit.
<b>Default:</b> depends on the joint
@see PxPhysics::getTolerancesScale()
*/
PxReal contactDistance;
PxJointLimitParameters() :
restitution (0.0f),
bounceThreshold (0.0f),
stiffness (0.0f),
damping (0.0f),
contactDistance (0.0f)
{
}
PxJointLimitParameters(const PxJointLimitParameters& p) :
restitution (p.restitution),
bounceThreshold (p.bounceThreshold),
stiffness (p.stiffness),
damping (p.damping),
contactDistance (p.contactDistance)
{
}
/**
\brief Returns true if the current settings are valid.
\return true if the current settings are valid
*/
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) && contactDistance >= 0;
}
PX_INLINE bool isSoft() const
{
return damping>0 || stiffness>0;
}
protected:
~PxJointLimitParameters() {}
};
/**
\brief Describes a one-sided linear limit.
*/
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:
/**
\brief the extent of the limit.
<b>Range:</b> (0, PX_MAX_F32) <br>
<b>Default:</b> PX_MAX_F32
*/
PxReal value;
/**
\brief construct a linear hard limit
\param[in] scale A PxTolerancesScale struct. Should be the same as used when creating the PxPhysics object.
\param[in] extent The extent of the limit
\param[in] contactDist The distance from the limit at which it becomes active. Default is 0.01f scaled by the tolerance length scale
@see PxJointLimitParameters PxTolerancesScale
*/
PxJointLinearLimit(const PxTolerancesScale& scale, PxReal extent, PxReal contactDist = -1.0f)
: value(extent)
{
PxJointLimitParameters::contactDistance = contactDist == -1.0f ? 0.01f*scale.length : contactDist;
}
/**
\brief construct a linear soft limit
\param[in] extent the extent of the limit
\param[in] spring the stiffness and damping parameters for the limit spring
@see PxJointLimitParameters PxTolerancesScale
*/
PxJointLinearLimit(PxReal extent, const PxSpring& spring) : value(extent)
{
stiffness = spring.stiffness;
damping = spring.damping;
}
/**
\brief Returns true if the limit is valid
\return true if the current settings are valid
*/
PX_INLINE bool isValid() const
{
return PxJointLimitParameters::isValid() &&
PxIsFinite(value) &&
value > 0.0f;
}
};
/**
\brief Describes a two-sided limit.
*/
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:
/**
\brief the range of the limit. The upper limit must be no lower than the
lower limit, and if they are equal the limited degree of freedom will be treated as locked.
<b>Range:</b> See the joint on which the limit is used for details<br>
<b>Default:</b> lower = -PX_MAX_F32/3, upper = PX_MAX_F32/3
*/
PxReal upper, lower;
/**
\brief Construct a linear hard limit pair. The lower distance value must be less than the upper distance value.
\param[in] scale A PxTolerancesScale struct. Should be the same as used when creating the PxPhysics object.
\param[in] lowerLimit The lower distance of the limit
\param[in] upperLimit The upper distance of the limit
\param[in] contactDist The distance from the limit at which it becomes active. Default is the lesser of 0.01f scaled by the tolerance length scale, and 0.49 * (upperLimit - lowerLimit)
@see PxJointLimitParameters PxTolerancesScale
*/
PxJointLinearLimitPair(const PxTolerancesScale& scale, PxReal lowerLimit = -PX_MAX_F32/3.0f, PxReal upperLimit = PX_MAX_F32/3.0f, PxReal contactDist = -1.0f) :
upper(upperLimit),
lower(lowerLimit)
{
PxJointLimitParameters::contactDistance = contactDist == -1.0f ? PxMin(scale.length * 0.01f, (upperLimit*0.49f-lowerLimit*0.49f)) : contactDist;
bounceThreshold = 2.0f*scale.length;
}
/**
\brief construct a linear soft limit pair
\param[in] lowerLimit The lower distance of the limit
\param[in] upperLimit The upper distance of the limit
\param[in] spring The stiffness and damping parameters of the limit spring
@see PxJointLimitParameters PxTolerancesScale
*/
PxJointLinearLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring) :
upper(upperLimit),
lower(lowerLimit)
{
stiffness = spring.stiffness;
damping = spring.damping;
}
/**
\brief Returns true if the limit is valid.
\return true if the current settings are valid
*/
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:
/**
\brief the range of the limit. The upper limit must be no lower than the lower limit.
<b>Unit:</b> Angular: Radians
<b>Range:</b> See the joint on which the limit is used for details<br>
<b>Default:</b> lower = -PI/2, upper = PI/2
*/
PxReal upper, lower;
/**
\brief construct an angular hard limit pair.
The lower value must be less than the upper value.
\param[in] lowerLimit The lower angle of the limit
\param[in] upperLimit The upper angle of the limit
\param[in] contactDist The distance from the limit at which it becomes active. Default is the lesser of 0.1 radians, and 0.49 * (upperLimit - lowerLimit)
@see PxJointLimitParameters
*/
PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, PxReal contactDist = -1.0f) :
upper(upperLimit),
lower(lowerLimit)
{
PxJointLimitParameters::contactDistance = contactDist ==-1.0f ? PxMin(0.1f, 0.49f*(upperLimit-lowerLimit)) : contactDist;
bounceThreshold = 0.5f;
}
/**
\brief construct an angular soft limit pair.
The lower value must be less than the upper value.
\param[in] lowerLimit The lower angle of the limit
\param[in] upperLimit The upper angle of the limit
\param[in] spring The stiffness and damping of the limit spring
@see PxJointLimitParameters
*/
PxJointAngularLimitPair(PxReal lowerLimit, PxReal upperLimit, const PxSpring& spring) :
upper(upperLimit),
lower(lowerLimit)
{
stiffness = spring.stiffness;
damping = spring.damping;
}
/**
\brief Returns true if the limit is valid.
\return true if the current settings are valid
*/
PX_INLINE bool isValid() const
{
return PxJointLimitParameters::isValid() &&
PxIsFinite(upper) && PxIsFinite(lower) && upper >= lower;
}
};
/**
\brief Describes an elliptical conical joint limit. Note that very small or highly elliptical limit cones may
result in jitter.
@see PxD6Joint PxSphericalJoint
*/
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:
/**
\brief the maximum angle from the Y axis of the constraint frame.
<b>Unit:</b> Angular: Radians
<b>Range:</b> Angular: (0,PI)<br>
<b>Default:</b> PI/2
*/
PxReal yAngle;
/**
\brief the maximum angle from the Z-axis of the constraint frame.
<b>Unit:</b> Angular: Radians
<b>Range:</b> Angular: (0,PI)<br>
<b>Default:</b> PI/2
*/
PxReal zAngle;
/**
\brief Construct a cone hard limit.
\param[in] yLimitAngle The limit angle from the Y-axis of the constraint frame
\param[in] zLimitAngle The limit angle from the Z-axis of the constraint frame
\param[in] contactDist The distance from the limit at which it becomes active. Default is the lesser of 0.1 radians, and 0.49 * the lower of the limit angles
@see PxJointLimitParameters
*/
PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, PxReal contactDist = -1.0f) :
yAngle(yLimitAngle),
zAngle(zLimitAngle)
{
PxJointLimitParameters::contactDistance = contactDist == -1.0f ? PxMin(0.1f, PxMin(yLimitAngle, zLimitAngle)*0.49f) : contactDist;
bounceThreshold = 0.5f;
}
/**
\brief Construct a cone soft limit.
\param[in] yLimitAngle The limit angle from the Y-axis of the constraint frame
\param[in] zLimitAngle The limit angle from the Z-axis of the constraint frame
\param[in] spring The stiffness and damping of the limit spring
@see PxJointLimitParameters
*/
PxJointLimitCone(PxReal yLimitAngle, PxReal zLimitAngle, const PxSpring& spring) :
yAngle(yLimitAngle),
zAngle(zLimitAngle)
{
stiffness = spring.stiffness;
damping = spring.damping;
}
/**
\brief Returns true if the limit is valid.
\return true if the current settings are valid
*/
PX_INLINE bool isValid() const
{
return PxJointLimitParameters::isValid() &&
PxIsFinite(yAngle) && yAngle>0 && yAngle<PxPi &&
PxIsFinite(zAngle) && zAngle>0 && zAngle<PxPi;
}
};
/**
\brief Describes a pyramidal joint limit.
@see PxD6Joint
*/
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:
/**
\brief the minimum angle from the Y axis of the constraint frame.
<b>Unit:</b> Angular: Radians
<b>Range:</b> Angular: (-PI,PI)<br>
<b>Default:</b> -PI/2
*/
PxReal yAngleMin;
/**
\brief the maximum angle from the Y axis of the constraint frame.
<b>Unit:</b> Angular: Radians
<b>Range:</b> Angular: (-PI,PI)<br>
<b>Default:</b> PI/2
*/
PxReal yAngleMax;
/**
\brief the minimum angle from the Z-axis of the constraint frame.
<b>Unit:</b> Angular: Radians
<b>Range:</b> Angular: (-PI,PI)<br>
<b>Default:</b> -PI/2
*/
PxReal zAngleMin;
/**
\brief the maximum angle from the Z-axis of the constraint frame.
<b>Unit:</b> Angular: Radians
<b>Range:</b> Angular: (-PI,PI)<br>
<b>Default:</b> PI/2
*/
PxReal zAngleMax;
/**
\brief Construct a pyramid hard limit.
\param[in] yLimitAngleMin The minimum limit angle from the Y-axis of the constraint frame
\param[in] yLimitAngleMax The maximum limit angle from the Y-axis of the constraint frame
\param[in] zLimitAngleMin The minimum limit angle from the Z-axis of the constraint frame
\param[in] zLimitAngleMax The maximum limit angle from the Z-axis of the constraint frame
\param[in] contactDist The distance from the limit at which it becomes active. Default is the lesser of 0.1 radians, and 0.49 * the lower of the limit angles
@see PxJointLimitParameters
*/
PxJointLimitPyramid(PxReal yLimitAngleMin, PxReal yLimitAngleMax, PxReal zLimitAngleMin, PxReal zLimitAngleMax, PxReal contactDist = -1.0f) :
yAngleMin(yLimitAngleMin),
yAngleMax(yLimitAngleMax),
zAngleMin(zLimitAngleMin),
zAngleMax(zLimitAngleMax)
{
if(contactDist == -1.0f)
{
const PxReal contactDistY = PxMin(0.1f, 0.49f*(yLimitAngleMax - yLimitAngleMin));
const PxReal contactDistZ = PxMin(0.1f, 0.49f*(zLimitAngleMax - zLimitAngleMin));
PxJointLimitParameters::contactDistance = contactDist == PxMin(contactDistY, contactDistZ);
}
else
{
PxJointLimitParameters::contactDistance = contactDist;
}
bounceThreshold = 0.5f;
}
/**
\brief Construct a pyramid soft limit.
\param[in] yLimitAngleMin The minimum limit angle from the Y-axis of the constraint frame
\param[in] yLimitAngleMax The maximum limit angle from the Y-axis of the constraint frame
\param[in] zLimitAngleMin The minimum limit angle from the Z-axis of the constraint frame
\param[in] zLimitAngleMax The maximum limit angle from the Z-axis of the constraint frame
\param[in] spring The stiffness and damping of the limit spring
@see PxJointLimitParameters
*/
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;
}
/**
\brief Returns true if the limit is valid.
\return true if the current settings are valid
*/
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

View File

@@ -0,0 +1,335 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_MASS_PROPERTIES_H
#define PX_PHYSICS_EXTENSIONS_MASS_PROPERTIES_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "foundation/PxMath.h"
#include "foundation/PxMathUtils.h"
#include "foundation/PxVec3.h"
#include "foundation/PxMat33.h"
#include "foundation/PxQuat.h"
#include "foundation/PxTransform.h"
#include "geometry/PxGeometry.h"
#include "geometry/PxBoxGeometry.h"
#include "geometry/PxSphereGeometry.h"
#include "geometry/PxCapsuleGeometry.h"
#include "geometry/PxConvexMeshGeometry.h"
#include "geometry/PxConvexMesh.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Utility class to compute and manipulate mass and inertia tensor properties.
In most cases #PxRigidBodyExt::updateMassAndInertia(), #PxRigidBodyExt::setMassAndUpdateInertia() should be enough to
setup the mass properties of a rigid body. This utility class targets users that need to customize the mass properties
computation.
*/
class PxMassProperties
{
public:
/**
\brief Default constructor.
*/
PX_FORCE_INLINE PxMassProperties() : inertiaTensor(PxIdentity), centerOfMass(0.0f), mass(1.0f) {}
/**
\brief Construct from individual elements.
*/
PX_FORCE_INLINE PxMassProperties(const PxReal m, const PxMat33& inertiaT, const PxVec3& com) : inertiaTensor(inertiaT), centerOfMass(com), mass(m) {}
/**
\brief Compute mass properties based on a provided geometry structure.
This constructor assumes the geometry has a density of 1. Mass and inertia tensor scale linearly with density.
\param[in] geometry The geometry to compute the mass properties for. Supported geometry types are: sphere, box, capsule and convex mesh.
*/
PxMassProperties(const PxGeometry& geometry)
{
switch (geometry.getType())
{
case PxGeometryType::eSPHERE:
{
const PxSphereGeometry& s = static_cast<const PxSphereGeometry&>(geometry);
mass = (4.0f / 3.0f) * PxPi * s.radius * s.radius * s.radius;
inertiaTensor = PxMat33::createDiagonal(PxVec3(2.0f / 5.0f * mass * s.radius * s.radius));
centerOfMass = PxVec3(0.0f);
}
break;
case PxGeometryType::eBOX:
{
const PxBoxGeometry& b = static_cast<const PxBoxGeometry&>(geometry);
mass = b.halfExtents.x * b.halfExtents.y * b.halfExtents.z * 8.0f;
PxVec3 d2 = b.halfExtents.multiply(b.halfExtents);
inertiaTensor = PxMat33::createDiagonal(PxVec3(d2.y + d2.z, d2.x + d2.z, d2.x + d2.y)) * (mass * 1.0f / 3.0f);
centerOfMass = PxVec3(0.0f);
}
break;
case PxGeometryType::eCAPSULE:
{
const PxCapsuleGeometry& c = static_cast<const PxCapsuleGeometry&>(geometry);
PxReal r = c.radius, h = c.halfHeight;
mass = ((4.0f / 3.0f) * r + 2 * c.halfHeight) * PxPi * r * r;
PxReal a = r*r*r * (8.0f / 15.0f) + h*r*r * (3.0f / 2.0f) + h*h*r * (4.0f / 3.0f) + h*h*h * (2.0f / 3.0f);
PxReal b = r*r*r * (8.0f / 15.0f) + h*r*r;
inertiaTensor = PxMat33::createDiagonal(PxVec3(b, a, a) * PxPi * r * r);
centerOfMass = PxVec3(0.0f);
}
break;
case PxGeometryType::eCONVEXMESH:
{
const PxConvexMeshGeometry& c = static_cast<const PxConvexMeshGeometry&>(geometry);
PxVec3 unscaledCoM;
PxMat33 unscaledInertiaTensorNonCOM; // inertia tensor of convex mesh in mesh local space
PxMat33 unscaledInertiaTensorCOM;
PxReal unscaledMass;
c.convexMesh->getMassInformation(unscaledMass, unscaledInertiaTensorNonCOM, unscaledCoM);
// inertia tensor relative to center of mass
unscaledInertiaTensorCOM[0][0] = unscaledInertiaTensorNonCOM[0][0] - unscaledMass*PxReal((unscaledCoM.y*unscaledCoM.y+unscaledCoM.z*unscaledCoM.z));
unscaledInertiaTensorCOM[1][1] = unscaledInertiaTensorNonCOM[1][1] - unscaledMass*PxReal((unscaledCoM.z*unscaledCoM.z+unscaledCoM.x*unscaledCoM.x));
unscaledInertiaTensorCOM[2][2] = unscaledInertiaTensorNonCOM[2][2] - unscaledMass*PxReal((unscaledCoM.x*unscaledCoM.x+unscaledCoM.y*unscaledCoM.y));
unscaledInertiaTensorCOM[0][1] = unscaledInertiaTensorCOM[1][0] = (unscaledInertiaTensorNonCOM[0][1] + unscaledMass*PxReal(unscaledCoM.x*unscaledCoM.y));
unscaledInertiaTensorCOM[1][2] = unscaledInertiaTensorCOM[2][1] = (unscaledInertiaTensorNonCOM[1][2] + unscaledMass*PxReal(unscaledCoM.y*unscaledCoM.z));
unscaledInertiaTensorCOM[0][2] = unscaledInertiaTensorCOM[2][0] = (unscaledInertiaTensorNonCOM[0][2] + unscaledMass*PxReal(unscaledCoM.z*unscaledCoM.x));
const PxMeshScale& s = c.scale;
mass = unscaledMass * s.scale.x * s.scale.y * s.scale.z;
centerOfMass = s.rotation.rotate(s.scale.multiply(s.rotation.rotateInv(unscaledCoM)));
inertiaTensor = scaleInertia(unscaledInertiaTensorCOM, s.rotation, s.scale);
}
break;
case PxGeometryType::eHEIGHTFIELD:
case PxGeometryType::ePLANE:
case PxGeometryType::eTRIANGLEMESH:
case PxGeometryType::eINVALID:
case PxGeometryType::eGEOMETRY_COUNT:
{
*this = PxMassProperties();
}
break;
}
PX_ASSERT(inertiaTensor.column0.isFinite() && inertiaTensor.column1.isFinite() && inertiaTensor.column2.isFinite());
PX_ASSERT(centerOfMass.isFinite());
PX_ASSERT(PxIsFinite(mass));
}
/**
\brief Scale mass properties.
\param[in] scale The linear scaling factor to apply to the mass properties.
\return The scaled mass properties.
*/
PX_FORCE_INLINE PxMassProperties operator*(const PxReal scale) const
{
PX_ASSERT(PxIsFinite(scale));
return PxMassProperties(mass * scale, inertiaTensor * scale, centerOfMass);
}
/**
\brief Translate the center of mass by a given vector and adjust the inertia tensor accordingly.
\param[in] t The translation vector for the center of mass.
*/
PX_FORCE_INLINE void translate(const PxVec3& t)
{
PX_ASSERT(t.isFinite());
inertiaTensor = translateInertia(inertiaTensor, mass, t);
centerOfMass += t;
PX_ASSERT(inertiaTensor.column0.isFinite() && inertiaTensor.column1.isFinite() && inertiaTensor.column2.isFinite());
PX_ASSERT(centerOfMass.isFinite());
}
/**
\brief Get the entries of the diagonalized inertia tensor and the corresponding reference rotation.
\param[in] inertia The inertia tensor to diagonalize.
\param[out] massFrame The frame the diagonalized tensor refers to.
\return The entries of the diagonalized inertia tensor.
*/
PX_FORCE_INLINE static PxVec3 getMassSpaceInertia(const PxMat33& inertia, PxQuat& massFrame)
{
PX_ASSERT(inertia.column0.isFinite() && inertia.column1.isFinite() && inertia.column2.isFinite());
PxVec3 diagT = PxDiagonalize(inertia, massFrame);
PX_ASSERT(diagT.isFinite());
PX_ASSERT(massFrame.isFinite());
return diagT;
}
/**
\brief Translate an inertia tensor using the parallel axis theorem
\param[in] inertia The inertia tensor to translate.
\param[in] mass The mass of the object.
\param[in] t The relative frame to translate the inertia tensor to.
\return The translated inertia tensor.
*/
PX_FORCE_INLINE static PxMat33 translateInertia(const PxMat33& inertia, const PxReal mass, const PxVec3& t)
{
PX_ASSERT(inertia.column0.isFinite() && inertia.column1.isFinite() && inertia.column2.isFinite());
PX_ASSERT(PxIsFinite(mass));
PX_ASSERT(t.isFinite());
PxMat33 s( PxVec3(0,t.z,-t.y),
PxVec3(-t.z,0,t.x),
PxVec3(t.y,-t.x,0) );
PxMat33 translatedIT = s.getTranspose() * s * mass + inertia;
PX_ASSERT(translatedIT.column0.isFinite() && translatedIT.column1.isFinite() && translatedIT.column2.isFinite());
return translatedIT;
}
/**
\brief Rotate an inertia tensor around the center of mass
\param[in] inertia The inertia tensor to rotate.
\param[in] q The rotation to apply to the inertia tensor.
\return The rotated inertia tensor.
*/
PX_FORCE_INLINE static PxMat33 rotateInertia(const PxMat33& inertia, const PxQuat& q)
{
PX_ASSERT(inertia.column0.isFinite() && inertia.column1.isFinite() && inertia.column2.isFinite());
PX_ASSERT(q.isUnit());
PxMat33 m(q);
PxMat33 rotatedIT = m * inertia * m.getTranspose();
PX_ASSERT(rotatedIT.column0.isFinite() && rotatedIT.column1.isFinite() && rotatedIT.column2.isFinite());
return rotatedIT;
}
/**
\brief Non-uniform scaling of the inertia tensor
\param[in] inertia The inertia tensor to scale.
\param[in] scaleRotation The frame of the provided scaling factors.
\param[in] scale The scaling factor for each axis (relative to the frame specified in scaleRotation).
\return The scaled inertia tensor.
*/
static PxMat33 scaleInertia(const PxMat33& inertia, const PxQuat& scaleRotation, const PxVec3& scale)
{
PX_ASSERT(inertia.column0.isFinite() && inertia.column1.isFinite() && inertia.column2.isFinite());
PX_ASSERT(scaleRotation.isUnit());
PX_ASSERT(scale.isFinite());
PxMat33 localInertiaT = rotateInertia(inertia, scaleRotation); // rotate inertia into scaling frame
PxVec3 diagonal(localInertiaT[0][0], localInertiaT[1][1], localInertiaT[2][2]);
PxVec3 xyz2 = PxVec3(diagonal.dot(PxVec3(0.5f))) - diagonal; // original x^2, y^2, z^2
PxVec3 scaledxyz2 = xyz2.multiply(scale).multiply(scale);
PxReal xx = scaledxyz2.y + scaledxyz2.z,
yy = scaledxyz2.z + scaledxyz2.x,
zz = scaledxyz2.x + scaledxyz2.y;
PxReal xy = localInertiaT[0][1] * scale.x * scale.y,
xz = localInertiaT[0][2] * scale.x * scale.z,
yz = localInertiaT[1][2] * scale.y * scale.z;
PxMat33 scaledInertia( PxVec3(xx, xy, xz),
PxVec3(xy, yy, yz),
PxVec3(xz, yz, zz));
PxMat33 scaledIT = rotateInertia(scaledInertia * (scale.x * scale.y * scale.z), scaleRotation.getConjugate());
PX_ASSERT(scaledIT.column0.isFinite() && scaledIT.column1.isFinite() && scaledIT.column2.isFinite());
return scaledIT;
}
/**
\brief Sum up individual mass properties.
\param[in] props Array of mass properties to sum up.
\param[in] transforms Reference transforms for each mass properties entry.
\param[in] count The number of mass properties to sum up.
\return The summed up mass properties.
*/
static PxMassProperties sum(const PxMassProperties* props, const PxTransform* transforms, const PxU32 count)
{
PxReal combinedMass = 0.0f;
PxVec3 combinedCoM(0.0f);
PxMat33 combinedInertiaT = PxMat33(PxZero);
for(PxU32 i = 0; i < count; i++)
{
PX_ASSERT(props[i].inertiaTensor.column0.isFinite() && props[i].inertiaTensor.column1.isFinite() && props[i].inertiaTensor.column2.isFinite());
PX_ASSERT(props[i].centerOfMass.isFinite());
PX_ASSERT(PxIsFinite(props[i].mass));
combinedMass += props[i].mass;
const PxVec3 comTm = transforms[i].transform(props[i].centerOfMass);
combinedCoM += comTm * props[i].mass;
}
if(combinedMass > 0.f)
combinedCoM /= combinedMass;
for(PxU32 i = 0; i < count; i++)
{
const PxVec3 comTm = transforms[i].transform(props[i].centerOfMass);
combinedInertiaT += translateInertia(rotateInertia(props[i].inertiaTensor, transforms[i].q), props[i].mass, combinedCoM - comTm);
}
PX_ASSERT(combinedInertiaT.column0.isFinite() && combinedInertiaT.column1.isFinite() && combinedInertiaT.column2.isFinite());
PX_ASSERT(combinedCoM.isFinite());
PX_ASSERT(PxIsFinite(combinedMass));
return PxMassProperties(combinedMass, combinedInertiaT, combinedCoM);
}
PxMat33 inertiaTensor; //!< The inertia tensor of the object.
PxVec3 centerOfMass; //!< The center of mass of the object.
PxReal mass; //!< The mass of the object.
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,236 @@
//
// 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-2019 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_PRISMATICJOINT_H
#define PX_PRISMATICJOINT_H
/** \addtogroup extensions
@{
*/
#include "extensions/PxJoint.h"
#include "extensions/PxJointLimit.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxPrismaticJoint;
/**
\brief Create a prismatic joint.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame0 The position and orientation of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame1 The position and orientation of the joint relative to actor1
@see PxPrismaticJoint
*/
PxPrismaticJoint* PxPrismaticJointCreate(PxPhysics& physics, PxRigidActor* actor0, const PxTransform& localFrame0, PxRigidActor* actor1, const PxTransform& localFrame1);
/**
\brief Flags specific to the prismatic joint.
@see PxPrismaticJoint
*/
struct PxPrismaticJointFlag
{
enum Enum
{
eLIMIT_ENABLED = 1<<1
};
};
typedef PxFlags<PxPrismaticJointFlag::Enum, PxU16> PxPrismaticJointFlags;
PX_FLAGS_OPERATORS(PxPrismaticJointFlag::Enum, PxU16)
/**
\brief A prismatic joint permits relative translational movement between two bodies along
an axis, but no relative rotational movement.
the axis on each body is defined as the line containing the origin of the joint frame and
extending along the x-axis of that frame
\image html prismJoint.png
@see PxPrismaticJointCreate() PxJoint
*/
class PxPrismaticJoint : public PxJoint
{
public:
/**
\brief returns the displacement of the joint along its axis.
*/
virtual PxReal getPosition() const = 0;
/**
\brief returns the velocity of the joint along its axis
*/
virtual PxReal getVelocity() const = 0;
/**
\brief sets the joint limit parameters.
The limit range is [-PX_MAX_F32, PX_MAX_F32], but note that the width of the limit (upper-lower) must also be
a valid float.
@see PxJointLinearLimitPair getLimit()
*/
virtual void setLimit(const PxJointLinearLimitPair&) = 0;
/**
\brief gets the joint limit parameters.
@see PxJointLinearLimit getLimit()
*/
virtual PxJointLinearLimitPair getLimit() const = 0;
/**
\brief Set the flags specific to the Prismatic Joint.
<b>Default</b> PxPrismaticJointFlags(0)
\param[in] flags The joint flags.
@see PxPrismaticJointFlag setFlag() getFlags()
*/
virtual void setPrismaticJointFlags(PxPrismaticJointFlags flags) = 0;
/**
\brief Set a single flag specific to a Prismatic Joint to true or false.
\param[in] flag The flag to set or clear.
\param[in] value The value to which to set the flag
@see PxPrismaticJointFlag, getFlags() setFlags()
*/
virtual void setPrismaticJointFlag(PxPrismaticJointFlag::Enum flag, bool value) = 0;
/**
\brief Get the flags specific to the Prismatic Joint.
\return the joint flags
@see PxPrismaticJoint::flags, PxPrismaticJointFlag setFlag() setFlags()
*/
virtual PxPrismaticJointFlags getPrismaticJointFlags() const = 0;
/**
\brief Set the linear tolerance threshold for projection.
If the joint separates by more than this distance along its locked degrees of freedom, the solver
will move the bodies to close the distance.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
This value must be nonnegative.
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 1e10f
\param[in] tolerance the linear tolerance threshold
@see getProjectionLinearTolerance()
*/
virtual void setProjectionLinearTolerance(PxReal tolerance) = 0;
/**
\brief Get the linear tolerance threshold for projection.
\return the linear tolerance threshold in radians
@see setProjectionLinearTolerance()
*/
virtual PxReal getProjectionLinearTolerance() const = 0;
/**
\brief Set the angular tolerance threshold for projection. Projection is enabled if PxConstraintFlag::ePROJECTION
is set for the joint.
If the joint separates by more than this distance along its locked degrees of freedom, the solver
will move the bodies to close the distance.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> Pi
\param[in] tolerance the linear tolerance threshold
@see getProjectionLinearTolerance() PxJoint::setConstraintFlags()
*/
virtual void setProjectionAngularTolerance(PxReal tolerance) = 0;
/**
\brief Get the angular tolerance threshold for projection.
@see getProjectionAngularTolerance()
*/
virtual PxReal getProjectionAngularTolerance() const = 0;
/**
\brief Returns string name of PxPrismaticJoint, used for serialization
*/
virtual const char* getConcreteTypeName() const { return "PxPrismaticJoint"; }
protected:
//serialization
/**
\brief Constructor
*/
PX_INLINE PxPrismaticJoint(PxType concreteType, PxBaseFlags baseFlags) : PxJoint(concreteType, baseFlags) {}
/**
\brief Deserialization constructor
*/
PX_INLINE PxPrismaticJoint(PxBaseFlags baseFlags) : PxJoint(baseFlags) {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* name) const { return !::strcmp("PxPrismaticJoint", name) || PxJoint::isKindOf(name); }
//~serialization
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,100 @@
//
// 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-2019 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_RAYCAST_CCD_H
#define PX_RAYCAST_CCD_H
/** \addtogroup extensions
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "foundation/PxVec3.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxScene;
class PxShape;
class PxRigidDynamic;
class RaycastCCDManagerInternal;
/**
\brief Raycast-CCD manager.
Raycast-CCD is a simple and potentially cheaper alternative to the SDK's built-in continuous collision detection algorithm.
This implementation has some limitations:
- it is only implemented for PxRigidDynamic objects (not for PxArticulationLink)
- it is only implemented for simple actors with 1 shape (not for "compounds")
Also, since it is raycast-based, the solution is not perfect. In particular:
- small dynamic objects can still go through the static world if the ray goes through a crack between edges, or a small
hole in the world (like the keyhole from a door).
- dynamic-vs-dynamic CCD is very approximate. It only works well for fast-moving dynamic objects colliding against
slow-moving dynamic objects.
Finally, since it is using the SDK's scene queries under the hood, it only works provided the simulation shapes also have
scene-query shapes associated with them. That is, if the objects in the scene only use PxShapeFlag::eSIMULATION_SHAPE
(and no PxShapeFlag::eSCENE_QUERY_SHAPE), then the raycast-CCD system will not work.
*/
class RaycastCCDManager
{
public:
RaycastCCDManager(PxScene* scene);
~RaycastCCDManager();
/**
\brief Register dynamic object for raycast CCD.
\param[in] actor object's actor
\param[in] shape object's shape
\return True if success
*/
bool registerRaycastCCDObject(PxRigidDynamic* actor, PxShape* shape);
/**
\brief Perform raycast CCD. Call this after your simulate/fetchResults calls.
\param[in] doDynamicDynamicCCD True to enable dynamic-vs-dynamic CCD (more expensive, not always needed)
*/
void doRaycastCCD(bool doDynamicDynamicCCD);
private:
RaycastCCDManagerInternal* mImpl;
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,148 @@
//
// 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-2019 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_REPX_SERIALIZER_H
#define PX_REPX_SERIALIZER_H
/** \addtogroup Serializers
@{
*/
#include "common/PxBase.h"
#include "extensions/PxRepXSimpleType.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class XmlMemoryAllocator;
class XmlWriter;
class XmlReader;
class MemoryBuffer;
/**
\brief Serializer interface for RepX (Xml) serialization.
In order to serialize a class to RepX both a PxSerializer and
a PxRepXSerializer implementation are needed.
A repx Serializer provides the ability to capture a live
object to a descriptor or static state and the ability to
write that state out to a file. Objects allocated
by the Serializer using the allocator are freed when the
collection itself is freed.
SnRepXCoreSerializers.cpp implements a set of Serializers
for the core PhysX types.
\note Implementing a PxRepXSerializer is currently not practical without including the internal PhysXExtension header "SnRepXSerializerImpl.h".
@see PxSerializer, PX_NEW_REPX_SERIALIZER, PxSerializationRegistry::registerRepXSerializer
*/
class PxRepXSerializer
{
protected:
virtual ~PxRepXSerializer(){}
public:
/**
\brief The type this Serializer is meant to operate on.
@see PxRepXObject::typeName
*/
virtual const char* getTypeName() = 0;
/**
\brief Convert from a RepX object to a key-value pair hierarchy
\param[in] inLiveObject The object to convert to the passed in descriptor.
\param[in] inCollection The collection to use to find ids of references of this object.
\param[in] inWriter Interface to write data to.
\param[in] inTempBuffer used to for temporary allocations.
\param[in] inArgs The arguments used in create resources and objects.
*/
virtual void objectToFile( const PxRepXObject& inLiveObject, PxCollection* inCollection, XmlWriter& inWriter, MemoryBuffer& inTempBuffer, PxRepXInstantiationArgs& inArgs ) = 0;
/**
\brief Convert from a descriptor to a live object. Must be an object of this Serializer type.
\param[in] inReader The inverse of the writer, a key-value pair database.
\param[in] inAllocator An allocator to use for temporary allocations. These will be freed after instantiation completes.
\param[in] inArgs The arguments used in create resources and objects.
\param[in] inCollection The collection used to find references.
\return The new live object. It can be an invalid object if the instantiation cannot take place.
*/
virtual PxRepXObject fileToObject( XmlReader& inReader, XmlMemoryAllocator& inAllocator, PxRepXInstantiationArgs& inArgs, PxCollection* inCollection ) = 0;
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/**
\brief Inline helper template function to create PxRepXObject from TDataType type supporting PxTypeInfo<TDataType>::name.
*/
template<typename TDataType>
PX_INLINE physx::PxRepXObject PxCreateRepXObject(const TDataType* inType, const physx::PxSerialObjectId inId)
{
return physx::PxRepXObject(physx::PxTypeInfo<TDataType>::name(), inType, inId);
}
/**
\brief Inline helper function to create PxRepXObject from a PxBase instance.
*/
PX_INLINE physx::PxRepXObject PxCreateRepXObject(const physx::PxBase* inType, const physx::PxSerialObjectId inId)
{
PX_ASSERT(inType);
return physx::PxRepXObject(inType->getConcreteTypeName(), inType, inId);
}
/**
\brief Inline helper template function to create PxRepXObject form TDataType type using inType pointer as a PxSerialObjectId id.
*/
template<typename TDataType>
PX_INLINE physx::PxRepXObject PxCreateRepXObject(const TDataType* inType)
{
return PxCreateRepXObject(inType, static_cast<physx::PxSerialObjectId>(reinterpret_cast<size_t>(inType)));
}
/**
\brief Preprocessor macro for RepX serializer creation.
*/
#define PX_NEW_REPX_SERIALIZER(T) \
*PX_PLACEMENT_NEW(PxGetFoundation().getAllocatorCallback().allocate(sizeof(T), "PxRepXSerializer", __FILE__, __LINE__ ), T)(PxGetFoundation().getAllocatorCallback())
/**
\brief Preprocessor Macro to simplify RepX serializer delete.
*/
#define PX_DELETE_REPX_SERIALIZER(x) \
{ PxRepXSerializer* s = x; if (s) { PxGetFoundation().getAllocatorCallback().deallocate(s); } }
/** @} */
#endif // PX_REPX_SERIALIZER_H

View File

@@ -0,0 +1,106 @@
//
// 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-2019 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_REPX_SIMPLE_TYPE_H
#define PX_REPX_SIMPLE_TYPE_H
/** \addtogroup extensions
@{
*/
#include "foundation/PxSimpleTypes.h"
#include "cooking/PxCooking.h"
#include "common/PxStringTable.h"
#include "common/PxSerialFramework.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief Helper class containing the mapping of id to object, and type name.
*/
struct PxRepXObject
{
/**
\brief Identifies the extension meant to handle this object.
@see PxTypeInfo, PX_DEFINE_TYPEINFO, PxRepXSerializer
*/
const char* typeName;
/**
\brief Pointer to the serializable this was created from
*/
const void* serializable;
/**
\brief Id given to this object at some point
*/
PxSerialObjectId id;
PxRepXObject( const char* inTypeName = "", const void* inSerializable = NULL, const PxSerialObjectId inId = 0 )
: typeName( inTypeName )
, serializable( inSerializable )
, id( inId )
{
}
bool isValid() const { return serializable != NULL; }
};
/**
\brief Arguments required to instantiate a serializable object from RepX.
Extra arguments can be added to the object map under special ids.
@see PxRepXSerializer::objectToFile, PxRepXSerializer::fileToObject
*/
struct PxRepXInstantiationArgs
{
PxPhysics& physics;
PxCooking* cooker;
PxStringTable* stringTable;
PxRepXInstantiationArgs( PxPhysics& inPhysics, PxCooking* inCooking = NULL , PxStringTable* inStringTable = NULL )
: physics( inPhysics )
, cooker( inCooking )
, stringTable( inStringTable )
{
}
PxRepXInstantiationArgs& operator=(const PxRepXInstantiationArgs&);
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,332 @@
//
// 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-2019 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_REVOLUTEJOINT_H
#define PX_REVOLUTEJOINT_H
/** \addtogroup extensions
@{
*/
#include "extensions/PxJoint.h"
#include "extensions/PxJointLimit.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxRevoluteJoint;
/**
\brief Create a revolute joint.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame0 The position and orientation of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame1 The position and orientation of the joint relative to actor1
@see PxRevoluteJoint
*/
PxRevoluteJoint* PxRevoluteJointCreate(PxPhysics& physics, PxRigidActor* actor0, const PxTransform& localFrame0, PxRigidActor* actor1, const PxTransform& localFrame1);
/**
\brief Flags specific to the Revolute Joint.
@see PxRevoluteJoint
*/
struct PxRevoluteJointFlag
{
enum Enum
{
eLIMIT_ENABLED = 1<<0, //!< enable the limit
eDRIVE_ENABLED = 1<<1, //!< enable the drive
eDRIVE_FREESPIN = 1<<2 //!< if the existing velocity is beyond the drive velocity, do not add force
};
};
typedef PxFlags<PxRevoluteJointFlag::Enum, PxU16> PxRevoluteJointFlags;
PX_FLAGS_OPERATORS(PxRevoluteJointFlag::Enum, PxU16)
/**
\brief A joint which behaves in a similar way to a hinge or axle.
A hinge joint removes all but a single rotational degree of freedom from two objects.
The axis along which the two bodies may rotate is specified with a point and a direction
vector.
The position of the hinge on each body is specified by the origin of the body's joint frame.
The axis of the hinge is specified as the direction of the x-axis in the body's joint frame.
\image html revoluteJoint.png
A revolute joint can be given a motor, so that it can apply a force to rotate the attached actors.
It may also be given a limit, to restrict the revolute motion to within a certain range. In
addition, the bodies may be projected together if the distance or angle between them exceeds
a given threshold.
Projection, drive and limits are activated by setting the appropriate flags on the joint.
@see PxRevoluteJointCreate() PxJoint
*/
class PxRevoluteJoint : public PxJoint
{
public:
/**
\brief return the angle of the joint, in the range (-2*Pi, 2*Pi]
*/
virtual PxReal getAngle() const = 0;
/**
\brief return the velocity of the joint
*/
virtual PxReal getVelocity() const = 0;
/**
\brief set the joint limit parameters.
The limit is activated using the flag PxRevoluteJointFlag::eLIMIT_ENABLED
The limit angle range is (-2*Pi, 2*Pi).
\param[in] limits The joint limit parameters.
@see PxJointAngularLimitPair getLimit()
*/
virtual void setLimit(const PxJointAngularLimitPair& limits) = 0;
/**
\brief get the joint limit parameters.
\return the joint limit parameters
@see PxJointAngularLimitPair setLimit()
*/
virtual PxJointAngularLimitPair getLimit() const = 0;
/**
\brief set the target velocity for the drive model.
The motor will only be able to reach this velocity if the maxForce is sufficiently large.
If the joint is spinning faster than this velocity, the motor will actually try to brake
(see PxRevoluteJointFlag::eDRIVE_FREESPIN.)
If you set this to infinity then the motor will keep speeding up, unless there is some sort
of resistance on the attached bodies. The sign of this variable determines the rotation direction,
with positive values going the same way as positive joint angles.
\param[in] velocity the drive target velocity
\param[in] autowake Whether to wake the joint rigids up if it is asleep.
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 0.0
@see PxRevoluteFlags::eDRIVE_FREESPIN
*/
virtual void setDriveVelocity(PxReal velocity, bool autowake = true) = 0;
/**
\brief gets the target velocity for the drive model.
\return the drive target velocity
@see setDriveVelocity()
*/
virtual PxReal getDriveVelocity() const = 0;
/**
\brief sets the maximum torque the drive can exert.
Setting this to a very large value if velTarget is also very large may cause unexpected results.
The value set here may be used either as an impulse limit or a force limit, depending on the flag PxConstraintFlag::eDRIVE_LIMITS_ARE_FORCES
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> PX_MAX_F32
@see setDriveVelocity()
*/
virtual void setDriveForceLimit(PxReal limit) = 0;
/**
\brief gets the maximum torque the drive can exert.
\return the torque limit
@see setDriveVelocity()
*/
virtual PxReal getDriveForceLimit() const = 0;
/**
\brief sets the gear ratio for the drive.
When setting up the drive constraint, the velocity of the first actor is scaled by this value, and its response to drive torque is scaled down.
So if the drive target velocity is zero, the second actor will be driven to the velocity of the first scaled by the gear ratio
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 1.0
\param[in] ratio the drive gear ratio
@see getDriveGearRatio()
*/
virtual void setDriveGearRatio(PxReal ratio) = 0;
/**
\brief gets the gear ratio.
\return the drive gear ratio
@see setDriveGearRatio()
*/
virtual PxReal getDriveGearRatio() const = 0;
/**
\brief sets the flags specific to the Revolute Joint.
<b>Default</b> PxRevoluteJointFlags(0)
\param[in] flags The joint flags.
@see PxRevoluteJointFlag setFlag() getFlags()
*/
virtual void setRevoluteJointFlags(PxRevoluteJointFlags flags) = 0;
/**
\brief sets a single flag specific to a Revolute Joint.
\param[in] flag The flag to set or clear.
\param[in] value the value to which to set the flag
@see PxRevoluteJointFlag, getFlags() setFlags()
*/
virtual void setRevoluteJointFlag(PxRevoluteJointFlag::Enum flag, bool value) = 0;
/**
\brief gets the flags specific to the Revolute Joint.
\return the joint flags
@see PxRevoluteJoint::flags, PxRevoluteJointFlag setFlag() setFlags()
*/
virtual PxRevoluteJointFlags getRevoluteJointFlags() const = 0;
/**
\brief Set the linear tolerance threshold for projection. Projection is enabled if PxConstraintFlag::ePROJECTION
is set for the joint.
If the joint separates by more than this distance along its locked degrees of freedom, the solver
will move the bodies to close the distance.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 1e10f
\param[in] tolerance the linear tolerance threshold
@see getProjectionLinearTolerance() PxJoint::setConstraintFlags() PxConstraintFlag::ePROJECTION
*/
virtual void setProjectionLinearTolerance(PxReal tolerance) = 0;
/**
\brief Get the linear tolerance threshold for projection.
\return the linear tolerance threshold
@see setProjectionLinearTolerance()
*/
virtual PxReal getProjectionLinearTolerance() const = 0;
/**
\brief Set the angular tolerance threshold for projection. Projection is enabled if
PxConstraintFlag::ePROJECTION is set for the joint.
If the joint deviates by more than this angle around its locked angular degrees of freedom,
the solver will move the bodies to close the angle.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
<b>Range:</b> [0,Pi] <br>
<b>Default:</b> Pi
\param[in] tolerance the angular tolerance threshold in radians
@see getProjectionAngularTolerance() PxJoint::setConstraintFlag() PxConstraintFlag::ePROJECTION
*/
virtual void setProjectionAngularTolerance(PxReal tolerance) = 0;
/**
\brief gets the angular tolerance threshold for projection.
\return the angular tolerance threshold in radians
@see setProjectionAngularTolerance()
*/
virtual PxReal getProjectionAngularTolerance() const = 0;
/**
\brief Returns string name of PxRevoluteJoint, used for serialization
*/
virtual const char* getConcreteTypeName() const { return "PxRevoluteJoint"; }
protected:
//serialization
/**
\brief Constructor
*/
PX_INLINE PxRevoluteJoint(PxType concreteType, PxBaseFlags baseFlags) : PxJoint(concreteType, baseFlags) {}
/**
\brief Deserialization constructor
*/
PX_INLINE PxRevoluteJoint(PxBaseFlags baseFlags) : PxJoint(baseFlags) {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* name) const { return !::strcmp("PxRevoluteJoint", name) || PxJoint::isKindOf(name); }
//~serialization
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,155 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_RIGIDACTOR_H
#define PX_PHYSICS_EXTENSIONS_RIGIDACTOR_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "PxPhysics.h"
#include "PxRigidActor.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief utility functions for use with PxRigidActor and subclasses
@see PxRigidActor PxRigidStatic PxRigidBody PxRigidDynamic PxArticulationLink
*/
class PxRigidActorExt
{
public:
/**
\brief Creates a new shape with default properties and a list of materials and adds it to the list of shapes of this actor.
This is equivalent to the following
PxShape* shape(...) = PxGetPhysics().createShape(...); // reference count is 1
actor->attachShape(shape); // increments reference count
shape->release(); // releases user reference, leaving reference count at 1
As a consequence, detachShape() will result in the release of the last reference, and the shape will be deleted.
\note The default shape flags to be set are: eVISUALIZATION, eSIMULATION_SHAPE, eSCENE_QUERY_SHAPE (see #PxShapeFlag).
Triangle mesh, heightfield or plane geometry shapes configured as eSIMULATION_SHAPE are not supported for
non-kinematic PxRigidDynamic instances.
\note Creating compounds with a very large number of shapes may adversely affect performance and stability.
<b>Sleeping:</b> Does <b>NOT</b> wake the actor up automatically.
\param[in] actor the actor to which to attach the shape
\param[in] geometry the geometry of the shape
\param[in] materials a pointer to an array of material pointers
\param[in] materialCount the count of materials
\param[in] shapeFlags optional PxShapeFlags
\return The newly created shape.
@see PxShape PxShape::release(), PxPhysics::createShape(), PxRigidActor::attachShape()
*/
static PxShape* createExclusiveShape(PxRigidActor& actor, const PxGeometry& geometry, PxMaterial*const* materials, PxU16 materialCount,
PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE)
{
PxShape* shape = PxGetPhysics().createShape(geometry, materials, materialCount, true, shapeFlags);
if(shape)
{
bool status = actor.attachShape(*shape); // attach can fail, if e.g. we try and attach a trimesh simulation shape to a dynamic actor
shape->release(); // if attach fails, we hold the only counted reference, and so this cleans up properly
if(!status)
shape = NULL;
}
return shape;
}
/**
\brief Creates a new shape with default properties and a single material adds it to the list of shapes of this actor.
This is equivalent to the following
PxShape* shape(...) = PxGetPhysics().createShape(...); // reference count is 1
actor->attachShape(shape); // increments reference count
shape->release(); // releases user reference, leaving reference count at 1
As a consequence, detachShape() will result in the release of the last reference, and the shape will be deleted.
\note The default shape flags to be set are: eVISUALIZATION, eSIMULATION_SHAPE, eSCENE_QUERY_SHAPE (see #PxShapeFlag).
Triangle mesh, heightfield or plane geometry shapes configured as eSIMULATION_SHAPE are not supported for
non-kinematic PxRigidDynamic instances.
\note Creating compounds with a very large number of shapes may adversely affect performance and stability.
<b>Sleeping:</b> Does <b>NOT</b> wake the actor up automatically.
\param[in] actor the actor to which to attach the shape
\param[in] geometry the geometry of the shape
\param[in] material the material for the shape
\param[in] shapeFlags optional PxShapeFlags
\return The newly created shape.
@see PxShape PxShape::release(), PxPhysics::createShape(), PxRigidActor::attachShape()
*/
static PX_FORCE_INLINE PxShape* createExclusiveShape(PxRigidActor& actor, const PxGeometry& geometry, const PxMaterial& material,
PxShapeFlags shapeFlags = PxShapeFlag::eVISUALIZATION | PxShapeFlag::eSCENE_QUERY_SHAPE | PxShapeFlag::eSIMULATION_SHAPE)
{
PxMaterial* materialPtr = const_cast<PxMaterial*>(&material);
return createExclusiveShape(actor, geometry, &materialPtr, 1, shapeFlags);
}
/**
\brief Gets a list of bounds based on shapes in rigid actor. This list can be used to cook/create
bounding volume hierarchy though PxCooking API.
\param[in] actor The actor from which the bounds list is retrieved.
\param[out] numBounds Number of bounds in returned list.
@see PxShape PxBVHStructure PxCooking::createBVHStructure PxCooking::cookBVHStructure
*/
static PxBounds3* getRigidActorShapeLocalBoundsList(const PxRigidActor& actor, PxU32& numBounds);
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,460 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_RIGIDBODY_H
#define PX_PHYSICS_EXTENSIONS_RIGIDBODY_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "PxRigidBody.h"
#include "PxQueryReport.h"
#include "PxQueryFiltering.h"
#include "extensions/PxMassProperties.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxScene;
struct PxQueryCache;
class PxShape;
/**
\brief utility functions for use with PxRigidBody and subclasses
@see PxRigidBody PxRigidDynamic PxArticulationLink
*/
class PxRigidBodyExt
{
public:
/**
\brief Computation of mass properties for a rigid body actor
To simulate a dynamic rigid actor, the SDK needs a mass and an inertia tensor.
This method offers functionality to compute the necessary mass and inertia properties based on the shapes declared in
the PxRigidBody descriptor and some additionally specified parameters. For each shape, the shape geometry,
the shape positioning within the actor and the specified shape density are used to compute the body's mass and
inertia properties.
<ul>
<li>Shapes without PxShapeFlag::eSIMULATION_SHAPE set are ignored unless includeNonSimShapes is true.</li>
<li>Shapes with plane, triangle mesh or heightfield geometry and PxShapeFlag::eSIMULATION_SHAPE set are not allowed for PxRigidBody collision.</li>
</ul>
This method will set the mass, center of mass, and inertia tensor
if no collision shapes are found, the inertia tensor is set to (1,1,1) and the mass to 1
if massLocalPose is non-NULL, the rigid body's center of mass parameter will be set
to the user provided value (massLocalPose) and the inertia tensor will be resolved at that point.
\note If all shapes of the actor have the same density then the overloaded method updateMassAndInertia() with a single density parameter can be used instead.
\param[in,out] body The rigid body.
\param[in] shapeDensities The per shape densities. There must be one entry for each shape which has the PxShapeFlag::eSIMULATION_SHAPE set (or for all shapes if includeNonSimShapes is set to true). Other shapes are ignored. The density values must be greater than 0.
\param[in] shapeDensityCount The number of provided density values.
\param[in] massLocalPose The center of mass relative to the actor frame. If set to null then (0,0,0) is assumed.
\param[in] includeNonSimShapes True if all kind of shapes (PxShapeFlag::eSCENE_QUERY_SHAPE, PxShapeFlag::eTRIGGER_SHAPE) should be taken into account.
\return Boolean. True on success else false.
@see PxRigidBody::setMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass
*/
static bool updateMassAndInertia(PxRigidBody& body, const PxReal* shapeDensities, PxU32 shapeDensityCount, const PxVec3* massLocalPose = NULL, bool includeNonSimShapes = false);
/**
\brief Computation of mass properties for a rigid body actor
See previous method for details.
\param[in,out] body The rigid body.
\param[in] density The density of the body. Used to compute the mass of the body. The density must be greater than 0.
\param[in] massLocalPose The center of mass relative to the actor frame. If set to null then (0,0,0) is assumed.
\param[in] includeNonSimShapes True if all kind of shapes (PxShapeFlag::eSCENE_QUERY_SHAPE, PxShapeFlag::eTRIGGER_SHAPE) should be taken into account.
\return Boolean. True on success else false.
@see PxRigidBody::setMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass
*/
static bool updateMassAndInertia(PxRigidBody& body, PxReal density, const PxVec3* massLocalPose = NULL, bool includeNonSimShapes = false);
/**
\brief Computation of mass properties for a rigid body actor
This method sets the mass, inertia and center of mass of a rigid body. The mass is set to the sum of all user-supplied
shape mass values, and the inertia and center of mass are computed according to the rigid body's shapes and the per shape mass input values.
If no collision shapes are found, the inertia tensor is set to (1,1,1)
\note If a single mass value should be used for the actor as a whole then the overloaded method setMassAndUpdateInertia() with a single mass parameter can be used instead.
@see updateMassAndInertia for more details.
\param[in,out] body The rigid body for which to set the mass and centre of mass local pose properties.
\param[in] shapeMasses The per shape mass values. There must be one entry for each shape which has the PxShapeFlag::eSIMULATION_SHAPE set. Other shapes are ignored. The mass values must be greater than 0.
\param[in] shapeMassCount The number of provided mass values.
\param[in] massLocalPose The center of mass relative to the actor frame. If set to null then (0,0,0) is assumed.
\param[in] includeNonSimShapes True if all kind of shapes (PxShapeFlag::eSCENE_QUERY_SHAPE, PxShapeFlag::eTRIGGER_SHAPE) should be taken into account.
\return Boolean. True on success else false.
@see PxRigidBody::setCMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass
*/
static bool setMassAndUpdateInertia(PxRigidBody& body, const PxReal* shapeMasses, PxU32 shapeMassCount, const PxVec3* massLocalPose = NULL, bool includeNonSimShapes = false);
/**
\brief Computation of mass properties for a rigid body actor
This method sets the mass, inertia and center of mass of a rigid body. The mass is set to the user-supplied
value, and the inertia and center of mass are computed according to the rigid body's shapes and the input mass.
If no collision shapes are found, the inertia tensor is set to (1,1,1)
@see updateMassAndInertia for more details.
\param[in,out] body The rigid body for which to set the mass and centre of mass local pose properties.
\param[in] mass The mass of the body. Must be greater than 0.
\param[in] massLocalPose The center of mass relative to the actor frame. If set to null then (0,0,0) is assumed.
\param[in] includeNonSimShapes True if all kind of shapes (PxShapeFlag::eSCENE_QUERY_SHAPE, PxShapeFlag::eTRIGGER_SHAPE) should be taken into account.
\return Boolean. True on success else false.
@see PxRigidBody::setCMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass
*/
static bool setMassAndUpdateInertia(PxRigidBody& body, PxReal mass, const PxVec3* massLocalPose = NULL, bool includeNonSimShapes = false);
/**
\brief Compute the mass, inertia tensor and center of mass from a list of shapes.
\param[in] shapes The shapes to compute the mass properties from.
\param[in] shapeCount The number of provided shapes.
\return The mass properties from the combined shapes.
@see PxRigidBody::setCMassLocalPose PxRigidBody::setMassSpaceInertiaTensor PxRigidBody::setMass
*/
static PxMassProperties computeMassPropertiesFromShapes(const PxShape* const* shapes, PxU32 shapeCount);
/**
\brief Applies a force (or impulse) defined in the global coordinate frame, acting at a particular
point in global coordinates, to the actor.
Note that if the force does not act along the center of mass of the actor, this
will also add the corresponding torque. Because forces are reset at the end of every timestep,
you can maintain a total external force on an object by calling this once every frame.
\note if this call is used to apply a force or impulse to an articulation link, only the link is updated, not the entire
articulation
::PxForceMode determines if the force is to be conventional or impulsive. Only eFORCE and eIMPULSE are supported, as the
force required to produce a given velocity change or acceleration is underdetermined given only the desired change at a
given point.
<b>Sleeping:</b> This call wakes the actor if it is sleeping and the wakeup parameter is true (default).
\param[in] body The rigid body to apply the force to.
\param[in] force Force/impulse to add, defined in the global frame. <b>Range:</b> force vector
\param[in] pos Position in the global frame to add the force at. <b>Range:</b> position vector
\param[in] mode The mode to use when applying the force/impulse(see #PxForceMode).
\param[in] wakeup Specify if the call should wake up the actor.
@see PxForceMode
@see addForceAtLocalPos() addLocalForceAtPos() addLocalForceAtLocalPos()
*/
static void addForceAtPos(PxRigidBody& body, const PxVec3& force, const PxVec3& pos, PxForceMode::Enum mode = PxForceMode::eFORCE, bool wakeup = true);
/**
\brief Applies a force (or impulse) defined in the global coordinate frame, acting at a particular
point in local coordinates, to the actor.
Note that if the force does not act along the center of mass of the actor, this
will also add the corresponding torque. Because forces are reset at the end of every timestep, you can maintain a
total external force on an object by calling this once every frame.
\note if this call is used to apply a force or impulse to an articulation link, only the link is updated, not the entire
articulation
::PxForceMode determines if the force is to be conventional or impulsive. Only eFORCE and eIMPULSE are supported, as the
force required to produce a given velocity change or acceleration is underdetermined given only the desired change at a
given point.
<b>Sleeping:</b> This call wakes the actor if it is sleeping and the wakeup parameter is true (default).
\param[in] body The rigid body to apply the force to.
\param[in] force Force/impulse to add, defined in the global frame. <b>Range:</b> force vector
\param[in] pos Position in the local frame to add the force at. <b>Range:</b> position vector
\param[in] mode The mode to use when applying the force/impulse(see #PxForceMode).
\param[in] wakeup Specify if the call should wake up the actor.
@see PxForceMode
@see addForceAtPos() addLocalForceAtPos() addLocalForceAtLocalPos()
*/
static void addForceAtLocalPos(PxRigidBody& body, const PxVec3& force, const PxVec3& pos, PxForceMode::Enum mode = PxForceMode::eFORCE, bool wakeup = true);
/**
\brief Applies a force (or impulse) defined in the actor local coordinate frame, acting at a
particular point in global coordinates, to the actor.
Note that if the force does not act along the center of mass of the actor, this
will also add the corresponding torque. Because forces are reset at the end of every timestep, you can maintain a
total external force on an object by calling this once every frame.
\note if this call is used to apply a force or impulse to an articulation link, only the link is updated, not the entire
articulation
::PxForceMode determines if the force is to be conventional or impulsive. Only eFORCE and eIMPULSE are supported, as the
force required to produce a given velocity change or acceleration is underdetermined given only the desired change at a
given point.
<b>Sleeping:</b> This call wakes the actor if it is sleeping and the wakeup parameter is true (default).
\param[in] body The rigid body to apply the force to.
\param[in] force Force/impulse to add, defined in the local frame. <b>Range:</b> force vector
\param[in] pos Position in the global frame to add the force at. <b>Range:</b> position vector
\param[in] mode The mode to use when applying the force/impulse(see #PxForceMode).
\param[in] wakeup Specify if the call should wake up the actor.
@see PxForceMode
@see addForceAtPos() addForceAtLocalPos() addLocalForceAtLocalPos()
*/
static void addLocalForceAtPos(PxRigidBody& body, const PxVec3& force, const PxVec3& pos, PxForceMode::Enum mode = PxForceMode::eFORCE, bool wakeup = true);
/**
\brief Applies a force (or impulse) defined in the actor local coordinate frame, acting at a
particular point in local coordinates, to the actor.
Note that if the force does not act along the center of mass of the actor, this
will also add the corresponding torque. Because forces are reset at the end of every timestep, you can maintain a
total external force on an object by calling this once every frame.
\note if this call is used to apply a force or impulse to an articulation link, only the link is updated, not the entire
articulation
::PxForceMode determines if the force is to be conventional or impulsive. Only eFORCE and eIMPULSE are supported, as the
force required to produce a given velocity change or acceleration is underdetermined given only the desired change at a
given point.
<b>Sleeping:</b> This call wakes the actor if it is sleeping and the wakeup parameter is true (default).
\param[in] body The rigid body to apply the force to.
\param[in] force Force/impulse to add, defined in the local frame. <b>Range:</b> force vector
\param[in] pos Position in the local frame to add the force at. <b>Range:</b> position vector
\param[in] mode The mode to use when applying the force/impulse(see #PxForceMode).
\param[in] wakeup Specify if the call should wake up the actor.
@see PxForceMode
@see addForceAtPos() addForceAtLocalPos() addLocalForceAtPos()
*/
static void addLocalForceAtLocalPos(PxRigidBody& body, const PxVec3& force, const PxVec3& pos, PxForceMode::Enum mode = PxForceMode::eFORCE, bool wakeup = true);
/**
\brief Computes the velocity of a point given in world coordinates if it were attached to the
specified body and moving with it.
\param[in] body The rigid body the point is attached to.
\param[in] pos Position we wish to determine the velocity for, defined in the global frame. <b>Range:</b> position vector
\return The velocity of point in the global frame.
@see getLocalPointVelocity()
*/
static PxVec3 getVelocityAtPos(const PxRigidBody& body, const PxVec3& pos);
/**
\brief Computes the velocity of a point given in local coordinates if it were attached to the
specified body and moving with it.
\param[in] body The rigid body the point is attached to.
\param[in] pos Position we wish to determine the velocity for, defined in the local frame. <b>Range:</b> position vector
\return The velocity of point in the local frame.
@see getLocalPointVelocity()
*/
static PxVec3 getLocalVelocityAtLocalPos(const PxRigidBody& body, const PxVec3& pos);
/**
\brief Computes the velocity of a point (offset from the origin of the body) given in world coordinates if it were attached to the
specified body and moving with it.
\param[in] body The rigid body the point is attached to.
\param[in] pos Position (offset from the origin of the body) we wish to determine the velocity for, defined in the global frame. <b>Range:</b> position vector
\return The velocity of point (offset from the origin of the body) in the global frame.
@see getLocalPointVelocity()
*/
static PxVec3 getVelocityAtOffset(const PxRigidBody& body, const PxVec3& pos);
/**
\brief Performs a linear sweep through space with the body's geometry objects.
\note Supported geometries are: box, sphere, capsule, convex. Other geometry types will be ignored.
\note If eTOUCH is returned from the filter callback, it will trigger an error and the hit will be discarded.
The function sweeps all shapes attached to a given rigid body through space and reports the nearest
object in the scene which intersects any of of the shapes swept paths.
Information about the closest intersection is written to a #PxSweepHit structure.
\param[in] body The rigid body to sweep.
\param[in] scene The scene object to process the query.
\param[in] unitDir Normalized direction of the sweep.
\param[in] distance Sweep distance. Needs to be larger than 0.
\param[in] outputFlags Specifies which properties should be written to the hit information.
\param[out] closestHit Closest hit result.
\param[out] shapeIndex Index of the body shape that caused the closest hit.
\param[in] filterData If any word in filterData.data is non-zero then filterData.data will be used for filtering,
otherwise shape->getQueryFilterData() will be used instead.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxQueryFlag flags are set. If NULL, all hits are assumed to be blocking.
\param[in] cache Cached hit shape (optional). Ray is tested against cached shape first then against the scene.
Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.
\param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.
\return True if a blocking hit was found.
@see PxScene PxQueryFlags PxFilterData PxBatchQueryPreFilterShader PxBatchQueryPostFilterShader PxSweepHit
*/
static bool linearSweepSingle(
PxRigidBody& body, PxScene& scene, const PxVec3& unitDir, const PxReal distance,
PxHitFlags outputFlags,
PxSweepHit& closestHit, PxU32& shapeIndex,
const PxQueryFilterData& filterData = PxQueryFilterData(),
PxQueryFilterCallback* filterCall = NULL,
const PxQueryCache* cache = NULL,
const PxReal inflation=0.0f);
/**
\brief Performs a linear sweep through space with the body's geometry objects, returning all overlaps.
\note Supported geometries are: box, sphere, capsule, convex. Other geometry types will be ignored.
This function sweeps all shapes attached to a given rigid body through space and reports all
objects in the scene that intersect any of the shapes' swept paths until there are no more objects to report
or a blocking hit is encountered.
\param[in] body The rigid body to sweep.
\param[in] scene The scene object to process the query.
\param[in] unitDir Normalized direction of the sweep.
\param[in] distance Sweep distance. Needs to be larger than 0.
\param[in] outputFlags Specifies which properties should be written to the hit information.
\param[out] touchHitBuffer Raycast hit information buffer. If the buffer overflows, an arbitrary subset of touch hits
is returned (typically the query should be restarted with a larger buffer).
\param[out] touchHitShapeIndices After the query is completed, touchHitShapeIndices[i] will contain the body index that caused the hit stored in hitBuffer[i]
\param[in] touchHitBufferSize Size of both touch hit buffers in elements.
\param[out] block Closest blocking hit is returned via this reference.
\param[out] blockingShapeIndex Set to -1 if if a blocking hit was not found, otherwise set to closest blocking hit shape index. The touching hits are reported separately in hitBuffer.
\param[out] overflow Set to true if touchHitBuffer didn't have enough space for all results. Touch hits will be incomplete if overflow occurred. Possible solution is to restart the query with a larger buffer.
\param[in] filterData If any word in filterData.data is non-zero then filterData.data will be used for filtering,
otherwise shape->getQueryFilterData() will be used instead.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxQueryFlag flags are set. If NULL, all hits are assumed to be blocking.
\param[in] cache Cached hit shape (optional). Ray is tested against cached shape first then against the scene.
Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.
\param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.
\return the number of touching hits. If overflow is set to true, the results are incomplete. In case of overflow there are also no guarantees that all touching hits returned are closer than the blocking hit.
@see PxScene PxQueryFlags PxFilterData PxBatchQueryPreFilterShader PxBatchQueryPostFilterShader PxSweepHit
*/
static PxU32 linearSweepMultiple(
PxRigidBody& body, PxScene& scene, const PxVec3& unitDir, const PxReal distance,
PxHitFlags outputFlags,
PxSweepHit* touchHitBuffer, PxU32* touchHitShapeIndices, PxU32 touchHitBufferSize,
PxSweepHit& block, PxI32& blockingShapeIndex, bool& overflow,
const PxQueryFilterData& filterData = PxQueryFilterData(),
PxQueryFilterCallback* filterCall = NULL,
const PxQueryCache* cache = NULL, const PxReal inflation = 0.0f);
/**
\brief Compute the change to linear and angular velocity that would occur if an impulsive force and torque were to be applied to a specified rigid body.
The rigid body is left unaffected unless a subsequent independent call is executed that actually applies the computed changes to velocity and angular velocity.
\note if this call is used to determine the velocity delta for an articulation link, only the mass properties of the link are taken into account.
@see PxRigidBody::getLinearVelocity, PxRigidBody::setLinearVelocity, PxRigidBody::getAngularVelocity, PxRigidBody::setAngularVelocity
\param[in] body The body under consideration.
\param[in] impulsiveForce The impulsive force that would be applied to the specified rigid body.
\param[in] impulsiveTorque The impulsive torque that would be applied to the specified rigid body.
\param[out] deltaLinearVelocity The change in linear velocity that would arise if impulsiveForce was to be applied to the specified rigid body.
\param[out] deltaAngularVelocity The change in angular velocity that would arise if impulsiveTorque was to be applied to the specified rigid body.
*/
static void computeVelocityDeltaFromImpulse(const PxRigidBody& body, const PxVec3& impulsiveForce, const PxVec3& impulsiveTorque, PxVec3& deltaLinearVelocity, PxVec3& deltaAngularVelocity);
/**
\brief Computes the linear and angular velocity change vectors for a given impulse at a world space position taking a mass and inertia scale into account
This function is useful for extracting the respective linear and angular velocity changes from a contact or joint when the mass/inertia ratios have been adjusted.
\note if this call is used to determine the velocity delta for an articulation link, only the mass properties of the link are taken into account.
\param[in] body The rigid body
\param[in] globalPose The body's world space transform
\param[in] point The point in world space where the impulse is applied
\param[in] impulse The impulse vector in world space
\param[in] invMassScale The inverse mass scale
\param[in] invInertiaScale The inverse inertia scale
\param[out] deltaLinearVelocity The linear velocity change
\param[out] deltaAngularVelocity The angular velocity change
*/
static void computeVelocityDeltaFromImpulse(const PxRigidBody& body, const PxTransform& globalPose, const PxVec3& point, const PxVec3& impulse, const PxReal invMassScale,
const PxReal invInertiaScale, PxVec3& deltaLinearVelocity, PxVec3& deltaAngularVelocity);
/**
\brief Computes the linear and angular impulse vectors for a given impulse at a world space position taking a mass and inertia scale into account
This function is useful for extracting the respective linear and angular impulses from a contact or joint when the mass/inertia ratios have been adjusted.
\param[in] body The rigid body
\param[in] globalPose The body's world space transform
\param[in] point The point in world space where the impulse is applied
\param[in] impulse The impulse vector in world space
\param[in] invMassScale The inverse mass scale
\param[in] invInertiaScale The inverse inertia scale
\param[out] linearImpulse The linear impulse
\param[out] angularImpulse The angular impulse
*/
static void computeLinearAngularImpulse(const PxRigidBody& body, const PxTransform& globalPose, const PxVec3& point, const PxVec3& impulse, const PxReal invMassScale,
const PxReal invInertiaScale, PxVec3& linearImpulse, PxVec3& angularImpulse);
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,309 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_SCENE_QUERY_H
#define PX_PHYSICS_EXTENSIONS_SCENE_QUERY_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "PxScene.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
// These types have been deprecated (removed) in PhysX 3.4. We typedef them to the new types here for easy migration from 3.3 to 3.4.
typedef PxQueryHit PxSceneQueryHit;
typedef PxQueryFilterData PxSceneQueryFilterData;
typedef PxQueryFilterCallback PxSceneQueryFilterCallback;
typedef PxQueryCache PxSceneQueryCache;
typedef PxHitFlag PxSceneQueryFlag;
typedef PxHitFlags PxSceneQueryFlags;
/**
\brief utility functions for use with PxScene, related to scene queries.
Some of these functions have been deprecated (removed) in PhysX 3.4. We re-implement them here for easy migration from 3.3 to 3.4.
@see PxShape
*/
class PxSceneQueryExt
{
public:
/**
\brief Raycast returning any blocking hit, not necessarily the closest.
Returns whether any rigid actor is hit along the ray.
\note Shooting a ray from within an object leads to different results depending on the shape type. Please check the details in article SceneQuery. User can ignore such objects by using one of the provided filter mechanisms.
\param[in] scene The scene
\param[in] origin Origin of the ray.
\param[in] unitDir Normalized direction of the ray.
\param[in] distance Length of the ray. Needs to be larger than 0.
\param[out] hit Raycast hit information.
\param[in] filterData Filtering data and simple logic.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be blocking.
\param[in] cache Cached hit shape (optional). Ray is tested against cached shape first. If no hit is found the ray gets queried against the scene.
Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.
Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking.
\return True if a blocking hit was found.
@see PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache PxSceneQueryHit
*/
static bool raycastAny( const PxScene& scene,
const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
PxSceneQueryHit& hit, const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL);
/**
\brief Raycast returning a single result.
Returns the first rigid actor that is hit along the ray. Data for a blocking hit will be returned as specified by the outputFlags field. Touching hits will be ignored.
\note Shooting a ray from within an object leads to different results depending on the shape type. Please check the details in article SceneQuery. User can ignore such objects by using one of the provided filter mechanisms.
\param[in] scene The scene
\param[in] origin Origin of the ray.
\param[in] unitDir Normalized direction of the ray.
\param[in] distance Length of the ray. Needs to be larger than 0.
\param[in] outputFlags Specifies which properties should be written to the hit information
\param[out] hit Raycast hit information.
\param[in] filterData Filtering data and simple logic.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be blocking.
\param[in] cache Cached hit shape (optional). Ray is tested against cached shape first then against the scene.
Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.
Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking.
\return True if a blocking hit was found.
@see PxSceneQueryFlags PxRaycastHit PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache
*/
static bool raycastSingle( const PxScene& scene,
const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
PxSceneQueryFlags outputFlags, PxRaycastHit& hit,
const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL);
/**
\brief Raycast returning multiple results.
Find all rigid actors that get hit along the ray. Each result contains data as specified by the outputFlags field.
\note Touching hits are not ordered.
\note Shooting a ray from within an object leads to different results depending on the shape type. Please check the details in article SceneQuery. User can ignore such objects by using one of the provided filter mechanisms.
\param[in] scene The scene
\param[in] origin Origin of the ray.
\param[in] unitDir Normalized direction of the ray.
\param[in] distance Length of the ray. Needs to be larger than 0.
\param[in] outputFlags Specifies which properties should be written to the hit information
\param[out] hitBuffer Raycast hit information buffer. If the buffer overflows, the blocking hit is returned as the last entry together with an arbitrary subset
of the nearer touching hits (typically the query should be restarted with a larger buffer).
\param[in] hitBufferSize Size of the hit buffer.
\param[out] blockingHit True if a blocking hit was found. If found, it is the last in the buffer, preceded by any touching hits which are closer. Otherwise the touching hits are listed.
\param[in] filterData Filtering data and simple logic.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be touching.
\param[in] cache Cached hit shape (optional). Ray is tested against cached shape first then against the scene.
Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.
Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking.
\return Number of hits in the buffer, or -1 if the buffer overflowed.
@see PxSceneQueryFlags PxRaycastHit PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache
*/
static PxI32 raycastMultiple( const PxScene& scene,
const PxVec3& origin, const PxVec3& unitDir, const PxReal distance,
PxSceneQueryFlags outputFlags,
PxRaycastHit* hitBuffer, PxU32 hitBufferSize, bool& blockingHit,
const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL);
/**
\brief Sweep returning any blocking hit, not necessarily the closest.
Returns whether any rigid actor is hit along the sweep path.
\note If a shape from the scene is already overlapping with the query shape in its starting position, behavior is controlled by the PxSceneQueryFlag::eINITIAL_OVERLAP flag.
\param[in] scene The scene
\param[in] geometry Geometry of object to sweep (supported types are: box, sphere, capsule, convex).
\param[in] pose Pose of the sweep object.
\param[in] unitDir Normalized direction of the sweep.
\param[in] distance Sweep distance. Needs to be larger than 0. Will be clamped to PX_MAX_SWEEP_DISTANCE.
\param[in] queryFlags Combination of PxSceneQueryFlag defining the query behavior
\param[out] hit Sweep hit information.
\param[in] filterData Filtering data and simple logic.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be blocking.
\param[in] cache Cached hit shape (optional). Sweep is performed against cached shape first. If no hit is found the sweep gets queried against the scene.
Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.
Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking.
\param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.
\return True if a blocking hit was found.
@see PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryHit PxSceneQueryCache
*/
static bool sweepAny( const PxScene& scene,
const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
PxSceneQueryFlags queryFlags,
PxSceneQueryHit& hit,
const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
PxSceneQueryFilterCallback* filterCall = NULL,
const PxSceneQueryCache* cache = NULL,
PxReal inflation = 0.0f);
/**
\brief Sweep returning a single result.
Returns the first rigid actor that is hit along the ray. Data for a blocking hit will be returned as specified by the outputFlags field. Touching hits will be ignored.
\note If a shape from the scene is already overlapping with the query shape in its starting position, behavior is controlled by the PxSceneQueryFlag::eINITIAL_OVERLAP flag.
\param[in] scene The scene
\param[in] geometry Geometry of object to sweep (supported types are: box, sphere, capsule, convex).
\param[in] pose Pose of the sweep object.
\param[in] unitDir Normalized direction of the sweep.
\param[in] distance Sweep distance. Needs to be larger than 0. Will be clamped to PX_MAX_SWEEP_DISTANCE.
\param[in] outputFlags Specifies which properties should be written to the hit information.
\param[out] hit Sweep hit information.
\param[in] filterData Filtering data and simple logic.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be blocking.
\param[in] cache Cached hit shape (optional). Sweep is performed against cached shape first then against the scene.
Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.
Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking.
\param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.
\return True if a blocking hit was found.
@see PxSceneQueryFlags PxSweepHit PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache
*/
static bool sweepSingle(const PxScene& scene,
const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
PxSceneQueryFlags outputFlags,
PxSweepHit& hit,
const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
PxSceneQueryFilterCallback* filterCall = NULL,
const PxSceneQueryCache* cache = NULL,
PxReal inflation=0.0f);
/**
\brief Sweep returning multiple results.
Find all rigid actors that get hit along the sweep. Each result contains data as specified by the outputFlags field.
\note Touching hits are not ordered.
\note If a shape from the scene is already overlapping with the query shape in its starting position, behavior is controlled by the PxSceneQueryFlag::eINITIAL_OVERLAP flag.
\param[in] scene The scene
\param[in] geometry Geometry of object to sweep (supported types are: box, sphere, capsule, convex).
\param[in] pose Pose of the sweep object.
\param[in] unitDir Normalized direction of the sweep.
\param[in] distance Sweep distance. Needs to be larger than 0. Will be clamped to PX_MAX_SWEEP_DISTANCE.
\param[in] outputFlags Specifies which properties should be written to the hit information.
\param[out] hitBuffer Sweep hit information buffer. If the buffer overflows, the blocking hit is returned as the last entry together with an arbitrary subset
of the nearer touching hits (typically the query should be restarted with a larger buffer).
\param[in] hitBufferSize Size of the hit buffer.
\param[out] blockingHit True if a blocking hit was found. If found, it is the last in the buffer, preceded by any touching hits which are closer. Otherwise the touching hits are listed.
\param[in] filterData Filtering data and simple logic.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to be touching.
\param[in] cache Cached hit shape (optional). Sweep is performed against cached shape first then against the scene.
Note: Filtering is not executed for a cached shape if supplied; instead, if a hit is found, it is assumed to be a blocking hit.
Note: Using past touching hits as cache will produce incorrect behavior since the cached hit will always be treated as blocking.
\param[in] inflation This parameter creates a skin around the swept geometry which increases its extents for sweeping. The sweep will register a hit as soon as the skin touches a shape, and will return the corresponding distance and normal.
\return Number of hits in the buffer, or -1 if the buffer overflowed.
@see PxSceneQueryFlags PxSweepHit PxSceneQueryFilterData PxSceneQueryFilterCallback PxSceneQueryCache
*/
static PxI32 sweepMultiple( const PxScene& scene,
const PxGeometry& geometry, const PxTransform& pose, const PxVec3& unitDir, const PxReal distance,
PxSceneQueryFlags outputFlags, PxSweepHit* hitBuffer, PxU32 hitBufferSize, bool& blockingHit,
const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
PxSceneQueryFilterCallback* filterCall = NULL, const PxSceneQueryCache* cache = NULL,
PxReal inflation = 0.0f);
/**
\brief Test overlap between a geometry and objects in the scene.
\note Filtering: Overlap tests do not distinguish between touching and blocking hit types. Both get written to the hit buffer.
\note PxHitFlag::eMESH_MULTIPLE and PxHitFlag::eMESH_BOTH_SIDES have no effect in this case
\param[in] scene The scene
\param[in] geometry Geometry of object to check for overlap (supported types are: box, sphere, capsule, convex).
\param[in] pose Pose of the object.
\param[out] hitBuffer Buffer to store the overlapping objects to. If the buffer overflows, an arbitrary subset of overlapping objects is stored (typically the query should be restarted with a larger buffer).
\param[in] hitBufferSize Size of the hit buffer.
\param[in] filterData Filtering data and simple logic.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to overlap.
\return Number of hits in the buffer, or -1 if the buffer overflowed.
@see PxSceneQueryFlags PxSceneQueryFilterData PxSceneQueryFilterCallback
*/
static PxI32 overlapMultiple( const PxScene& scene,
const PxGeometry& geometry, const PxTransform& pose,
PxOverlapHit* hitBuffer, PxU32 hitBufferSize,
const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
PxSceneQueryFilterCallback* filterCall = NULL);
/**
\brief Test returning, for a given geometry, any overlapping object in the scene.
\note Filtering: Overlap tests do not distinguish between touching and blocking hit types. Both trigger a hit.
\note PxHitFlag::eMESH_MULTIPLE and PxHitFlag::eMESH_BOTH_SIDES have no effect in this case
\param[in] scene The scene
\param[in] geometry Geometry of object to check for overlap (supported types are: box, sphere, capsule, convex).
\param[in] pose Pose of the object.
\param[out] hit Pointer to store the overlapping object to.
\param[in] filterData Filtering data and simple logic.
\param[in] filterCall Custom filtering logic (optional). Only used if the corresponding #PxHitFlag flags are set. If NULL, all hits are assumed to overlap.
\return True if an overlap was found.
@see PxSceneQueryFlags PxSceneQueryFilterData PxSceneQueryFilterCallback
*/
static bool overlapAny( const PxScene& scene,
const PxGeometry& geometry, const PxTransform& pose,
PxOverlapHit& hit,
const PxSceneQueryFilterData& filterData = PxSceneQueryFilterData(),
PxSceneQueryFilterCallback* filterCall = NULL);
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,290 @@
//
// 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-2019 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_SERIALIZATION_H
#define PX_SERIALIZATION_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "common/PxBase.h"
#include "cooking/PxCooking.h"
#include "foundation/PxIO.h"
#include "common/PxTolerancesScale.h"
#include "common/PxTypeInfo.h"
#include "common/PxStringTable.h"
/**
PX_BINARY_SERIAL_VERSION is used to version the PhysX binary data and meta data. The global unique identifier of the PhysX SDK needs to match
the one in the data and meta data, otherwise they are considered incompatible. A 32 character wide GUID can be generated with https://www.guidgenerator.com/ for example.
*/
#define PX_BINARY_SERIAL_VERSION "F193874828914B3A8AC4EFE75AED0247"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxBinaryConverter;
/**
\brief Utility functions for serialization
@see PxCollection, PxSerializationRegistry
*/
class PxSerialization
{
public:
/**
\brief Additional PxScene and PxPhysics options stored in XML serialized data.
The PxXmlMiscParameter parameter can be serialized and deserialized along with PxCollection instances (XML only).
This is for application use only and has no impact on how objects are serialized or deserialized.
@see PxSerialization::createCollectionFromXml, PxSerialization::serializeCollectionToXml
*/
struct PxXmlMiscParameter
{
/**
\brief Up vector for the scene reference coordinate system.
*/
PxVec3 upVector;
/**
\brief Tolerances scale to be used for the scene.
*/
PxTolerancesScale scale;
PxXmlMiscParameter() : upVector(0) {}
PxXmlMiscParameter(PxVec3& inUpVector, PxTolerancesScale inScale) : upVector(inUpVector), scale(inScale) {}
};
/**
\brief Returns whether the collection is serializable with the externalReferences collection.
Some definitions to explain whether a collection can be serialized or not:
For definitions of <b>requires</b> and <b>complete</b> see #PxSerialization::complete
A serializable object is <b>subordinate</b> if it cannot be serialized on its own
The following objects are subordinate:
- articulation links
- articulation joints
- joints
A collection C can be serialized with external references collection D iff
- C is complete relative to D (no dangling references)
- Every object in D required by an object in C has a valid ID (no unnamed references)
- Every subordinate object in C is required by another object in C (no orphans)
\param[in] collection Collection to be checked
\param[in] sr PxSerializationRegistry instance with information about registered classes.
\param[in] externalReferences the external References collection
\return Whether the collection is serializable
@see PxSerialization::complete, PxSerialization::serializeCollectionToBinary, PxSerialization::serializeCollectionToXml, PxSerializationRegistry
*/
static bool isSerializable(PxCollection& collection, PxSerializationRegistry& sr, const PxCollection* externalReferences = NULL);
/**
\brief Adds to a collection all objects such that it can be successfully serialized.
A collection C is complete relative to an other collection D if every object required by C is either in C or D.
This function adds objects to a collection, such that it becomes complete with respect to the exceptFor collection.
Completeness is needed for serialization. See #PxSerialization::serializeCollectionToBinary,
#PxSerialization::serializeCollectionToXml.
Sdk objects require other sdk object according to the following rules:
- joints require their actors and constraint
- rigid actors require their shapes
- shapes require their material(s) and mesh (triangle mesh, convex mesh or height field), if any
- articulations require their links and joints
- aggregates require their actors
If followJoints is specified another rule is added:
- actors require their joints
Specifying followJoints will make whole jointed actor chains being added to the collection. Following chains
is interrupted whenever a object in exceptFor is encountered.
\param[in,out] collection Collection which is completed
\param[in] sr PxSerializationRegistry instance with information about registered classes.
\param[in] exceptFor Optional exemption collection
\param[in] followJoints Specifies whether joints should be added for jointed actors
@see PxCollection, PxSerialization::serializeCollectionToBinary, PxSerialization::serializeCollectionToXml, PxSerializationRegistry
*/
static void complete(PxCollection& collection, PxSerializationRegistry& sr, const PxCollection* exceptFor = NULL, bool followJoints = false);
/**
\brief Creates PxSerialObjectId values for unnamed objects in a collection.
Creates PxSerialObjectId names for unnamed objects in a collection starting at a base value and incrementing,
skipping values that are already assigned to objects in the collection.
\param[in,out] collection Collection for which names are created
\param[in] base Start address for PxSerialObjectId names
@see PxCollection
*/
static void createSerialObjectIds(PxCollection& collection, const PxSerialObjectId base);
/**
\brief Creates a PxCollection from XML data.
\param inputData The input data containing the XML collection.
\param cooking PxCooking instance used for sdk object instantiation.
\param sr PxSerializationRegistry instance with information about registered classes.
\param externalRefs PxCollection used to resolve external references.
\param stringTable PxStringTable instance used for storing object names.
\param outArgs Optional parameters of physics and scene deserialized from XML. See #PxSerialization::PxXmlMiscParameter
\return a pointer to a PxCollection if successful or NULL if it failed.
@see PxCollection, PxSerializationRegistry, PxInputData, PxStringTable, PxCooking, PxSerialization::PxXmlMiscParameter
*/
static PxCollection* createCollectionFromXml(PxInputData& inputData, PxCooking& cooking, PxSerializationRegistry& sr, const PxCollection* externalRefs = NULL, PxStringTable* stringTable = NULL, PxXmlMiscParameter* outArgs = NULL);
/**
\brief Deserializes a PxCollection from memory.
Creates a collection from memory. If the collection has external dependencies another collection
can be provided to resolve these.
The memory block provided has to be 128 bytes aligned and contain a contiguous serialized collection as written
by PxSerialization::serializeCollectionToBinary. The contained binary data needs to be compatible with the current binary format version
which is defined by "PX_PHYSICS_VERSION_MAJOR.PX_PHYSICS_VERSION_MINOR.PX_PHYSICS_VERSION_BUGFIX-PX_BINARY_SERIAL_VERSION".
For a list of compatible sdk releases refer to the documentation of PX_BINARY_SERIAL_VERSION.
\param[in] memBlock Pointer to memory block containing the serialized collection
\param[in] sr PxSerializationRegistry instance with information about registered classes.
\param[in] externalRefs Collection to resolve external dependencies
@see PxCollection, PxSerialization::complete, PxSerialization::serializeCollectionToBinary, PxSerializationRegistry, PX_BINARY_SERIAL_VERSION
*/
static PxCollection* createCollectionFromBinary(void* memBlock, PxSerializationRegistry& sr, const PxCollection* externalRefs = NULL);
/**
\brief Serializes a physics collection to an XML output stream.
The collection to be serialized needs to be complete @see PxSerialization.complete.
Optionally the XML may contain meshes in binary cooked format for fast loading. It does this when providing a valid non-null PxCooking pointer.
\note Serialization of objects in a scene that is simultaneously being simulated is not supported and leads to undefined behavior.
\param outputStream Stream to save collection to.
\param collection PxCollection instance which is serialized. The collection needs to be complete with respect to the externalRefs collection.
\param sr PxSerializationRegistry instance with information about registered classes.
\param cooking Optional pointer to cooking instance. If provided, cooked mesh data is cached for fast loading.
\param externalRefs Collection containing external references.
\param inArgs Optional parameters of physics and scene serialized to XML along with the collection. See #PxSerialization::PxXmlMiscParameter
\return true if the collection is successfully serialized.
@see PxCollection, PxOutputStream, PxSerializationRegistry, PxCooking, PxSerialization::PxXmlMiscParameter
*/
static bool serializeCollectionToXml(PxOutputStream& outputStream, PxCollection& collection, PxSerializationRegistry& sr, PxCooking* cooking = NULL, const PxCollection* externalRefs = NULL, PxXmlMiscParameter* inArgs = NULL);
/**
\brief Serializes a collection to a binary stream.
Serializes a collection to a stream. In order to resolve external dependencies the externalReferences collection has to be provided.
Optionally names of objects that where set for example with #PxActor::setName are serialized along with the objects.
The collection can be successfully serialized if isSerializable(collection) returns true. See #isSerializable.
The implementation of the output stream needs to fulfill the requirements on the memory block input taken by
PxSerialization::createCollectionFromBinary.
\note Serialization of objects in a scene that is simultaneously being simulated is not supported and leads to undefined behavior.
\param[out] outputStream into which the collection is serialized
\param[in] collection Collection to be serialized
\param[in] sr PxSerializationRegistry instance with information about registered classes.
\param[in] externalRefs Collection used to resolve external dependencies
\param[in] exportNames Specifies whether object names are serialized
\return Whether serialization was successful
@see PxCollection, PxOutputStream, PxSerialization::complete, PxSerialization::createCollectionFromBinary, PxSerializationRegistry
*/
static bool serializeCollectionToBinary(PxOutputStream& outputStream, PxCollection& collection, PxSerializationRegistry& sr, const PxCollection* externalRefs = NULL, bool exportNames = false );
/**
\brief Serializes a collection to a binary stream.
Convenience function that serializes a collection to a stream while rebasing memory addresses and handles
to achieve a deterministic output, independent of the PhysX runtime environment the objects have been created in.
The same functionality can be achieved by manually
- creating a binary data stream with PxSerialization::serializeCollectionToBinary
- producing the binary meta data of the current runtime platform with PxSerialization::dumpBinaryMetaData
- converting the binary data stream with the PxBinaryConverter, using the binary meta for both source and destination
@see PxSerialization::serializeCollectionToBinary, PxSerialization::dumpBinaryMetaData, PxBinaryConverter
*/
static bool serializeCollectionToBinaryDeterministic(PxOutputStream& outputStream, PxCollection& collection, PxSerializationRegistry& sr, const PxCollection* externalRefs = NULL, bool exportNames = false);
/**
\brief Dumps the binary meta-data to a stream.
A meta-data file contains information about the SDK's internal classes and about custom user types ready
for serialization. Such a file is needed to convert binary-serialized data from one platform to another (re-targeting).
The converter needs meta-data files for the source and target platforms to perform conversions.
Custom user types can be supported with PxSerializationRegistry::registerBinaryMetaDataCallback (see the guide for more information).
\param[out] outputStream Stream to write meta data to
\param[in] sr PxSerializationRegistry instance with information about registered classes used for conversion.
@see PxOutputStream, PxSerializationRegistry
*/
static void dumpBinaryMetaData(PxOutputStream& outputStream, PxSerializationRegistry& sr);
/**
\brief Creates binary converter for re-targeting binary-serialized data.
\return Binary converter instance.
*/
static PxBinaryConverter* createBinaryConverter();
/**
\brief Creates an application managed registry for serialization.
\param[in] physics Physics SDK to generate create serialization registry
\return PxSerializationRegistry instance.
@see PxSerializationRegistry
*/
static PxSerializationRegistry* createSerializationRegistry(PxPhysics& physics);
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,158 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_SHAPE_H
#define PX_PHYSICS_EXTENSIONS_SHAPE_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "PxShape.h"
#include "PxRigidActor.h"
#include "geometry/PxGeometryQuery.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief utility functions for use with PxShape
@see PxShape
*/
class PxShapeExt
{
public:
/**
\brief Retrieves the world space pose of the shape.
\param[in] shape The shape for which to get the global pose.
\param[in] actor The actor to which the shape is attached
\return Global pose of shape.
*/
static PX_INLINE PxTransform getGlobalPose(const PxShape& shape, const PxRigidActor& actor)
{
return actor.getGlobalPose() * shape.getLocalPose();
}
/**
\brief Raycast test against the shape.
\param[in] shape the shape
\param[in] actor the actor to which the shape is attached
\param[in] rayOrigin The origin of the ray to test the geometry object against
\param[in] rayDir The direction of the ray to test the geometry object against
\param[in] maxDist Maximum ray length
\param[in] hitFlags Specify which properties per hit should be computed and written to result hit array. Combination of #PxHitFlag flags
\param[in] maxHits max number of returned hits = size of 'rayHits' buffer
\param[out] rayHits Raycast hits information
\return Number of hits between the ray and the shape
@see PxRaycastHit PxTransform
*/
static PX_INLINE PxU32 raycast(const PxShape& shape, const PxRigidActor& actor,
const PxVec3& rayOrigin, const PxVec3& rayDir, PxReal maxDist, PxHitFlags hitFlags,
PxU32 maxHits, PxRaycastHit* rayHits)
{
return PxGeometryQuery::raycast(
rayOrigin, rayDir, shape.getGeometry().any(), getGlobalPose(shape, actor), maxDist, hitFlags, maxHits, rayHits);
}
/**
\brief Test overlap between the shape and a geometry object
\param[in] shape the shape
\param[in] actor the actor to which the shape is attached
\param[in] otherGeom The other geometry object to test overlap with
\param[in] otherGeomPose Pose of the other geometry object
\return True if the shape overlaps the geometry object
@see PxGeometry PxTransform
*/
static PX_INLINE bool overlap(const PxShape& shape, const PxRigidActor& actor,
const PxGeometry& otherGeom, const PxTransform& otherGeomPose)
{
return PxGeometryQuery::overlap(shape.getGeometry().any(), getGlobalPose(shape, actor), otherGeom, otherGeomPose);
}
/**
\brief Sweep a geometry object against the shape.
Currently only box, sphere, capsule and convex mesh shapes are supported, i.e. the swept geometry object must be one of those types.
\param[in] shape the shape
\param[in] actor the actor to which the shape is attached
\param[in] unitDir Normalized direction along which the geometry object should be swept.
\param[in] distance Sweep distance. Needs to be larger than 0.
\param[in] otherGeom The geometry object to sweep against the shape
\param[in] otherGeomPose Pose of the geometry object
\param[out] sweepHit The sweep hit information. Only valid if this method returns true.
\param[in] hitFlags Specify which properties per hit should be computed and written to result hit array. Combination of #PxHitFlag flags
\return True if the swept geometry object hits the shape
@see PxGeometry PxTransform PxSweepHit
*/
static PX_INLINE bool sweep(const PxShape& shape, const PxRigidActor& actor,
const PxVec3& unitDir, const PxReal distance, const PxGeometry& otherGeom, const PxTransform& otherGeomPose,
PxSweepHit& sweepHit, PxHitFlags hitFlags)
{
return PxGeometryQuery::sweep(unitDir, distance, otherGeom, otherGeomPose, shape.getGeometry().any(), getGlobalPose(shape, actor), sweepHit, hitFlags);
}
/**
\brief Retrieves the axis aligned bounding box enclosing the shape.
\return The shape's bounding box.
\param[in] shape the shape
\param[in] actor the actor to which the shape is attached
\param[in] inflation Scale factor for computed world bounds. Box extents are multiplied by this value.
@see PxBounds3
*/
static PX_INLINE PxBounds3 getWorldBounds(const PxShape& shape, const PxRigidActor& actor, float inflation=1.01f)
{
return PxGeometryQuery::getWorldBounds(shape.getGeometry().any(), getGlobalPose(shape, actor), inflation);
}
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,337 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_SIMPLE_FACTORY_H
#define PX_PHYSICS_EXTENSIONS_SIMPLE_FACTORY_H
/** \addtogroup extensions
@{
*/
#include "common/PxPhysXCommonConfig.h"
#include "foundation/PxTransform.h"
#include "foundation/PxPlane.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxPhysics;
class PxMaterial;
class PxRigidActor;
class PxRigidDynamic;
class PxRigidStatic;
class PxGeometry;
class PxShape;
/** \brief simple method to create a PxRigidDynamic actor with a single PxShape.
\param[in] sdk the PxPhysics object
\param[in] transform the global pose of the new object
\param[in] geometry the geometry of the new object's shape, which must be a sphere, capsule, box or convex
\param[in] material the material for the new object's shape
\param[in] density the density of the new object. Must be greater than zero.
\param[in] shapeOffset an optional offset for the new shape, defaults to identity
\return a new dynamic actor with the PxRigidBodyFlag, or NULL if it could
not be constructed
@see PxRigidDynamic PxShapeFlag
*/
PxRigidDynamic* PxCreateDynamic(PxPhysics& sdk,
const PxTransform& transform,
const PxGeometry& geometry,
PxMaterial& material,
PxReal density,
const PxTransform& shapeOffset = PxTransform(PxIdentity));
/** \brief simple method to create a PxRigidDynamic actor with a single PxShape.
\param[in] sdk the PxPhysics object
\param[in] transform the transform of the new object
\param[in] shape the shape of the new object
\param[in] density the density of the new object. Must be greater than zero.
\return a new dynamic actor with the PxRigidBodyFlag, or NULL if it could
not be constructed
@see PxRigidDynamic PxShapeFlag
*/
PxRigidDynamic* PxCreateDynamic(PxPhysics& sdk,
const PxTransform& transform,
PxShape& shape,
PxReal density);
/** \brief simple method to create a kinematic PxRigidDynamic actor with a single PxShape.
\param[in] sdk the PxPhysics object
\param[in] transform the global pose of the new object
\param[in] geometry the geometry of the new object's shape
\param[in] material the material for the new object's shape
\param[in] density the density of the new object. Must be greater than zero if the object is to participate in simulation.
\param[in] shapeOffset an optional offset for the new shape, defaults to identity
\note unlike PxCreateDynamic, the geometry is not restricted to box, capsule, sphere or convex. However,
kinematics of other geometry types may not participate in simulation collision and may be used only for
triggers or scene queries of moving objects under animation control. In this case the density parameter
will be ignored and the created shape will be set up as a scene query only shape (see #PxShapeFlag::eSCENE_QUERY_SHAPE)
\return a new dynamic actor with the PxRigidBodyFlag::eKINEMATIC set, or NULL if it could
not be constructed
@see PxRigidDynamic PxShapeFlag
*/
PxRigidDynamic* PxCreateKinematic(PxPhysics& sdk,
const PxTransform& transform,
const PxGeometry& geometry,
PxMaterial& material,
PxReal density,
const PxTransform& shapeOffset = PxTransform(PxIdentity));
/** \brief simple method to create a kinematic PxRigidDynamic actor with a single PxShape.
\param[in] sdk the PxPhysics object
\param[in] transform the global pose of the new object
\param[in] density the density of the new object. Must be greater than zero if the object is to participate in simulation.
\param[in] shape the shape of the new object
\note unlike PxCreateDynamic, the geometry is not restricted to box, capsule, sphere or convex. However,
kinematics of other geometry types may not participate in simulation collision and may be used only for
triggers or scene queries of moving objects under animation control. In this case the density parameter
will be ignored and the created shape will be set up as a scene query only shape (see #PxShapeFlag::eSCENE_QUERY_SHAPE)
\return a new dynamic actor with the PxRigidBodyFlag::eKINEMATIC set, or NULL if it could
not be constructed
@see PxRigidDynamic PxShapeFlag
*/
PxRigidDynamic* PxCreateKinematic(PxPhysics& sdk,
const PxTransform& transform,
PxShape& shape,
PxReal density);
/** \brief simple method to create a PxRigidStatic actor with a single PxShape.
\param[in] sdk the PxPhysics object
\param[in] transform the global pose of the new object
\param[in] geometry the geometry of the new object's shape
\param[in] material the material for the new object's shape
\param[in] shapeOffset an optional offset for the new shape, defaults to identity
\return a new static actor, or NULL if it could not be constructed
@see PxRigidStatic
*/
PxRigidStatic* PxCreateStatic(PxPhysics& sdk,
const PxTransform& transform,
const PxGeometry& geometry,
PxMaterial& material,
const PxTransform& shapeOffset = PxTransform(PxIdentity));
/** \brief simple method to create a PxRigidStatic actor with a single PxShape.
\param[in] sdk the PxPhysics object
\param[in] transform the global pose of the new object
\param[in] shape the new object's shape
\return a new static actor, or NULL if it could not be constructed
@see PxRigidStatic
*/
PxRigidStatic* PxCreateStatic(PxPhysics& sdk,
const PxTransform& transform,
PxShape& shape);
/** \brief simple method to create a PxRigidStatic actor with a single PxShape.
\param[in] sdk the PxPhysics object
\param[in] transform the global pose of the new object
\param[in] shape the new object's shape
\return a new static actor, or NULL if it could not be constructed
@see PxRigidStatic
*/
PxRigidStatic* PxCreateStatic(PxPhysics& sdk,
const PxTransform& transform,
PxShape& shape);
/**
\brief create a shape by copying attributes from another shape
The function clones a PxShape. The following properties are copied:
- geometry
- flags
- materials
- actor-local pose
- contact offset
- rest offset
- simulation filter data
- query filter data
The following are not copied and retain their default values:
- name
- user data
\param[in] physicsSDK - the physics SDK used to allocate the shape
\param[in] shape the shape from which to take the attributes.
\param[in] isExclusive whether the new shape should be an exclusive or shared shape.
\return the newly-created rigid static
*/
PxShape* PxCloneShape(PxPhysics& physicsSDK,
const PxShape& shape,
bool isExclusive);
/**
\brief create a static body by copying attributes from another rigid actor
The function clones a PxRigidDynamic or PxRigidStatic as a PxRigidStatic. A uniform scale is applied. The following properties are copied:
- shapes
- actor flags
- owner client and client behavior bits
The following are not copied and retain their default values:
- name
- joints or observers
- aggregate or scene membership
- user data
\note Transforms are not copied with bit-exact accuracy.
\param[in] physicsSDK - the physics SDK used to allocate the rigid static
\param[in] actor the rigid actor from which to take the attributes.
\param[in] transform the transform of the new static.
\return the newly-created rigid static
*/
PxRigidStatic* PxCloneStatic(PxPhysics& physicsSDK,
const PxTransform& transform,
const PxRigidActor& actor);
/**
\brief create a dynamic body by copying attributes from an existing body
The following properties are copied:
- shapes
- actor flags and rigidDynamic flags
- mass, moment of inertia, and center of mass frame
- linear and angular velocity
- linear and angular damping
- maximum angular velocity
- position and velocity solver iterations
- maximum depenetration velocity
- sleep threshold
- contact report threshold
- dominance group
- owner client and client behavior bits
- name pointer
The following are not copied and retain their default values:
- name
- joints or observers
- aggregate or scene membership
- sleep timer
- user data
\note Transforms are not copied with bit-exact accuracy.
\param[in] physicsSDK PxPhysics - the physics SDK used to allocate the rigid static
\param[in] body the rigid dynamic to clone.
\param[in] transform the transform of the new dynamic
\return the newly-created rigid static
*/
PxRigidDynamic* PxCloneDynamic(PxPhysics& physicsSDK,
const PxTransform& transform,
const PxRigidDynamic& body);
/** \brief create a plane actor. The plane equation is n.x + d = 0
\param[in] sdk the PxPhysics object
\param[in] plane a plane of the form n.x + d = 0
\param[in] material the material for the new object's shape
\return a new static actor, or NULL if it could not be constructed
@see PxRigidStatic
*/
PxRigidStatic* PxCreatePlane(PxPhysics& sdk,
const PxPlane& plane,
PxMaterial& material);
/**
\brief scale a rigid actor by a uniform scale
The geometry and relative positions of the actor are multiplied by the given scale value. If the actor is a rigid body or an
articulation link and the scaleMassProps value is true, the mass properties are scaled assuming the density is constant: the
center of mass is linearly scaled, the mass is multiplied by the cube of the scale, and the inertia tensor by the fifth power of the scale.
\param[in] actor a rigid actor
\param[in] scale the scale by which to multiply the actor. Must be >0.
\param[in] scaleMassProps whether to scale the mass properties
*/
void PxScaleRigidActor(PxRigidActor& actor, PxReal scale, bool scaleMassProps = true);
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,61 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_SMOOTH_NORMALS_H
#define PX_PHYSICS_EXTENSIONS_SMOOTH_NORMALS_H
/** \addtogroup extensions
@{
*/
#include "common/PxPhysXCommonConfig.h"
/**
\brief Builds smooth vertex normals over a mesh.
- "smooth" because smoothing groups are not supported here
- takes angles into account for correct cube normals computation
To use 32bit indices pass a pointer in dFaces and set wFaces to zero. Alternatively pass a pointer to
wFaces and set dFaces to zero.
\param[in] nbTris Number of triangles
\param[in] nbVerts Number of vertices
\param[in] verts Array of vertices
\param[in] dFaces Array of dword triangle indices, or null
\param[in] wFaces Array of word triangle indices, or null
\param[out] normals Array of computed normals (assumes nbVerts vectors)
\param[in] flip Flips the normals or not
\return True on success.
*/
PX_C_EXPORT bool PX_CALL_CONV PxBuildSmoothNormals(physx::PxU32 nbTris, physx::PxU32 nbVerts, const physx::PxVec3* verts,
const physx::PxU32* dFaces, const physx::PxU16* wFaces, physx::PxVec3* normals, bool flip);
/** @} */
#endif

View File

@@ -0,0 +1,215 @@
//
// 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-2019 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_SPHERICALJOINT_H
#define PX_SPHERICALJOINT_H
/** \addtogroup extensions
@{
*/
#include "extensions/PxJoint.h"
#include "extensions/PxJointLimit.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxSphericalJoint;
/**
\brief Create a spherical joint.
\param[in] physics The physics SDK
\param[in] actor0 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame0 The position and orientation of the joint relative to actor0
\param[in] actor1 An actor to which the joint is attached. NULL may be used to attach the joint to a specific point in the world frame
\param[in] localFrame1 The position and orientation of the joint relative to actor1
@see PxSphericalJoint
*/
PxSphericalJoint* PxSphericalJointCreate(PxPhysics& physics, PxRigidActor* actor0, const PxTransform& localFrame0, PxRigidActor* actor1, const PxTransform& localFrame1);
/**
\brief Flags specific to the spherical joint.
@see PxSphericalJoint
*/
struct PxSphericalJointFlag
{
enum Enum
{
eLIMIT_ENABLED = 1<<1 //!< the cone limit for the spherical joint is enabled
};
};
typedef PxFlags<PxSphericalJointFlag::Enum, PxU16> PxSphericalJointFlags;
PX_FLAGS_OPERATORS(PxSphericalJointFlag::Enum, PxU16)
/**
\brief A joint which behaves in a similar way to a ball and socket.
A spherical joint removes all linear degrees of freedom from two objects.
The position of the joint on each actor is specified by the origin of the body's joint frame.
A spherical joint may have a cone limit, to restrict the motion to within a certain range. In
addition, the bodies may be projected together if the distance between them exceeds a given threshold.
Projection, drive and limits are activated by setting the appropriate flags on the joint.
@see PxRevoluteJointCreate() PxJoint
*/
class PxSphericalJoint : public PxJoint
{
public:
/**
\brief Set the limit cone.
If enabled, the limit cone will constrain the angular movement of the joint to lie
within an elliptical cone.
\return the limit cone
@see PxJointLimitCone setLimit()
*/
virtual PxJointLimitCone getLimitCone() const = 0;
/**
\brief Get the limit cone.
\param[in] limit the limit cone
@see PxJointLimitCone getLimit()
*/
virtual void setLimitCone(const PxJointLimitCone& limit) = 0;
/**
\brief get the swing angle of the joint from the Y axis
*/
virtual PxReal getSwingYAngle() const = 0;
/**
\brief get the swing angle of the joint from the Z axis
*/
virtual PxReal getSwingZAngle() const = 0;
/**
\brief Set the flags specific to the Spherical Joint.
<b>Default</b> PxSphericalJointFlags(0)
\param[in] flags The joint flags.
@see PxSphericalJointFlag setFlag() getFlags()
*/
virtual void setSphericalJointFlags(PxSphericalJointFlags flags) = 0;
/**
\brief Set a single flag specific to a Spherical Joint to true or false.
\param[in] flag The flag to set or clear.
\param[in] value the value to which to set the flag
@see PxSphericalJointFlag, getFlags() setFlags()
*/
virtual void setSphericalJointFlag(PxSphericalJointFlag::Enum flag, bool value) = 0;
/**
\brief Get the flags specific to the Spherical Joint.
\return the joint flags
@see PxSphericalJoint::flags, PxSphericalJointFlag setFlag() setFlags()
*/
virtual PxSphericalJointFlags getSphericalJointFlags() const = 0;
/**
\brief Set the linear tolerance threshold for projection. Projection is enabled if PxConstraintFlag::ePROJECTION
is set for the joint.
If the joint separates by more than this distance along its locked degrees of freedom, the solver
will move the bodies to close the distance.
Setting a very small tolerance may result in simulation jitter or other artifacts.
Sometimes it is not possible to project (for example when the joints form a cycle).
<b>Range:</b> [0, PX_MAX_F32)<br>
<b>Default:</b> 1e10f
\param[in] tolerance the linear tolerance threshold
@see getProjectionLinearTolerance() PxJoint::setConstraintFlags() PxConstraintFlag::ePROJECTION
*/
virtual void setProjectionLinearTolerance(PxReal tolerance) = 0;
/**
\brief Get the linear tolerance threshold for projection.
\return the linear tolerance threshold
@see setProjectionLinearTolerance()
*/
virtual PxReal getProjectionLinearTolerance() const = 0;
/**
\brief Returns string name of PxSphericalJoint, used for serialization
*/
virtual const char* getConcreteTypeName() const { return "PxSphericalJoint"; }
protected:
//serialization
/**
\brief Constructor
*/
PX_INLINE PxSphericalJoint(PxType concreteType, PxBaseFlags baseFlags) : PxJoint(concreteType, baseFlags) {}
/**
\brief Deserialization constructor
*/
PX_INLINE PxSphericalJoint(PxBaseFlags baseFlags) : PxJoint(baseFlags) {}
/**
\brief Returns whether a given type name matches with the type of this instance
*/
virtual bool isKindOf(const char* name) const { return !::strcmp("PxSphericalJoint", name) || PxJoint::isKindOf(name); }
//~serialization
};
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif

View File

@@ -0,0 +1,57 @@
//
// 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-2019 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_STRING_TABLE_EXT_H
#define PX_STRING_TABLE_EXT_H
#include "foundation/Px.h"
#include "common/PxStringTable.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
/**
\brief a factory class for creating PxStringTable with a specific allocator.
@see PxStringTable
*/
class PxStringTableExt
{
public:
static PxStringTable& createStringTable( physx::PxAllocatorCallback& inAllocator );
};
#if !PX_DOXYGEN
} // namespace physx
#endif
#endif

View File

@@ -0,0 +1,188 @@
//
// 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-2019 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_PHYSICS_EXTENSIONS_TRIANGLE_MESH_H
#define PX_PHYSICS_EXTENSIONS_TRIANGLE_MESH_H
/** \addtogroup extensions
@{
*/
#include "PxPhysXConfig.h"
#include "common/PxPhysXCommonConfig.h"
#if !PX_DOXYGEN
namespace physx
{
#endif
class PxGeometry;
class PxTriangleMeshGeometry;
class PxHeightFieldGeometry;
/**
\brief Utility class to find mesh triangles touched by a specified geometry object.
This class is a helper calling PxMeshQuery::findOverlapTriangleMesh or PxMeshQuery::findOverlapHeightField under the hood,
while taking care of necessary memory management issues.
PxMeshQuery::findOverlapTriangleMesh and PxMeshQuery::findOverlapHeightField are the "raw" functions operating on user-provided fixed-size
buffers. These functions abort with an error code in case of buffer overflow. PxMeshOverlapUtil is a convenient helper function checking
this error code, and resizing buffers appropriately, until the desired call succeeds.
Returned triangle indices are stored within the class, and can be used with PxMeshQuery::getTriangle() to retrieve the triangle properties.
*/
class PxMeshOverlapUtil
{
public:
PxMeshOverlapUtil();
~PxMeshOverlapUtil();
/**
\brief Find the mesh triangles which touch the specified geometry object.
\param[in] geom The geometry object to test for mesh triangle overlaps. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry
\param[in] geomPose Pose of the geometry object
\param[in] meshGeom The triangle mesh geometry to check overlap against
\param[in] meshPose Pose of the triangle mesh
\return Number of overlaps found. Triangle indices can then be accessed through the #getResults() function.
@see PxGeometry PxTransform PxTriangleMeshGeometry PxMeshQuery::findOverlapTriangleMesh
*/
PxU32 findOverlap(const PxGeometry& geom, const PxTransform& geomPose, const PxTriangleMeshGeometry& meshGeom, const PxTransform& meshPose);
/**
\brief Find the height field triangles which touch the specified geometry object.
\param[in] geom The geometry object to test for height field overlaps. Supported geometries are #PxSphereGeometry, #PxCapsuleGeometry and #PxBoxGeometry. The sphere and capsule queries are currently conservative estimates.
\param[in] geomPose Pose of the geometry object
\param[in] hfGeom The height field geometry to check overlap against
\param[in] hfPose Pose of the height field
\return Number of overlaps found. Triangle indices can then be accessed through the #getResults() function.
@see PxGeometry PxTransform PxHeightFieldGeometry PxMeshQuery::findOverlapHeightField
*/
PxU32 findOverlap(const PxGeometry& geom, const PxTransform& geomPose, const PxHeightFieldGeometry& hfGeom, const PxTransform& hfPose);
/**
\brief Retrieves array of triangle indices after a findOverlap call.
\return Indices of touched triangles
*/
PX_FORCE_INLINE const PxU32* getResults() const { return mResultsMemory; }
/**
\brief Retrieves number of triangle indices after a findOverlap call.
\return Number of touched triangles
*/
PX_FORCE_INLINE PxU32 getNbResults() const { return mNbResults; }
private:
PxU32* mResultsMemory;
PxU32 mResults[256];
PxU32 mNbResults;
PxU32 mMaxNbResults;
};
/**
\brief Computes an approximate minimum translational distance (MTD) between a geometry object and a mesh.
This iterative function computes an approximate vector that can be used to depenetrate a geom object
from a triangle mesh. Returned depenetration vector should be applied to 'geom', to get out of the mesh.
The function works best when the amount of overlap between the geom object and the mesh is small. If the
geom object's center goes inside the mesh, backface culling usually kicks in, no overlap is detected,
and the function does not compute an MTD vector.
The function early exits if no overlap is detected after a depenetration attempt. This means that if
maxIter = N, the code will attempt at most N iterations but it might exit earlier if depenetration has
been successful. Usually N = 4 gives good results.
\param[out] direction Computed MTD unit direction
\param[out] depth Penetration depth. Always positive or zero.
\param[in] geom The geometry object
\param[in] geomPose Pose for the geometry object
\param[in] meshGeom The mesh geometry
\param[in] meshPose Pose for the mesh
\param[in] maxIter Max number of iterations before returning.
\param[out] usedIter Number of depenetrations attempts performed during the call. Will not be returned if the pointer is NULL.
\return True if the MTD has successfully been computed, i.e. if objects do overlap.
@see PxGeometry PxTransform PxTriangleMeshGeometry
*/
bool PxComputeTriangleMeshPenetration(PxVec3& direction,
PxReal& depth,
const PxGeometry& geom,
const PxTransform& geomPose,
const PxTriangleMeshGeometry& meshGeom,
const PxTransform& meshPose,
PxU32 maxIter,
PxU32* usedIter = NULL);
/**
\brief Computes an approximate minimum translational distance (MTD) between a geometry object and a heightfield.
This iterative function computes an approximate vector that can be used to depenetrate a geom object
from a heightfield. Returned depenetration vector should be applied to 'geom', to get out of the heightfield.
The function works best when the amount of overlap between the geom object and the mesh is small. If the
geom object's center goes inside the heightfield, backface culling usually kicks in, no overlap is detected,
and the function does not compute an MTD vector.
The function early exits if no overlap is detected after a depenetration attempt. This means that if
maxIter = N, the code will attempt at most N iterations but it might exit earlier if depenetration has
been successful. Usually N = 4 gives good results.
\param[out] direction Computed MTD unit direction
\param[out] depth Penetration depth. Always positive or zero.
\param[in] geom The geometry object
\param[in] geomPose Pose for the geometry object
\param[in] heightFieldGeom The heightfield geometry
\param[in] heightFieldPose Pose for the heightfield
\param[in] maxIter Max number of iterations before returning.
\param[out] usedIter Number of depenetrations attempts performed during the call. Will not be returned if the pointer is NULL.
\return True if the MTD has successfully been computed, i.e. if objects do overlap.
@see PxGeometry PxTransform PxHeightFieldGeometry
*/
bool PxComputeHeightFieldPenetration(PxVec3& direction,
PxReal& depth,
const PxGeometry& geom,
const PxTransform& geomPose,
const PxHeightFieldGeometry& heightFieldGeom,
const PxTransform& heightFieldPose,
PxU32 maxIter,
PxU32* usedIter = NULL);
#if !PX_DOXYGEN
} // namespace physx
#endif
/** @} */
#endif