/// <summary> /// Randomizes the orientation of a die /// </summary> /// <param name="die">Die body</param> public void RandomizeDieOrientation(RigidBody die) { float xRot = -MathHelper.Pi + ((float)random.NextDouble() * MathHelper.TwoPi); float yRot = -MathHelper.Pi + ((float)random.NextDouble() * MathHelper.TwoPi); float zRot = -MathHelper.Pi + ((float)random.NextDouble() * MathHelper.TwoPi); die.Orientation = JMatrix.CreateRotationX(xRot) * JMatrix.CreateRotationY(yRot) * JMatrix.CreateRotationZ(zRot); }
void IConstructable.Construct(IDictionary <string, string> param) { var type = param["type"]; switch (type) { case "trimesh": var physData = ResourceFactory.LoadAsset <PhysicsData>(param["physData"]); Shape shape = new TriangleMeshShape(physData.Octree); Body = new RigidBody(shape) { Material = { Restitution = 0f, KineticFriction = 0f } }; break; case "hull": physData = ResourceFactory.LoadAsset <PhysicsData>(param["physData"]); shape = new ConvexHullShape(physData.Vertices); Body = new RigidBody(shape); break; case "sphere": shape = new SphereShape(float.Parse(param["radius"], CultureInfo.InvariantCulture)); Body = new RigidBody(shape); break; case "box": var d = param["size"].ConvertToVector(); var offset = param.Get("offset", "0;0;0").ConvertToVector(); shape = new BoxShape(2.0f * d.ToJVector()); Body = new RigidBody(shape) { Position = offset.ToJVector() }; break; case "capsule": var height = float.Parse(param["height"], CultureInfo.InvariantCulture); var radius = float.Parse(param["radius"], CultureInfo.InvariantCulture); shape = new CapsuleShape(height, radius); Body = new RigidBody(shape) { Position = JVector.Backward * (0.5f * height + radius), Orientation = JMatrix.CreateRotationX(MathHelper.PiOver2) }; break; default: throw new Exception("Unknown shape: " + type); } Body.IsStatic = Convert.ToBoolean(param.Get("static", "false")); Body.Material.KineticFriction = 0.5f; Body.Material.StaticFriction = 0.5f; Body.Material.Restitution = 0.5f; }
private JMatrix GetOrientation() { switch (Axis) { case AxisAlignment.PositiveX: case AxisAlignment.NegativeX: return(JMatrix.CreateRotationZ(JMath.PiOver2)); case AxisAlignment.PositiveY: case AxisAlignment.NegativeY: return(JMatrix.Identity); case AxisAlignment.PositiveZ: case AxisAlignment.NegativeZ: return(JMatrix.CreateRotationX(JMath.PiOver2)); default: throw new ArgumentOutOfRangeException(); } }
public override void Draw() { G.PushMatrix(); G.SetTransform(Body.Position, Body.Orientation); G.Translate(0, -0.3f, -0.2f); G.Scale(0.032f, 0.032f, 0.032f); sc.Draw(); G.PopMatrix(); for (int i = 0; i < ((DefaultCar)Body).Wheels.Length; i++) { G.PushMatrix(); Wheel wheel = ((DefaultCar)Body).Wheels[i]; G.SetTransform(wheel.GetWorldPosition(), Body.Orientation); G.SetTransform(JVector.Zero, JMatrix.CreateRotationY(wheel.SteerAngle * (float)Math.PI / 180)); G.SetTransform(JVector.Zero, JMatrix.CreateRotationX(-wheel.WheelRotation * (float)Math.PI / 180)); G.Scale(whRadius * 1.3f, whRadius * 1.3f, whRadius * 1.3f); wc.Draw(); G.PopMatrix(); } }
public void InitBody(ref RigidBody body, TransformComponent transform, int entity) { body.Shape = new BoxShape(0.2f, 0.2f, 0.2f); body.Position = new JVector(transform.X, transform.Y, transform.Z); body.Orientation = JMatrix.CreateRotationX(transform.RotationX) * JMatrix.CreateRotationY(transform.RotationY) * JMatrix.CreateRotationZ(transform.RotationZ); body.SetMassProperties(); body.Update(); body.IsActive = true; // TODO body.IsStatic = !OwnerApp.EntityManager.HasComponent <MovableComponent>(entity); body.Mass = 1.0f; // TODO body.Material = new Material() { Restitution = 0.2f, StaticFriction = 0.8f, KineticFriction = 0.8f }; // TODO _world.AddBody(body); }