RevoluteJoint wandHinge; // Moves the wand

        #endregion Fields

        #region Constructors

        public Vehicle(MemoryBank memBank, float distance)
        {
            // Figure out the positions of the vehicle and it's sliderBase
            Vector3 position = new Vector3(memBank.Position.X, memBank.Position.Y, memBank.Position.Z + 10);
            Vector3 motorPos = new Vector3(position.X - memBank.Length - distance, position.Y, position.Z);
            byteDist = memBank.ByteDistance;
            bytes = memBank.NumberOfBytes;

            wandGoal = sliderGoal = false;
            delay = 0;

            // Build the main vechicle
            chassis = XNAGame.Instance.createVehicle(position);

            // Build the slider, and attatch
            sliderBase = new Box(motorPos, 1, 1, 1);
            slider = new PrismaticJoint(sliderBase, chassis.body, sliderBase.Position, Vector3.UnitX, chassis.body.Position);
            XNAGame.Instance.space.Add(slider);
            XNAGame.Instance.space.Add(sliderBase);

            // Change slider settings
            slider.Motor.Settings.Mode = MotorMode.Servomechanism;
            slider.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;
            slider.Motor.Settings.Servo.MaxCorrectiveVelocity = 200;
            slider.Motor.Settings.Servo.BaseCorrectiveSpeed = 120;

            // Create the wand
            setUpWand(position);
        }
 BepuEntity fireBall()
 {
     BepuEntity ball = new BepuEntity();
     ball.modelName = "sphere";
     float size = 1;
     ball.localTransform = Matrix.CreateScale(new Vector3(size, size, size));
     ball.body = new Sphere(Camera.Position + (Camera.Look * 8), size, size * 10);
     ball.diffuse = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
     space.Add(ball.body);
     ball.LoadContent();
     ball.configureEvents();
     ball.body.ApplyImpulse(Camera.Position, Camera.Look * 500);
     children.Add(ball);
     return ball;
 }
 BepuEntity createWheel(Vector3 position, float wheelWidth, float wheelRadius)
 {
     BepuEntity wheelEntity = new BepuEntity();
     wheelEntity.modelName = "cyl";
     wheelEntity.LoadContent();
     wheelEntity.body = new Cylinder(position, wheelWidth, wheelRadius, wheelRadius);
     wheelEntity.localTransform = Matrix.CreateScale(wheelRadius, wheelWidth, wheelRadius);
     wheelEntity.body.Orientation = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.PiOver2);
     wheelEntity.diffuse = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
     space.Add(wheelEntity.body);
     children.Add(wheelEntity);
     return wheelEntity;
 }
        void createSteerableVehicle(Vector3 position)
        {
            float width = 15;
            float height = 2;
            float length = 5;
            float wheelWidth = 1;
            float wheelRadius = 2;

            BepuEntity chassis = createBox(position, width, height, length);
            chassis.LoadContent();
            chassis.body.Mass = 100;

            RevoluteMotor motor;

            BepuEntity wheel;
            RevoluteJoint joint;
            SwivelHingeJoint steerJoint;
            Vector3 wheelPos = new Vector3(position.X - (width / 2) + wheelRadius, position.Y, position.Z - (length / 2));
            wheel = createWheel(wheelPos, wheelWidth, wheelRadius);
            motor = new RevoluteMotor(chassis.body, wheel.body, Vector3.UnitZ);
            motor.Settings.VelocityMotor.GoalVelocity = -6;
            motor.IsActive = true;
            wheelPos = new Vector3(position.X - (width / 2) + wheelRadius, position.Y, position.Z - (length / 2) - (wheelWidth * 2));
            space.Add(motor);

            joint = new RevoluteJoint(chassis.body, wheel.body, wheel.body.Position, new Vector3(0, 0, -1));
            space.Add(joint);

            wheel = createWheel(new Vector3(position.X - (width / 2) + wheelRadius, position.Y, position.Z + (length / 2) + wheelWidth), wheelWidth, wheelRadius);
            joint = new RevoluteJoint(chassis.body, wheel.body, wheel.body.Position, new Vector3(0, 0, -1));
            space.Add(joint);

            wheel = createWheel(new Vector3(position.X + (width / 2) - wheelRadius, position.Y, position.Z - (length / 2) - wheelWidth), wheelWidth, wheelRadius);
            motor = new RevoluteMotor(chassis.body, wheel.body, Vector3.UnitZ);
            motor.Settings.VelocityMotor.GoalVelocity = -6;
            motor.IsActive = true;
            joint = new RevoluteJoint(chassis.body, wheel.body, wheel.body.Position, new Vector3(0, 0, -1));
            space.Add(joint);
            space.Add(motor);

            wheel = createWheel(new Vector3(position.X + (width / 2) - wheelRadius, position.Y, position.Z + (length / 2) + wheelWidth), wheelWidth, wheelRadius);
            joint = new RevoluteJoint(chassis.body, wheel.body, wheel.body.Position, new Vector3(0, 0, -1));
            space.Add(joint);

            BepuEntity pole = new BepuEntity();
            pole.modelName = "cube";
            pole.body = new Box(new Vector3(0, position.Y + 12, 0), 2, 18, 2, 1); // I have no idea whatsoever why the height has to be one, but it won't work otherwise...
            pole.localTransform = Matrix.CreateScale(new Vector3(2, 18, 2));
            //pole.body.CollisionInformation.LocalPosition = new Vector3(0, 20, 0);
            pole.configureEvents();

            joint = new RevoluteJoint(chassis.body, pole.body, chassis.body.Position, new Vector3(-1, 0, 0));

            joint.Limit.IsActive = true;
            joint.Limit.MaximumAngle = MathHelper.ToRadians(45.0f);
            joint.Limit.MinimumAngle = MathHelper.ToRadians(-45.0f);
            joint.Motor.Settings.Mode = MotorMode.Servomechanism;
            joint.Motor.Settings.Servo.Goal = MathHelper.ToRadians(-45.0f);
            joint.Motor.Settings.Servo.BaseCorrectiveSpeed = 8f;
            joint.Motor.Settings.MaximumForce = 2;
            joint.Motor.IsActive = true;

            children.Add(pole);
            space.Add(pole.body);
            space.Add(joint);
        }
 BepuEntity createFromMesh(Vector3 position, string mesh, float scale)
 {
     BepuEntity entity = new BepuEntity();
     entity.modelName = mesh;
     entity.LoadContent();
     Vector3[] vertices;
     int[] indices;
     TriangleMesh.GetVerticesAndIndicesFromModel(entity.model, out vertices, out indices);
     AffineTransform localTransform = new AffineTransform(new Vector3(scale, scale, scale), Quaternion.Identity, new Vector3(0, 0, 0));
     MobileMesh mobileMesh = new MobileMesh(vertices, indices, localTransform, BEPUphysics.CollisionShapes.MobileMeshSolidity.Counterclockwise, 1);
     entity.localTransform = Matrix.CreateScale(scale, scale, scale);
     entity.body = mobileMesh;
     entity.HasColor = true;
     entity.diffuse = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
     entity.body.Position = position;
     space.Add(entity.body);
     children.Add(entity);
     return entity;
 }
 public BepuEntity createBox(Vector3 position, float width, float height, float length)
 {
     BepuEntity theBox = new BepuEntity();
     theBox.modelName = "cube";
     theBox.LoadContent();
     theBox.localTransform = Matrix.CreateScale(new Vector3(width, height, length));
     theBox.body = new Box(position, width, height, length, 1);
     theBox.diffuse = new Vector3((float)random.NextDouble(), (float)random.NextDouble(), (float)random.NextDouble());
     theBox.configureEvents();
     space.Add(theBox.body);
     children.Add(theBox);
     return theBox;
 }