24 #ifndef PXR_USD_USD_MASS_PROPERTIES_H
25 #define PXR_USD_USD_MASS_PROPERTIES_H
41 float v[3] = { 0, 0, 0 };
43 return GfQuatf(c, v[0], v[1], v[2]);
48 return (i + 1 + (i >> 1)) & 3;
54 const uint32_t MAX_ITERS = 24;
59 for (uint32_t i = 0; i < MAX_ITERS; i++)
64 float d0 = fabs(d[1][2]), d1 = fabs(d[0][2]), d2 = fabs(d[0][1]);
65 uint32_t
a = uint32_t(d0 > d1 && d0 > d2 ? 0 : d1 > d2 ? 1 : 2);
70 if (d[a1][a2] == 0.0
f || fabs(d[a1][a1] - d[a2][a2]) > 2e6 * fabs(2.0 * d[a1][a2]))
73 float w = (d[a1][a1] - d[a2][a2]) / (2.0
f * d[a1][a2]);
81 float t = 1 / (absw +
sqrt(w * w + 1));
82 float h = 1 /
sqrt(t * t + 1);
87 q = (q *
r).GetNormalized();
110 _inertiaTensor[0][0] = 1.0;
111 _inertiaTensor[1][1] = 1.0;
112 _inertiaTensor[2][2] = 1.0;
117 : _inertiaTensor(inertiaT), _centerOfMass(com), _mass(m)
183 float combinedMass = 0.0f;
187 for (uint32_t i = 0; i <
count; i++)
189 combinedMass += props[i]._mass;
191 combinedCoM += comTm * props[i]._mass;
194 if (combinedMass > 0.
f)
195 combinedCoM /= combinedMass;
197 for (uint32_t i = 0; i <
count; i++)
202 props[i]._mass, combinedCoM - comTm);
212 return _inertiaTensor;
219 _inertiaTensor = inTensor;
226 return _centerOfMass;
PXR_NAMESPACE_OPEN_SCOPE GfQuatf UsdPhysicsIndexedRotation(uint32_t axis, float s, float c)
static USDPHYSICS_API UsdPhysicsMassProperties Sum(const UsdPhysicsMassProperties *props, const GfMatrix4f *transforms, const uint32_t count)
vfloat4 sqrt(const vfloat4 &a)
static USDPHYSICS_API GfMatrix3f RotateInertia(const GfMatrix3f &inertia, const GfQuatf &q)
GLboolean GLboolean GLboolean GLboolean a
static USDPHYSICS_API GfVec3f GetMassSpaceInertia(const GfMatrix3f &inertia, GfQuatf &massFrame)
GA_API const UT_StringHolder com
GF_API GfMatrix3f GetTranspose() const
Returns the transpose of the matrix.
GLdouble GLdouble GLdouble q
GfVec3f UsdPhysicsDiagonalize(const GfMatrix3f &m, GfQuatf &massFrame)
GA_API const UT_StringHolder scale
void SetMass(float inMass)
const GfVec3f & GetCenterOfMass() const
USDPHYSICS_API void Translate(const GfVec3f &t)
GfVec3d Transform(const GfVec3d &vec) const
uint32_t UsdPhysicsGetNextIndex3(uint32_t i)
GfVec3f GetColumn(int i) const
Gets a column of the matrix as a Vec3.
USDPHYSICS_API UsdPhysicsMassProperties operator*(const float scale) const
USDPHYSICS_API UsdPhysicsMassProperties(const float m, const GfMatrix3f &inertiaT, const GfVec3f &com)
Construct from individual elements.
GA_API const UT_StringHolder mass
GLfloat GLfloat GLfloat GLfloat h
void SetInertiaTensor(const GfMatrix3f &inTensor)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
#define PXR_NAMESPACE_CLOSE_SCOPE
const GfMatrix3f & GetInertiaTensor() const
GLubyte GLubyte GLubyte GLubyte w
static USDPHYSICS_API GfMatrix3f TranslateInertia(const GfMatrix3f &inertia, const float mass, const GfVec3f &t)
void SetColumn(int i, const GfVec3f &v)
Sets a column of the matrix from a Vec3.
USDPHYSICS_API UsdPhysicsMassProperties()
Construct a MassProperties.
GLenum GLuint GLsizei const GLenum * props