diff options
| author | sschirm <[email protected]> | 2016-12-23 14:20:36 +0100 |
|---|---|---|
| committer | sschirm <[email protected]> | 2016-12-23 14:56:17 +0100 |
| commit | ef6937e69e8ee3f409cf9d460d5ad300a65d5924 (patch) | |
| tree | 710426e8daa605551ce3f34b581897011101c30f /PhysX_3.4/Include/extensions/PxMassProperties.h | |
| parent | Initial commit: (diff) | |
| download | physx-3.4-ef6937e69e8ee3f409cf9d460d5ad300a65d5924.tar.xz physx-3.4-ef6937e69e8ee3f409cf9d460d5ad300a65d5924.zip | |
PhysX 3.4 / APEX 1.4 release candidate @21506124
Diffstat (limited to 'PhysX_3.4/Include/extensions/PxMassProperties.h')
| -rw-r--r-- | PhysX_3.4/Include/extensions/PxMassProperties.h | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/PhysX_3.4/Include/extensions/PxMassProperties.h b/PhysX_3.4/Include/extensions/PxMassProperties.h index db978b39..87f823b6 100644 --- a/PhysX_3.4/Include/extensions/PxMassProperties.h +++ b/PhysX_3.4/Include/extensions/PxMassProperties.h @@ -98,7 +98,7 @@ public: 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 * 2.0f / 3.0f); + 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; @@ -120,14 +120,23 @@ public: { const PxConvexMeshGeometry& c = static_cast<const PxConvexMeshGeometry&>(geometry); PxVec3 unscaledCoM; - PxMat33 unscaledInertiaTensor; + PxMat33 unscaledInertiaTensorNonCOM; // inertia tensor of convex mesh in mesh local space + PxMat33 unscaledInertiaTensorCOM; PxReal unscaledMass; - c.convexMesh->getMassInformation(unscaledMass, unscaledInertiaTensor, unscaledCoM); + 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(unscaledInertiaTensor, s.rotation, s.scale); + inertiaTensor = scaleInertia(unscaledInertiaTensorCOM, s.rotation, s.scale); } break; |