private void SetPhysics() { if (Mass == 0f) { if (!Bounding.Equals(CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_NONE)) { PhysicsId = Physics.CreateStaticMeshBody(mesh); } } else { PhysicsId = Physics.CreateMeshBody(Mass, mesh, Bounding, true); } SetPhysicsMaterial(); }
public void UpdatePhysics() { if (mesh == null) { return; } if (PhysicsId != -1) { core.Physics.DestroyBody(PhysicsId, false); } if (mass == 0f) { if (!Bounding.Equals(Helpers.BodyBounding.None)) { PhysicsId = core.Physics.CreateStaticMeshBody(mesh); } else { PhysicsId = -1; return; } } else { CONST_TV_PHYSICSBODY_BOUNDING bounding = CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_CONVEXHULL; switch (Bounding) { case Helpers.BodyBounding.Box: bounding = CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_BOX; break; case Helpers.BodyBounding.Convexhull: bounding = CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_CONVEXHULL; break; case Helpers.BodyBounding.Cylinder: bounding = CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_CYLINDER; break; case Helpers.BodyBounding.None: bounding = CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_NONE; break; case Helpers.BodyBounding.Sphere: bounding = CONST_TV_PHYSICSBODY_BOUNDING.TV_BODY_SPHERE; break; } PhysicsId = core.Physics.CreateMeshBody(mass, mesh, bounding, true); } // Set material from selected material template switch (material) { case Materials.Custom: //Do nothing break; case Materials.Wood: staticFriction = 0.5f; kineticFriction = 0.2f; softness = 0.1f; bounciness = 0.1f; break; case Materials.Metal: staticFriction = 1f; kineticFriction = 0.7f; softness = 0.1f; bounciness = 0.1f; break; case Materials.Concrete: staticFriction = 0.7f; kineticFriction = 0.4f; softness = 0.1f; bounciness = 0.1f; break; } // Create material if (materialIdx == -1) { //materialIdx = Core.Physics.CreateMaterialGroup(Guid.NewGuid().ToString()); } if (PhysicsId != -1) { //Core.Physics.SetMaterialInteractionFriction(materialIdx, -1, staticFriction, kineticFriction); //Core.Physics.SetMaterialInteractionSoftness(materialIdx, -1, softness); //Core.Physics.SetMaterialInteractionBounciness(materialIdx, -1, bounciness); //Core.Physics.SetBodyMaterialGroup(PhysicsId, materialIdx); Core.Physics.SetAutoFreeze(PhysicsId, false); Core.Physics.SetBodyPosition(PhysicsId, Position.X, Position.Y, Position.Z); Core.Physics.SetBodyRotation(PhysicsId, Rotation.X, Rotation.Y, Rotation.Z); Core.Physics.SetDamping(PhysicsId, 0f, new TV_3DVECTOR(0f, 0f, 0f)); } }