setupMass method
Calulates mass datas(center of gravity, mass, moment inertia, etc...).
If the parameter type is set to BODY_STATIC, the rigid body will be fixed to the space.
If the parameter adjustPosition is set to true, the shapes' relative positions and
the rigid body's position will be adjusted to the center of gravity.
type type of rigid body
adjustPosition
Implementation
void setupMass([bool adjustPosition = true]) {
mass = 0;
localInertia.setValues(0,0,0,0,0,0,0,0,0);
Matrix3 tmpM = Matrix3.identity();
Vector3 tmpV = Vector3.zero();
for(Shape? shape = shapes; shape != null; shape = shape.next){
shape.calculateMassInfo(massInfo);
double shapeMass = massInfo.mass;
tmpV.addScaled(shape.relativePosition, shapeMass);
mass += shapeMass;
rotateInertia(shape.relativeRotation, massInfo.inertia, tmpM );
localInertia.add(tmpM);
// add offset inertia
localInertia.addOffset(shapeMass, shape.relativePosition );
}
setupInertia(tmpV,adjustPosition);
}