29#ifndef PX_MASS_PROPERTIES_H
30#define PX_MASS_PROPERTIES_H
35#include "PxPhysXConfig.h"
36#include "foundation/PxMath.h"
37#include "foundation/PxMathUtils.h"
38#include "foundation/PxVec3.h"
39#include "foundation/PxMat33.h"
40#include "foundation/PxQuat.h"
41#include "foundation/PxTransform.h"
42#include "geometry/PxGeometry.h"
43#include "geometry/PxBoxGeometry.h"
44#include "geometry/PxSphereGeometry.h"
45#include "geometry/PxCapsuleGeometry.h"
46#include "geometry/PxConvexMeshGeometry.h"
47#include "geometry/PxConvexMesh.h"
48#include "geometry/PxCustomGeometry.h"
49#include "geometry/PxTriangleMeshGeometry.h"
50#include "geometry/PxTriangleMesh.h"
86 switch (geometry.getType())
88 case PxGeometryType::eSPHERE:
91 mass = (4.0f / 3.0f) * PxPi * s.radius * s.radius * s.radius;
97 case PxGeometryType::eBOX:
100 mass = b.halfExtents.x * b.halfExtents.y * b.halfExtents.z * 8.0f;
101 PxVec3 d2 = b.halfExtents.multiply(b.halfExtents);
107 case PxGeometryType::eCAPSULE:
110 PxReal r = c.radius, h = c.halfHeight;
111 mass = ((4.0f / 3.0f) * r + 2 * c.halfHeight) * PxPi * r * r;
113 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);
114 PxReal b = r*r*r * (8.0f / 15.0f) + h*r*r;
120 case PxGeometryType::eCONVEXMESH:
124 PxMat33 unscaledInertiaTensorNonCOM;
125 PxMat33 unscaledInertiaTensorCOM;
127 c.convexMesh->getMassInformation(unscaledMass, unscaledInertiaTensorNonCOM, unscaledCoM);
130 unscaledInertiaTensorCOM[0][0] = unscaledInertiaTensorNonCOM[0][0] - unscaledMass*PxReal((unscaledCoM.y*unscaledCoM.y+unscaledCoM.z*unscaledCoM.z));
131 unscaledInertiaTensorCOM[1][1] = unscaledInertiaTensorNonCOM[1][1] - unscaledMass*PxReal((unscaledCoM.z*unscaledCoM.z+unscaledCoM.x*unscaledCoM.x));
132 unscaledInertiaTensorCOM[2][2] = unscaledInertiaTensorNonCOM[2][2] - unscaledMass*PxReal((unscaledCoM.x*unscaledCoM.x+unscaledCoM.y*unscaledCoM.y));
133 unscaledInertiaTensorCOM[0][1] = unscaledInertiaTensorCOM[1][0] = (unscaledInertiaTensorNonCOM[0][1] + unscaledMass*PxReal(unscaledCoM.x*unscaledCoM.y));
134 unscaledInertiaTensorCOM[1][2] = unscaledInertiaTensorCOM[2][1] = (unscaledInertiaTensorNonCOM[1][2] + unscaledMass*PxReal(unscaledCoM.y*unscaledCoM.z));
135 unscaledInertiaTensorCOM[0][2] = unscaledInertiaTensorCOM[2][0] = (unscaledInertiaTensorNonCOM[0][2] + unscaledMass*PxReal(unscaledCoM.z*unscaledCoM.x));
138 mass = unscaledMass * s.scale.x * s.scale.y * s.scale.z;
144 case PxGeometryType::eCUSTOM:
147 static_cast<const PxCustomGeometry&
>(geometry).callbacks->computeMassProperties(geometry, *
this);
151 case PxGeometryType::eTRIANGLEMESH:
156 PxMat33 unscaledInertiaTensorNonCOM;
157 PxMat33 unscaledInertiaTensorCOM;
162 unscaledInertiaTensorCOM[0][0] = unscaledInertiaTensorNonCOM[0][0] - unscaledMass * PxReal((unscaledCoM.y*unscaledCoM.y + unscaledCoM.z*unscaledCoM.z));
163 unscaledInertiaTensorCOM[1][1] = unscaledInertiaTensorNonCOM[1][1] - unscaledMass * PxReal((unscaledCoM.z*unscaledCoM.z + unscaledCoM.x*unscaledCoM.x));
164 unscaledInertiaTensorCOM[2][2] = unscaledInertiaTensorNonCOM[2][2] - unscaledMass * PxReal((unscaledCoM.x*unscaledCoM.x + unscaledCoM.y*unscaledCoM.y));
165 unscaledInertiaTensorCOM[0][1] = unscaledInertiaTensorCOM[1][0] = (unscaledInertiaTensorNonCOM[0][1] + unscaledMass * PxReal(unscaledCoM.x*unscaledCoM.y));
166 unscaledInertiaTensorCOM[1][2] = unscaledInertiaTensorCOM[2][1] = (unscaledInertiaTensorNonCOM[1][2] + unscaledMass * PxReal(unscaledCoM.y*unscaledCoM.z));
167 unscaledInertiaTensorCOM[0][2] = unscaledInertiaTensorCOM[2][0] = (unscaledInertiaTensorNonCOM[0][2] + unscaledMass * PxReal(unscaledCoM.z*unscaledCoM.x));
170 mass = unscaledMass * s.scale.x * s.scale.y * s.scale.z;
227 PxVec3 diagT = PxDiagonalize(inertia, massFrame);
251 PxMat33 translatedIT = s.getTranspose() * s *
mass + inertia;
287 PX_ASSERT(scaleRotation.
isUnit());
288 PX_ASSERT(scale.isFinite());
291 PxVec3 diagonal(localInertiaT[0][0], localInertiaT[1][1], localInertiaT[2][2]);
296 PxReal xx = scaledxyz2.y + scaledxyz2.z,
297 yy = scaledxyz2.z + scaledxyz2.x,
298 zz = scaledxyz2.x + scaledxyz2.y;
300 PxReal xy = localInertiaT[0][1] * scale.x * scale.y,
301 xz = localInertiaT[0][2] * scale.x * scale.z,
302 yz = localInertiaT[1][2] * scale.y * scale.z;
308 PxMat33 scaledIT =
rotateInertia(scaledInertia * (scale.x * scale.y * scale.z), scaleRotation.getConjugate());
323 PxReal combinedMass = 0.0f;
327 for(PxU32 i = 0; i < count; i++)
333 combinedMass += props[i].
mass;
335 combinedCoM += comTm * props[i].
mass;
338 if(combinedMass > 0.f)
339 combinedCoM /= combinedMass;
341 for(PxU32 i = 0; i < count; i++)
347 PX_ASSERT(combinedInertiaT.column0.
isFinite() && combinedInertiaT.column1.
isFinite() && combinedInertiaT.column2.
isFinite());
Class representing the geometry of a box.
Definition PxBoxGeometry.h:49
Class representing the geometry of a capsule.
Definition PxCapsuleGeometry.h:54
Convex mesh geometry class.
Definition PxConvexMeshGeometry.h:79
Custom geometry class. This class allows user to create custom geometries by providing a set of virtu...
Definition PxCustomGeometry.h:52
A geometry object.
Definition PxGeometry.h:79
Utility class to compute and manipulate mass and inertia tensor properties.
Definition PxMassProperties.h:65
PxVec3 centerOfMass
The center of mass of the object.
Definition PxMassProperties.h:356
static PX_FORCE_INLINE PxMat33 rotateInertia(const PxMat33 &inertia, const PxQuat &q)
Rotate an inertia tensor around the center of mass.
Definition PxMassProperties.h:264
static PX_FORCE_INLINE PxMat33 translateInertia(const PxMat33 &inertia, const PxReal mass, const PxVec3 &t)
Translate an inertia tensor using the parallel axis theorem.
Definition PxMassProperties.h:241
PX_FORCE_INLINE PxMassProperties operator*(const PxReal scale) const
Scale mass properties.
Definition PxMassProperties.h:193
PxReal mass
The mass of the object.
Definition PxMassProperties.h:357
PX_FORCE_INLINE PxMassProperties()
Default constructor.
Definition PxMassProperties.h:70
PxMassProperties(const PxGeometry &geometry)
Compute mass properties based on a provided geometry structure.
Definition PxMassProperties.h:84
static PX_FORCE_INLINE PxVec3 getMassSpaceInertia(const PxMat33 &inertia, PxQuat &massFrame)
Get the entries of the diagonalized inertia tensor and the corresponding reference rotation.
Definition PxMassProperties.h:223
static PxMassProperties sum(const PxMassProperties *props, const PxTransform *transforms, const PxU32 count)
Sum up individual mass properties.
Definition PxMassProperties.h:321
PxMat33 inertiaTensor
The inertia tensor of the object.
Definition PxMassProperties.h:355
PX_FORCE_INLINE void translate(const PxVec3 &t)
Translate the center of mass by a given vector and adjust the inertia tensor accordingly.
Definition PxMassProperties.h:205
PX_FORCE_INLINE PxMassProperties(const PxReal m, const PxMat33 &inertiaT, const PxVec3 &com)
Construct from individual elements.
Definition PxMassProperties.h:75
static PxMat33 scaleInertia(const PxMat33 &inertia, const PxQuat &scaleRotation, const PxVec3 &scale)
Non-uniform scaling of the inertia tensor.
Definition PxMassProperties.h:284
PX_CUDA_CALLABLE static PX_INLINE const PxMat33T createDiagonal(const PxVec3T< float > &d)
Construct from diagonal, off-diagonals are zero.
Definition PxMat33.h:186
3x3 matrix class
Definition PxMat33.h:91
PX_CUDA_CALLABLE PX_FORCE_INLINE const PxMat33 getTranspose() const
Get transposed matrix.
Definition PxMat33.h:190
A class expressing a nonuniform scaling transformation.
Definition PxMeshScale.h:69
This is a quaternion class. For more information on quaternion mathematics consult a mathematics sour...
Definition PxQuat.h:50
PX_CUDA_CALLABLE bool isUnit() const
returns true if finite and magnitude is close to unit
Definition PxQuat.h:132
PX_CUDA_CALLABLE bool isFinite() const
returns true if all elements are finite (not NAN or INF, etc.)
Definition PxQuat.h:124
A class representing the geometry of a sphere.
Definition PxSphereGeometry.h:48
Triangle mesh geometry class.
Definition PxTriangleMeshGeometry.h:81
PxTriangleMesh * triangleMesh
A reference to the mesh object.
Definition PxTriangleMeshGeometry.h:138
PxMeshScale scale
The scaling transformation.
Definition PxTriangleMeshGeometry.h:135
virtual void getMassInformation(PxReal &mass, PxMat33 &localInertia, PxVec3 &localCenterOfMass) const =0
Returns the mass properties of the mesh assuming unit density.
3 Element vector class.
Definition PxVec3.h:50
PX_CUDA_CALLABLE PX_FORCE_INLINE float dot(const PxVec3 &v) const
returns the scalar product of this and other.
Definition PxVec3.h:276
PX_CUDA_CALLABLE PX_FORCE_INLINE PxVec3 multiply(const PxVec3 &a) const
a[i] * b[i], for all i.
Definition PxVec3.h:336
PX_CUDA_CALLABLE PX_INLINE bool isFinite() const
returns true if all 3 elems of the vector are finite (not NAN or INF, etc.)
Definition PxVec3.h:156
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_CUDA_CALLABLE PX_FORCE_INLINE bool PxIsFinite(float f)
returns true if the passed number is a finite floating point number as opposed to INF,...
Definition PxMath.h:326