//------------------------------------Private Functions------------------------------------- private Matrix4x4 CalculateInertiaTensor() { // Calculating the moment of inertia of the body. Vector3 momentOfInertia = Vector3.one; switch (pCollider.pType) { case ColliderType.Sphere: momentOfInertia *= PSI_PhysicsUtils.MomentOfInertiaOfSphere(Mass, ((PSI_Collider_Sphere)pCollider).pRadius); break; case ColliderType.Box: momentOfInertia = PSI_PhysicsUtils.MomentOfInertiaOfBox(Mass, ((PSI_Collider_Box)pCollider).pSize); break; default: return(Matrix4x4.identity); } // Using the moment of inertia to construct the inertia tensor matrix. Matrix4x4 inertiaTensor = new Matrix4x4(); inertiaTensor.m00 = momentOfInertia.x; inertiaTensor.m11 = momentOfInertia.y; inertiaTensor.m22 = momentOfInertia.z; inertiaTensor.m33 = 1f; return(inertiaTensor); }
private Vector3 CalculateAngularAcceleration(Vector3 torque) { // Geting the moment of inertia of the body and using to calculate the accelerating due to torque. switch (pCollider.pType) { case ColliderType.Sphere: return((Mathf.Rad2Deg * torque) * PSI_PhysicsUtils.MomentOfInertiaOfSphere(Mass, ((PSI_Collider_Sphere)pCollider).pRadius)); case ColliderType.Box: Vector3 angAcc = (Mathf.Rad2Deg * torque); Vector3 momentOfInertia = PSI_PhysicsUtils.MomentOfInertiaOfBox(Mass, ((PSI_Collider_Box)pCollider).pSize); angAcc.x *= momentOfInertia.x; angAcc.y *= momentOfInertia.y; angAcc.z *= momentOfInertia.z; return(angAcc); default: return(Vector3.zero); } }