public void Add(RigidBody rigidBody)
        {
            if (items.ContainsKey(rigidBody.Id))
            {
                Remove(items[rigidBody.Id]);
            }

            items.Add(rigidBody.Id, rigidBody);

            AddRigidBodyToWorld(rigidBody);
        }
 public void CanRotate(RigidBody rigidBody, bool state)
 {
     worldItems[rigidBody].UseUserMassProperties(JMatrix.Zero, 1.0f, true);
     worldItems[rigidBody].Restitution = 0.0f;
 }
 public void ApplyImpulse(RigidBody rigidBody, Vector3 velocity)
 {
     worldItems[rigidBody].ApplyImpulse(new JVector(velocity.X, velocity.Y, velocity.Z));
 }
        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;
            }
        }
 public void SetVelocity(RigidBody rigidBody, Vector3 velocity)
 {
     rigidBody.Velocity = velocity;
     worldItems[rigidBody].LinearVelocity = new JVector(velocity.X, velocity.Y, velocity.Z);
 }
 public void SetPosition(RigidBody rigidBody, Vector3 position)
 {
     rigidBody.Position = position;
     worldItems[rigidBody].Position = new JVector(position.X, position.Y, position.Z);
 }
        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);
        }