struct
InertiaComponent which defines the inertia of a body.
The tensor of inertia gives us how the mass is distributed in a rigid body, representing resistance to angular acceleration. A higher angular inertia requires more torque for the same acceleration.
It does not take into account child entities, even when set to update automatically.
A total angular inertia of zero is a special case, and is interpreted as infinite inertia, meaning the rigid body will not be affected by any torque.
For bodies that are symmetric in the usual x, y and z axis, the tensor is always diagonal. For a general three-dimensional body, such as any voxel shape, it may not be. However, it is always possible to find 3 mutually orthogonal axis (an x', y', z' coordinate system) for which the products of inertia are zero, and the inertia matrix takes a diagonal form. A more thourough explanation can be found here: https://ocw.mit.edu/courses/16-07-dynamics-fall-2009/dd277ec654440f4c2b5b07d6c286c3fd_
Public functions
- void setFromTensor(glm::mat3 inertiaTensor)
- Sets the inertia from the given inertia tensor.
- void setWithLocalFrame(glm::vec3 principalInertia, glm::quat principalLocalFrame)
- Sets the inertia from the principal inertia and the principal local frame.
- auto rotatedInertia(const glm::quat& rotationQuat) const -> glm::mat3
- Computes the inertia tensor with the given rotation. Can be used to transform the local inertia tensor to world space.
- auto rotatedInverseInertia(const glm::quat& rotationQuat) const -> glm::mat3
- Computes the inverse inertia tensor with the given rotation. Can be used to transform the local inverse inertia tensor to world space.
Public variables
- glm::mat3 inertia
- The inertia tensor in local space.
- glm::mat3 inverseInertia
- The inverse inertia tensor in local space.
- bool autoUpdate
- Whether to update the component automatically when the Mass or the collision shape change.
Function documentation
void cubos:: engine:: Inertia:: setFromTensor(glm::mat3 inertiaTensor)
Sets the inertia from the given inertia tensor.
Parameters | |
---|---|
inertiaTensor |
void cubos:: engine:: Inertia:: setWithLocalFrame(glm::vec3 principalInertia,
glm::quat principalLocalFrame)
Sets the inertia from the principal inertia and the principal local frame.
Parameters | |
---|---|
principalInertia | The diagonal of a diagonal inertia tensor. |
principalLocalFrame | The orientation of the principal inertial axis, for which the inertia tensor is diagonal. |
glm::mat3 cubos:: engine:: Inertia:: rotatedInertia(const glm::quat& rotationQuat) const
Computes the inertia tensor with the given rotation. Can be used to transform the local inertia tensor to world space.
Parameters | |
---|---|
rotationQuat | Quarternion with the desired rotation. |
Returns | The inertia tensor rotated. |
glm::mat3 cubos:: engine:: Inertia:: rotatedInverseInertia(const glm::quat& rotationQuat) const
Computes the inverse inertia tensor with the given rotation. Can be used to transform the local inverse inertia tensor to world space.
Parameters | |
---|---|
rotationQuat | Quarternion with the desired rotation. |
Returns | The inertia tensor rotated. |