public void CalculateMassProperties() { CollisionSkin skin = new CollisionSkin(); #region Mass Variables Vector3 centerOfMass; float mass; Matrix inertiaTensor; Matrix inertiaTensorCoM; #endregion for (int i = 0; i < MaterialPrimitivePairs.Count; i++) { if (this.MaterialPrimitivePairs[i].MaterialID == (int)MaterialTable.MaterialID.UserDefined) { skin.AddPrimitive(this.MaterialPrimitivePairs[i].Primitive, this.MaterialPrimitivePairs[i].MaterialID); } else { skin.AddPrimitive(this.MaterialPrimitivePairs[i].Primitive, this.MaterialPrimitivePairs[i].MaterialProperties); } } skin.GetMassProperties(PrimitiveProperties, out mass, out centerOfMass, out inertiaTensor, out inertiaTensorCoM); skin.RemoveAllPrimitives(); _massProperties.Mass = mass; _massProperties.CenterOfMass = centerOfMass; _massProperties.InertiaTensor = inertiaTensor; _massProperties.InertiaTensorCoM = inertiaTensorCoM; }
private void Initialize(Primitive primitive, MaterialProperties materialProperties, PrimitiveProperties primitiveProperties, bool enableBody) { float mass; Vector3 centerOfMass; Matrix inertiaTensor; Matrix inertiaTensorCoM; // Set variables ... _primitive = primitive; _primitiveProperties = primitiveProperties; _materialProperties = materialProperties; // Create and link Body and CollisionSkin. _body = new Body(); _skin = new CollisionSkin(_body); _body.CollisionSkin = _skin; // Add primitive to CollisionSkin. _skin.AddPrimitive(primitive, materialProperties); // Set body properties. _skin.GetMassProperties(primitiveProperties, out mass, out centerOfMass, out inertiaTensor, out inertiaTensorCoM); _body.BodyInertia = inertiaTensorCoM; _body.Mass = mass; // Sync CollisionSkin and Body. _body.MoveTo(Vector3.Zero, Matrix.Identity); _skin.ApplyLocalTransform(new Transform(-centerOfMass, Matrix.Identity)); // Enable Body. if (enableBody) { _body.EnableBody(); } else { _body.DisableBody(); } }