Path: blob/master/thirdparty/jolt_physics/Jolt/Physics/Body/MassProperties.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#include <Jolt/ObjectStream/SerializableObject.h>78JPH_NAMESPACE_BEGIN910class StreamIn;11class StreamOut;1213/// Describes the mass and inertia properties of a body. Used during body construction only.14class JPH_EXPORT MassProperties15{16JPH_DECLARE_SERIALIZABLE_NON_VIRTUAL(JPH_EXPORT, MassProperties)1718public:19/// Using eigendecomposition, decompose the inertia tensor into a diagonal matrix D and a right-handed rotation matrix R so that the inertia tensor is \f$R \: D \: R^{-1}\f$.20/// @see https://en.wikipedia.org/wiki/Moment_of_inertia section 'Principal axes'21/// @param outRotation The rotation matrix R22/// @param outDiagonal The diagonal of the diagonal matrix D23/// @return True if successful, false if failed24bool DecomposePrincipalMomentsOfInertia(Mat44 &outRotation, Vec3 &outDiagonal) const;2526/// Set the mass and inertia of a box with edge size inBoxSize and density inDensity27void SetMassAndInertiaOfSolidBox(Vec3Arg inBoxSize, float inDensity);2829/// Set the mass and scale the inertia tensor to match the mass30void ScaleToMass(float inMass);3132/// Calculates the size of the solid box that has an inertia tensor diagonal inInertiaDiagonal33static Vec3 sGetEquivalentSolidBoxSize(float inMass, Vec3Arg inInertiaDiagonal);3435/// Rotate the inertia by 3x3 matrix inRotation36void Rotate(Mat44Arg inRotation);3738/// Translate the inertia by a vector inTranslation39void Translate(Vec3Arg inTranslation);4041/// Scale the mass and inertia by inScale, note that elements can be < 0 to flip the shape42void Scale(Vec3Arg inScale);4344/// Saves the state of this object in binary form to inStream.45void SaveBinaryState(StreamOut &inStream) const;4647/// Restore the state of this object from inStream.48void RestoreBinaryState(StreamIn &inStream);4950/// Mass of the shape (kg)51float mMass = 0.0f;5253/// Inertia tensor of the shape (kg m^2)54Mat44 mInertia = Mat44::sZero();55};5657JPH_NAMESPACE_END585960