Ejemplo n.º 1
0
        public void Add(RigidBody rigidBody)
        {
            if (items.ContainsKey(rigidBody.Id))
            {
                Remove(items[rigidBody.Id]);
            }

            items.Add(rigidBody.Id, rigidBody);

            AddRigidBodyToWorld(rigidBody);
        }
Ejemplo n.º 2
0
 public void CanRotate(RigidBody rigidBody, bool state)
 {
     worldItems[rigidBody].UseUserMassProperties(JMatrix.Zero, 1.0f, true);
     worldItems[rigidBody].Restitution = 0.0f;
 }
Ejemplo n.º 3
0
 public void ApplyImpulse(RigidBody rigidBody, Vector3 velocity)
 {
     worldItems[rigidBody].ApplyImpulse(new JVector(velocity.X, velocity.Y, velocity.Z));
 }
Ejemplo n.º 4
0
        private void AddRigidBodyToWorld(RigidBody item)
        {
            // Initialize the shape
            Jitter.Collision.Shapes.Shape shape = null;

            // Box shape
            if (item.Shape is BoxShape)
            {
                var shapeInfo = item.Shape as BoxShape;
                shape = new Jitter.Collision.Shapes.BoxShape(shapeInfo.Size.X, shapeInfo.Size.Y, shapeInfo.Size.Z);
            }
            // Capsule shape
            else if (item.Shape is CapsuleShape)
            {
                var shapeInfo = item.Shape as CapsuleShape;
                shape = new Jitter.Collision.Shapes.CapsuleShape(shapeInfo.Length, shapeInfo.Radius);
            }
            // Default shape
            else
            {
                throw new NotImplementedException("The specified shape has not been implemented");
            }

            // Initialize the body with the specified shape
            var body = new Jitter.Dynamics.RigidBody(shape)
            {
                Position = new JVector(item.Position.X, item.Position.Y, item.Position.Z),
                IsStatic = item.IsStatic,
                DynamicFriction = 0,
                Mass = item.Mass
            };

            // Add the body to the world
            world.AddBody(body);

            // Map the item to the world item
            worldItems.Add(item, body);

            // TODO: DEBUG code only
            if (item.Id == "Player")
            {
                var constraint = new CharacterController(world, body);
                world.AddConstraint(constraint);
                item.Tag = constraint;
            }
        }
Ejemplo n.º 5
0
 public void SetVelocity(RigidBody rigidBody, Vector3 velocity)
 {
     rigidBody.Velocity = velocity;
     worldItems[rigidBody].LinearVelocity = new JVector(velocity.X, velocity.Y, velocity.Z);
 }
Ejemplo n.º 6
0
 public void SetPosition(RigidBody rigidBody, Vector3 position)
 {
     rigidBody.Position = position;
     worldItems[rigidBody].Position = new JVector(position.X, position.Y, position.Z);
 }
Ejemplo n.º 7
0
        public void Remove(RigidBody rigidBody)
        {
            // Remove the item from the world
            world.RemoveBody(worldItems[rigidBody]);
            worldItems.Remove(rigidBody);

            // Remove the item from the items
            items.Remove(rigidBody.Id);
        }