Class MassProperties

java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
com.github.stephengold.joltjni.MassProperties
All Implemented Interfaces:
ConstJoltPhysicsObject, ConstMassProperties, AutoCloseable, Comparable<JoltPhysicsObject>

public final class MassProperties extends JoltPhysicsObject implements ConstMassProperties
The mass and inertial tensor of a Body. Used only during construction.
  • Constructor Details

    • MassProperties

      public MassProperties()
      Instantiate default properties.
  • Method Details

    • rotate

      public void rotate(Mat44Arg rotation)
      Rotate the inertia by the specified 3x3 matrix.
      Parameters:
      rotation - the rotation to apply (not null, unaffected)
    • scale

      public void scale(Vec3Arg scaleFactors)
      Scale the mass and inertia by the specified factors. Note that factors can be <0 to flip the shape.
      Parameters:
      scaleFactors - the desired scaling (not null unaffected)
    • scaleToMass

      public void scaleToMass(float mass)
      Set the mass and scale the inertia tensor to match.
      Parameters:
      mass - the desired mass (in kilograms, ≥0)
    • setInertia

      public MassProperties setInertia(Mat44Arg inertia)
      Alter the inertia tensor. (native attribute: mInertia)
      Parameters:
      inertia - the desired value (not null, unaffected, default=zero)
      Returns:
      the modified properties, for chaining
    • setMass

      public MassProperties setMass(float mass)
      Alter the mass. (native attribute: mMass)
      Parameters:
      mass - the desired mass (in kilograms, ≥0, default=0)
      Returns:
      the modified properties, for chaining
    • setMassAndInertiaOfSolidBox

      public void setMassAndInertiaOfSolidBox(Vec3Arg boxSize, float density)
      Alter the mass and inertia to that of a box with the specified dimensions and uniform density.
      Parameters:
      boxSize - the edge lengths of the box (not null, unaffected)
      density - the density to use
    • translate

      public void translate(Vec3Arg offset)
      Translate the inertia by the specified offset.
      Parameters:
      offset - the amount of translation (not null, unaffected)
    • decomposePrincipalMomentsOfInertia

      public boolean decomposePrincipalMomentsOfInertia(Mat44 storeRotation, Vec3 storeDiagonal)
      Decompose the inertia tensor into a diagonal matrix and a right-handed rotation matrix. The properties are unaffected.
      Specified by:
      decomposePrincipalMomentsOfInertia in interface ConstMassProperties
      Parameters:
      storeRotation - storage for the rotation matrix (not null, modified)
      storeDiagonal - storage for the diagonal matrix (not null, modified)
      Returns:
      true if successful, otherwise false
    • getInertia

      public Mat44 getInertia()
      Copy the inertia tensor. The properties are unaffected. (native attribute: mInertia)
      Specified by:
      getInertia in interface ConstMassProperties
      Returns:
      a new matrix (in kilogram.meters squared)
    • getMass

      public float getMass()
      Return the mass. The properties are unaffected. (native attribute: mMass)
      Specified by:
      getMass in interface ConstMassProperties
      Returns:
      the mass (in kilograms, ≥0)
    • toString

      public String toString()
      Return a string representation of the properties object, which is unaffected.
      Overrides:
      toString in class JoltPhysicsObject
      Returns:
      the string representation (not null, not empty)