Restricts the linear and angular motion between two entities.
Inheritance: SolverGroup
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public MoreConstraintsTestDemo(DemosGame game)
            : base(game)
        {
            Box boxA = new Box(new Vector3(0, 5, 0), 1, 2, 1, 10);
            Box boxB = new Box(new Vector3(0, 8, 0), 1, 2, 1, 10);
            boxA.Orientation = Quaternion.CreateFromYawPitchRoll(0, MathHelper.PiOver4, 0);
            boxB.Orientation = Quaternion.CreateFromYawPitchRoll(MathHelper.PiOver4, 0, 0);

            WeldJoint weld = new WeldJoint(boxA, boxB);

            Space.Add(boxA);
            Space.Add(boxB);
            Space.Add(weld);

            boxA = new Box(new Vector3(3, 5, 0), 1, 2, 1, 10);
            boxB = new Box(new Vector3(3, 8, 0), 1, 2, 1, 10);
            boxA.Orientation = Quaternion.CreateFromYawPitchRoll(0, MathHelper.PiOver4, 0);
            boxB.Orientation = Quaternion.CreateFromYawPitchRoll(MathHelper.PiOver4, 0, 0);

            BallSocketJoint ballSocket = new BallSocketJoint(boxA, boxB, (boxA.Position + boxB.Position) / 2);
            AngularMotor angularMotor = new AngularMotor(boxA, boxB);
            angularMotor.Settings.Mode = MotorMode.Servomechanism;

            Space.Add(boxA);
            Space.Add(boxB);
            Space.Add(ballSocket);
            Space.Add(angularMotor);

            Box ground = new Box(new Vector3(0, 0, 0), 10, 1, 10);

            Space.Add(ground);

            game.Camera.Position = new Vector3(0, 6, 15);
        }
        /// <summary>
        /// Creates a new, cool, advanced Model. For Accelerated Delivery. Otherwise I get
        /// lots of silly repetative variables. Note that all rendering options are hardcoded.
        /// </summary>
        /// <param name="machineNo">The machine number. For any numbers outside of 1-10, it is treated as the number of
        /// milliseconds until this machine automatically activates.</param>
        /// <param name="machines">An array of machines this machine holds. Null is acceptable.</param>
        /// <param name="models">A list of BaseModels and Tubes that the Machine contains.</param>
        /// <param name="targetPos">The amount of X, Y, and Z to translate.</param>
        /// <param name="timestep">The amount of time to use to translate.</param>
        public TranslateMachine(int machineNo, int soundIndex, Vector3 targetPos, float timestep, bool automatic, params BaseModel[] models)
            : base(machineNo, soundIndex, models)
        {
            joints = new List<WeldJoint>();
            timeStep = timestep;
            targetPosition = targetPos;
            this.automatic = automatic;
            baseJoint = new PrismaticJoint(null, modelList[0].Ent, modelList[0].Ent.Position, Vector3.Normalize(targetPos), modelList[0].Ent.Position);
            baseJoint.Motor.IsActive = true;
            baseJoint.Motor.Settings.Mode = MotorMode.Servomechanism;
            baseJoint.Motor.Settings.Servo.Goal = 0;
            baseJoint.Limit.Maximum = targetPos.Length();
            baseJoint.Limit.Minimum = 0;
            baseJoint.Limit.IsActive = true;
            baseJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = targetPos.Length() / timestep;
            baseJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = targetPos.Length() / timestep;
            baseJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 15;

            foreach(BaseModel m in modelList)
            {
                if(m == modelList[0])
                    continue;
                WeldJoint j = new WeldJoint(modelList[0].Ent, m.Ent);
                joints.Add(j);
            }
            foreach(Tube t in tubeList)
                t.SetParent(modelList[0].Ent);

            if(automatic)
            {
                inputs.Clear();
                inputs.Add(new MachineTimer(machineNo / 1000f));
            }
        }
        public StationaryCollisionCannon(CannonPathFinder path, Vector3 particlePos, params BaseModel[] models)
            : base(0, -1, models)
        {
            //explosion = new Explosion(explosionPos, explosionMag, 5, GameManager.Space);
            pathFinder = path;

            particles = new FocusedBurstSystem(Program.Game, Vector3.UnitZ, particlePos + 2 * Vector3.UnitZ);
            particles.AutoInitialize(RenderingDevice.GraphicsDevice, Program.Game.Content, RenderingDevice.SpriteBatch);
            initialParticleOrientation = particles.Emitter.OrientationData.Orientation;

            foreach(BaseModel m in modelList)
            {
                WeldJoint j = new WeldJoint(null, m.Ent);
                j.IsActive = true;
                joints.Add(j);
            }

            modelList[0].Ent.CollisionInformation.Events.PairTouching += onCollision;
        }
        /// <summary>
        /// Creates a machine that rotates, pauses, and rotates again.
        /// </summary>
        /// <param name="machineNo">Machine number, zero for auto.</param>
        /// <param name="center">Center of the machine.</param>
        /// <param name="radiansPerRotation">Angle to rotate on each rotation.</param>
        /// <param name="rotationAxis">Axis to rotate on.</param>
        /// <param name="rotationsToOrigin">Number of rotations until the machine is back to normal.</param>
        /// <param name="deactivationTime">Time to stay still for (if automatic).</param>
        /// <param name="rotateTime">Time to rotate for.</param>
        /// <param name="models">Models.</param>
        public ContinuingRotationMachine(int machineNo, int soundIndex, Vector3 rotationAxis, Vector3 zeroAxis, float radiansPerRotation, 
            int rotationsToOrigin, float deactivationTime, float rotateTime, Vector3 center, params BaseModel[] models)
            : base(machineNo, soundIndex, models)
        {
            if(machineNo == 0)
                automatic = true;

            //Quaternion radiansToRotateQ = Quaternion.CreateFromAxisAngle(rotationAxis, radiansPerRotation);
            this.rotationsToOrigin = rotationsToOrigin;
            rotationTime = rotateTime;
            angle = radiansPerRotation;
            inactiveTime = deactivationTime;
            originalAxis = rotationAxis;

            baseJoint = new RevoluteJoint(null, modelList[0].Ent, center, rotationAxis);
            baseJoint.Motor.IsActive = true;
            baseJoint.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            baseJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            baseJoint.Motor.Settings.Servo.Goal = 0;
            baseJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = radiansPerRotation / rotateTime;
            baseJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = radiansPerRotation / rotateTime;
            baseJoint.Motor.Basis.SetWorldAxes(rotationAxis, zeroAxis);
            baseJoint.Motor.TestAxis = zeroAxis;

            if(modelList.Count > 1)
                foreach(BaseModel m in modelList)
                {
                    if(m == modelList[0])
                        continue;
                    WeldJoint j = new WeldJoint(modelList[0].Ent, m.Ent);
                    joints.Add(j);
                }
            foreach(Tube t in tubeList)
                t.SetParent(modelList[0].Ent);
        }
Beispiel #5
0
        public void createVehicle(Vector3 position)
        {
            Chassis chassisentity = new Chassis();
            float width = 4;
            float height = 4;
            float length = 4;
            float pistonheight=1;
            float pistonradius=1;
            float hubheight = .1f;
            float hubradius = 3.25f;
            WeldJoint weldjoint;
            BepuEntity chassis = chassisentity.createChassis(position, width, height, length);
            chassis.LoadContent();
            chassis.body.Mass = 5;
            float wheelWidth = 3;
            float wheelRadius = .006f;
            BepuEntity wheel;
            BepuEntity cylinder1;
            BepuEntity piston;
            BepuEntity shoeright;
            BepuEntity shoeleft;

            BepuEntity hub;

            pos = position;
            chassis.body.Position = position;
            position = pos;

            SlaveCylinder slave = new SlaveCylinder();
            Hub hubentity = new Hub();
            BrakeShoeLeft brakeshoeleft = new BrakeShoeLeft();
            BrakeShoeRight brakeshoeright = new BrakeShoeRight();
            Wheel wheelentity = new Wheel();
            SlavePiston slavepiston = new SlavePiston();

            /*
            shoeright = createShoeRight(new Vector3(position.X - (width + 12), position.Y, position.Z - (length / 2)), width, height, length);
            LineJoint = new LineSliderJoint(chassis.body, shoeright.body, new Vector3(1, 0, 0), new Vector3(1, 0, 0), new Vector3(1, 0, 0));
             //   LineJoint.Motor.Settings.VelocityMotor.GoalVelocity = .0000000000000000001f;
            LineJoint.Motor.IsActive = false;
            space.Add(LineJoint);*/

            shoeright = brakeshoeright.createShoeRight(new Vector3(position.X - (width + 12), position.Y, position.Z - (length / 2)), width, height, length);
            XNAGame.Instance().joint = new RevoluteJoint(chassis.body, shoeright.body, shoeright.body.Position, new Vector3(1, 0, 0));
            XNAGame.Instance().space.Add(XNAGame.Instance().joint);
            shoeright = brakeshoeright.createShoeRight(new Vector3(position.X + (width + 12), position.Y, position.Z - (length / 2)), width, height, length);
            XNAGame.Instance().joint = new RevoluteJoint(chassis.body, shoeright.body, shoeright.body.Position, new Vector3(1, 0, 0));
            XNAGame.Instance().space.Add(XNAGame.Instance().joint);
            shoeright = brakeshoeright.createShoeRight(new Vector3(position.X - (width + 12), position.Y, position.Z + (length + 23)), width, height, length);
            XNAGame.Instance().joint = new RevoluteJoint(chassis.body, shoeright.body, shoeright.body.Position, new Vector3(1, 0, 0));
            XNAGame.Instance().space.Add(XNAGame.Instance().joint);
            shoeright = brakeshoeright.createShoeRight(new Vector3(position.X + (width + 12), position.Y, position.Z + (length + 23)), width, height, length);
            XNAGame.Instance().joint = new RevoluteJoint(chassis.body, shoeright.body, shoeright.body.Position, new Vector3(1, 0, 0));
            XNAGame.Instance().space.Add(XNAGame.Instance().joint);

            /*
                       shoeleft = brakeshoeleft.createShoeLeft(new Vector3(position.X - (width + 12), position.Y-2.5f, position.Z - (length / 2)), width, height, length);
                       joint = new RevoluteJoint(chassis.body, shoeleft.body, shoeleft.body.Position, new Vector3(0, 0, 1));
                       space.Add(joint);
                       shoeleft = brakeshoeleft.createShoeLeft(new Vector3(position.X + (width + 12), position.Y-2.5f, position.Z - (length / 2)), width, height, length);
                       joint = new RevoluteJoint(chassis.body, shoeleft.body, shoeleft.body.Position, new Vector3(1, 0, 0));
                       space.Add(joint);
                       shoeleft = brakeshoeleft.createShoeLeft(new Vector3(position.X - (width + 12), position.Y-2.5f, position.Z + (length + 23)), width, height, length);
                       joint = new RevoluteJoint(chassis.body, shoeleft.body, shoeleft.body.Position, new Vector3(1, 0, 0));
                       space.Add(joint);
                       shoeleft = brakeshoeleft.createShoeLeft(new Vector3(position.X + (width + 12), position.Y-2.5f, position.Z + (length + 23)), width, height, length);
                       joint = new RevoluteJoint(chassis.body, shoeleft.body, shoeleft.body.Position, new Vector3(0, 1, 0));
                       space.Add(joint);
                  */

            hub = hubentity.createHub(new Vector3(position.X - (width + 10), position.Y, position.Z - (length - 2)), hubheight, hubradius);
            weldjoint = new WeldJoint(chassis.body, hub.body);
            XNAGame.Instance().space.Add(weldjoint);
            hub = hubentity.createHub(new Vector3(position.X + (width + 10), position.Y, position.Z - (length - 2)), hubheight, hubradius);
            weldjoint = new WeldJoint(chassis.body, hub.body);
            XNAGame.Instance().space.Add(weldjoint);
            hub = hubentity.createHub(new Vector3(position.X - (width + 10), position.Y, position.Z + (length + 23)), hubheight, hubradius);
            weldjoint = new WeldJoint(chassis.body, hub.body);
            XNAGame.Instance().space.Add(weldjoint);

            hub = hubentity.createHub(new Vector3(position.X + (width + 10), position.Y, position.Z + (length + 23)), hubheight, hubradius);
            weldjoint = new WeldJoint(chassis.body, hub.body);
            XNAGame.Instance().space.Add(weldjoint);

            cylinder1 = slave.createCylinder(new Vector3(position.X - (width + 11), position.Y + 1.25f, position.Z -1), "SlaveCylinder", 1);
            XNAGame.Instance().joint = new RevoluteJoint(chassis.body, cylinder1.body, cylinder1.body.Position, new Vector3(0, 0, 1));

            XNAGame.Instance().space.Add(XNAGame.Instance().joint);

            weldjoint = new WeldJoint(chassis.body, cylinder1.body);
            XNAGame.Instance().space.Add(weldjoint);
            cylinder1 = slave.createCylinder(new Vector3(position.X + (width + 11), position.Y + 1.25f, position.Z - 1), "SlaveCylinder", 1);
            XNAGame.Instance().joint = new RevoluteJoint(chassis.body, cylinder1.body, cylinder1.body.Position, new Vector3(0, 0, 1));
            XNAGame.Instance().space.Add(XNAGame.Instance().joint);

            weldjoint = new WeldJoint(chassis.body, cylinder1.body);
            XNAGame.Instance().space.Add(weldjoint);
             cylinder1 = slave.createCylinder(new Vector3(position.X - (width + 11), position.Y + 1.25f, position.Z + (length + 24)), "SlaveCylinder", 1);
             XNAGame.Instance().joint = new RevoluteJoint(chassis.body, cylinder1.body, cylinder1.body.Position, new Vector3(0, 0, 1));
             XNAGame.Instance().space.Add(XNAGame.Instance().joint);

            weldjoint = new WeldJoint(chassis.body, cylinder1.body);
            XNAGame.Instance().space.Add(weldjoint);
            cylinder1 = slave.createCylinder(new Vector3(position.X + (width + 11), position.Y + 1.25f, position.Z + (length + 24)), "SlaveCylinder", 1);
            XNAGame.Instance().joint = new RevoluteJoint(chassis.body, cylinder1.body, cylinder1.body.Position, new Vector3(0, 0, 1));
            XNAGame.Instance().space.Add(XNAGame.Instance().joint);

            weldjoint = new WeldJoint(chassis.body, cylinder1.body);
            XNAGame.Instance().space.Add(weldjoint);

            piston = slavepiston.createPiston1(new Vector3(position.X - (width + 11), position.Y + 1.25f, position.Z - 1), pistonheight, pistonradius);
            /*
            prismjoint = new PrismaticJoint(cylinder1.body, piston.body, cylinder1.body.Position,new Vector3(0,1,0) , piston.body.Position);
            prismjoint.Motor.IsActive = false;
            prismjoint.Limit.IsActive = true;
            prismjoint.Limit.Minimum = 0;
            prismjoint.Limit.Maximum = 4;
            space.Add(prismjoint);
            */

            XNAGame.Instance().LineJoint = new LineSliderJoint(cylinder1.body, piston.body, new Vector3(60, 5, -21), new Vector3(0, 0, -10), new Vector3(60, 5, -10));
            XNAGame.Instance().LineJoint.Motor.IsActive = false;
            XNAGame.Instance().space.Add(XNAGame.Instance().LineJoint);

            piston = slavepiston.createPiston1(new Vector3(position.X + (width + 11), position.Y + 1.25f, position.Z - 1), pistonheight, pistonradius);
            XNAGame.Instance().LineJoint = new LineSliderJoint(cylinder1.body, piston.body, new Vector3(60, 5, -21), new Vector3(0, 0, 10), new Vector3(60, 5, -10));
            XNAGame.Instance().LineJoint.Motor.IsActive = false;
            //    space.Add(LineJoint);

            piston = slavepiston.createPiston1(new Vector3(position.X - (width + 11), position.Y + 1.25f, position.Z + (length + 24)), pistonheight, pistonradius);
            XNAGame.Instance().LineJoint = new LineSliderJoint(cylinder1.body, piston.body, new Vector3(60, 5, -21), new Vector3(0, 0, 10), new Vector3(60, 5, -10));
            XNAGame.Instance().LineJoint.Motor.IsActive = false;
            //    space.Add(LineJoint);

            piston = slavepiston.createPiston1(new Vector3(position.X + (width + 11), position.Y + 1.25f, position.Z + (length + 24)), pistonheight, pistonradius);
            XNAGame.Instance().LineJoint = new LineSliderJoint(cylinder1.body, piston.body, new Vector3(60, 5, -21), new Vector3(0, 0, 10), new Vector3(60, 5, -10));
            XNAGame.Instance().LineJoint.Motor.IsActive = false;
            //    space.Add(LineJoint);

            //WHEELS AS MESH ENTITYS
            wheel = wheelentity.createWheel(new Vector3(position.X - (width + 12) + wheelRadius, position.Y, position.Z - (length - 5) - wheelWidth), "Wheels6", 1);
            XNAGame.Instance().wheeljoint1 = new RevoluteJoint(chassis.body, wheel.body, wheel.body.Position, new Vector3(1, 0, 0));
            XNAGame.Instance().wheeljoint1.Motor.IsActive = false;
            XNAGame.Instance().space.Add(XNAGame.Instance().wheeljoint1);

            wheel = wheelentity.createWheel(new Vector3(position.X + (width + 12) - wheelRadius, position.Y, position.Z - (length - 5) - wheelWidth), "Wheels6", 1);
            XNAGame.Instance().wheeljoint2 = new RevoluteJoint(chassis.body, wheel.body, wheel.body.Position, new Vector3(1, 0, 0));
            XNAGame.Instance().wheeljoint2.Motor.IsActive = false;
            XNAGame.Instance().space.Add(XNAGame.Instance().wheeljoint2);

            wheel = wheelentity.createWheel(new Vector3(position.X - (width + 12) + wheelRadius, position.Y, position.Z + (length + 21) + wheelWidth), "Wheels6", 1);
            XNAGame.Instance().wheeljoint3 = new RevoluteJoint(chassis.body, wheel.body, wheel.body.Position, new Vector3(1, 0, 0));
            XNAGame.Instance().wheeljoint3.Motor.IsActive = false;
            XNAGame.Instance().space.Add(XNAGame.Instance().wheeljoint3);

            wheel = wheelentity.createWheel(new Vector3(position.X + (width + 12) - wheelRadius, position.Y, position.Z + (length + 21) + wheelWidth), "Wheels6", 1);
            XNAGame.Instance().wheeljoint4 = new RevoluteJoint(chassis.body, wheel.body, wheel.body.Position, new Vector3(1, 0, 0));
            XNAGame.Instance().wheeljoint4.Motor.IsActive = false;
            XNAGame.Instance().space.Add(XNAGame.Instance().wheeljoint4);

            //modelDrawer.Add(chassis.body);
        }
Beispiel #6
0
		//static public void MakeWeldJoint(Entity a, Entity b, Frame3D bBodyOffset)
		//{
		//    WeldJoint wj = new WeldJoint(a, b);
		//    //return JointFactory.CreateWeldJoint(World, a, b, new Microsoft.Xna.Framework.Vector2(0, 0),
		//    //    ConvertUnits.ToSimUnits(new Microsoft.Xna.Framework.Vector2((float)-bBodyOffset.X, (float)-bBodyOffset.Y)));
		//    //без минусов не работает как надо
		//}

		static public WeldJoint MakeWeldJoint(Entity a, Entity b)
		{
			WeldJoint wj = new WeldJoint(a, b);

			World.Add(wj);

			return wj;
			//return JointFactory.CreateWeldJoint(World, a, b, new Microsoft.Xna.Framework.Vector2(0, 0));
			//return MakeWeldJoint(a, b, new Frame3D(b.Position.X, b.Position.Y, 0));
		}
        void jointDemo()
        {
            BepuEntity e1;
            BepuEntity e2;
            Joint joint;

            // Ball & socket joint
            e1 = createBox(new Vector3(20, 5, -20), 1, 1, 5);
            e1.body.BecomeKinematic();
            e2 = createBox(new Vector3(20, 5, -10), 1, 1, 5);
            joint = new BallSocketJoint(e1.body, e2.body, new Vector3(20, 5, -15));
            space.Add(joint);

            // Hinge
            e1 = createBox(new Vector3(30, 5, -20), 1, 1, 5);
            e1.body.BecomeKinematic();
            e2 = createBox(new Vector3(30, 5, -10), 1, 1, 5);

            RevoluteJoint hinge = new RevoluteJoint(e1.body, e2.body, new Vector3(20, 5, -15), new Vector3(1, 0, 0));
            space.Add(hinge);

            // Universal
            e1 = createBox(new Vector3(40, 5, -20), 1, 1, 5);

            e2 = createBox(new Vector3(40, 5, -10), 1, 1, 5);

            UniversalJoint uni = new UniversalJoint(e1.body, e2.body, new Vector3(40, 5, -15));
            space.Add(uni);

            // Weld Joint
            e1 = createBox(new Vector3(50, 5, -20), 1, 1, 5);
            e2 = createBox(new Vector3(50, 5, -10), 1, 1, 5);

            WeldJoint weld = new WeldJoint(e1.body, e2.body);
            space.Add(weld);

            // PointOnLine Joint
            // create the line
            e1 = createBox(new Vector3(60, 5, -20), 1, 1, 5);
            e1.body.BecomeKinematic();
            e2 = createBox(new Vector3(60, 10, -10), 1, 1, 1);
            PointOnLineJoint pol = new PointOnLineJoint(e1.body, e2.body, new Vector3(60, 5, -20), new Vector3(0, 0, -1), new Vector3(60, 5, -10));
            space.Add(pol);
        }
        //public Cannon(int machineNo, int soundIndex, float delayTime, Vector3 unitsToTranslate, Vector3 rotationAxis, Vector3 explosionPos, float explosionMag, params BaseModel[] models)
        //    : this(machineNo, soundIndex, unitsToTranslate, rotationAxis, explosionPos, explosionMag, models)
        //{
        //    delay = delayTime;
        //}
        public Cannon(int machineNo, int soundIndex, Vector3 unitsToTranslate, Vector3 rotationAxis, CannonPathFinder path, Vector3 particlePos, /*float explosionMag,*/ params BaseModel[] models)
            : base(machineNo, soundIndex, models)
        {
            this.unitsToTranslate = unitsToTranslate;
            this.rotationAxis = rotationAxis;
            //explosion = new Explosion(explosionPos, explosionMag, 5, GameManager.Space);
            this.path = path;
            Vector3 explosionDirection = Vector3.Normalize(Vector3.Transform(Vector3.UnitZ, Quaternion.CreateFromAxisAngle(rotationAxis, angle)));
            if(float.IsInfinity(explosionDirection.X) || float.IsInfinity(explosionDirection.X) || float.IsInfinity(explosionDirection.Z))
                explosionDirection = Vector3.UnitZ;

            particles = new FocusedBurstSystem(Program.Game, explosionDirection, particlePos + 3 * explosionDirection);
            particles.AutoInitialize(RenderingDevice.GraphicsDevice, Program.Game.Content, RenderingDevice.SpriteBatch);
            RenderingDevice.GDM.DeviceCreated += delegate { particles.AutoInitialize(RenderingDevice.GraphicsDevice, Program.Game.Content, RenderingDevice.SpriteBatch); };
            RenderingDevice.Add(particles);

            initialParticleOrientation = particles.Emitter.OrientationData.Orientation;

            baseJoint = new PerpendicularLineJoint(null, modelList[0].Ent, modelList[0].Ent.Position, Vector3.Normalize(unitsToTranslate),
                modelList[0].Ent.Position, rotationAxis);
            baseJoint.LinearMotor.IsActive = true;
            baseJoint.LinearMotor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            baseJoint.LinearMotor.Settings.Servo.Goal = 0;
            baseJoint.LinearMotor.Settings.Servo.BaseCorrectiveSpeed = baseJoint.LinearMotor.Settings.Servo.MaxCorrectiveVelocity = unitsToTranslate.Length() / 2;
            baseJoint.LinearMotor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.LinearMotor.Settings.Servo.SpringSettings.DampingConstant /= 15;
            baseJoint.LinearLimit.Maximum = unitsToTranslate.Length();
            baseJoint.LinearLimit.Minimum = 0;
            baseJoint.LinearLimit.IsActive = true;

            baseJoint.AngularMotor.IsActive = true;
            baseJoint.AngularMotor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            baseJoint.AngularMotor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.AngularMotor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            baseJoint.AngularMotor.Settings.Servo.Goal = 0;
            baseJoint.AngularMotor.Settings.Servo.MaxCorrectiveVelocity = angle;
            baseJoint.AngularMotor.Settings.Servo.BaseCorrectiveSpeed = angle;
            baseJoint.AngularMotor.Basis.SetWorldAxes(rotationAxis, Vector3.UnitZ);
            baseJoint.AngularMotor.TestAxis = Vector3.UnitZ;
            baseJoint.AngularLimit.IsActive = true;
            baseJoint.AngularLimit.MinimumAngle = 0;
            baseJoint.AngularLimit.MaximumAngle = angle;
            baseJoint.AngularLimit.Basis.SetWorldAxes(rotationAxis, Vector3.UnitZ);
            baseJoint.AngularLimit.TestAxis = Vector3.UnitZ;

            if(modelList.Count > 1)
                foreach(BaseModel m in modelList)
                {
                    if(m == modelList[0])
                        continue;
                    WeldJoint j = new WeldJoint(modelList[0].Ent, m.Ent);
                    joints.Add(j);
                }

            //curve = new QuaternionSlerpCurve();
            //curve.ControlPoints.Add(0, Quaternion.Identity);
            //curve.ControlPoints.Add(2, Quaternion.Identity);
            //curve.ControlPoints.Add(3, Quaternion.CreateFromAxisAngle(rotationAxis, MathHelper.ToRadians(45)));
            //curve.ControlPoints.Add(4, Quaternion.CreateFromAxisAngle(rotationAxis, MathHelper.ToRadians(45)));
            //curve.PostLoop = CurveEndpointBehavior.Mirror;
            //curve.PreLoop = CurveEndpointBehavior.Mirror;
        }
        public TruckMachine(int machineNo, int soundIndex, float translationTime, float rotationTime, float angle,
            Vector3 translationAxis, Vector3 glassRotationAxis, Vector3 wheelRotationAxis,
            Vector3 glassZeroAxis, Vector3 glassCenter1, Vector3 glassCenter2, Vector3 wheelsCenter1,
            Vector3 wheelsCenter2, BaseModel wheels1, BaseModel wheels2, BaseModel glass1,
            BaseModel glass2, params BaseModel[] models)
            : base(machineNo, soundIndex, models.Concat(new BaseModel[] { wheels1, wheels2, glass1, glass2 }).ToArray<BaseModel>())
        {
            translation = translationAxis;
            this.translationTime = translationTime;
            this.rotationTime = rotationTime;

            originalGlassAxis = glassRotationAxis;
            originalWheelAxis = wheelRotationAxis;
            unitsToTranslate = translationAxis;

            baseJoint = new PrismaticJoint(null, models[0].Ent, models[0].Ent.Position, translationAxis, models[0].Ent.Position);
            baseJoint.Motor.IsActive = true;
            baseJoint.Motor.Settings.Mode = MotorMode.Servomechanism;
            baseJoint.Motor.Settings.Servo.Goal = 0;
            baseJoint.Limit.Maximum = translationAxis.Length();
            baseJoint.Limit.Minimum = 0;
            baseJoint.Limit.IsActive = true;
            baseJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = translationAxis.Length() / translationTime;
            baseJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = translationAxis.Length() / translationTime;
            baseJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 11;

            glassJoint1 = new RevoluteJoint(models[0].Ent, glass1.Ent, glassCenter1, glassRotationAxis);
            glassJoint1.Motor.IsActive = true;
            glassJoint1.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            glassJoint1.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            glassJoint1.Motor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            glassJoint1.Motor.Settings.Servo.Goal = 0;
            glassJoint1.Motor.Settings.Servo.MaxCorrectiveVelocity = angle / rotationTime;
            glassJoint1.Motor.Settings.Servo.BaseCorrectiveSpeed = angle / rotationTime;
            glassJoint1.Motor.Basis.SetWorldAxes(glassRotationAxis, glassZeroAxis);
            glassJoint1.Motor.TestAxis = glassZeroAxis;
            glassJoint1.Limit.IsActive = true;
            glassJoint1.Limit.MinimumAngle = 0;
            glassJoint1.Limit.MaximumAngle = angle;
            glassJoint1.Limit.Basis.SetWorldAxes(glassRotationAxis, glassZeroAxis);
            glassJoint1.Limit.TestAxis = glassZeroAxis;

            glassJoint2 = new RevoluteJoint(models[0].Ent, glass2.Ent, glassCenter2, -glassRotationAxis);
            glassJoint2.Motor.IsActive = true;
            glassJoint2.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            glassJoint2.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            glassJoint2.Motor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            glassJoint2.Motor.Settings.Servo.Goal = 0;
            glassJoint2.Motor.Settings.Servo.MaxCorrectiveVelocity = angle / rotationTime;
            glassJoint2.Motor.Settings.Servo.BaseCorrectiveSpeed = angle / rotationTime;
            glassJoint2.Motor.Basis.SetWorldAxes(-glassRotationAxis, glassZeroAxis);
            glassJoint2.Motor.TestAxis = glassZeroAxis;
            glassJoint2.Limit.IsActive = true;
            glassJoint2.Limit.MinimumAngle = 0;
            glassJoint2.Limit.MaximumAngle = angle;
            glassJoint2.Limit.Basis.SetWorldAxes(-glassRotationAxis, glassZeroAxis);
            glassJoint2.Limit.TestAxis = glassZeroAxis;

            wheelsJoint1 = new RevoluteJoint(models[0].Ent, wheels1.Ent, wheelsCenter1, wheelRotationAxis);
            wheelsJoint1.Motor.Settings.Mode = MotorMode.VelocityMotor;
            wheelsJoint1.Motor.Settings.VelocityMotor.GoalVelocity = 0f;
            wheelsJoint1.Motor.Settings.VelocityMotor.Softness = 1 / glassJoint1.Motor.Settings.Servo.SpringSettings.DampingConstant;
            wheelsJoint2 = new RevoluteJoint(models[0].Ent, wheels2.Ent, wheelsCenter2, wheelRotationAxis);
            wheelsJoint2.Motor.Settings.Mode = MotorMode.VelocityMotor;
            wheelsJoint2.Motor.Settings.VelocityMotor.GoalVelocity = 0f;
            wheelsJoint2.Motor.Settings.VelocityMotor.Softness = 1 / glassJoint2.Motor.Settings.Servo.SpringSettings.DampingConstant;

            if(models.Length > 1)
                foreach(BaseModel m in models)
                {
                    if(m == models[0])
                        continue;
                    WeldJoint j = new WeldJoint(models[0].Ent, m.Ent);
                    j.IsActive = true;
                    joints.Add(j);
                }
        }
        /// <summary>
        /// Creates a machine that rotates between two orientations, with or without an offset.
        /// </summary>
        /// <param name="machineNo">The machine number.</param>
        /// <param name="objects">A list of BaseModels and Tubes that the Machine contains. It will be assumed that the first is the base of the
        /// machine and all others are contained inside the machine.</param>
        /// <param name="angle">The angle of rotation.</param>
        /// <param name="rotationAxis">The axis of rotation.</param>
        /// <param name="center">The center of rotation.</param>
        /// <param name="rotateTime">The time to complete one rotation in seconds.</param>
        public ClampedRotationMachine(int machineNo, int soundIndex, float rotateTime, Vector3 rotationAxis, float angle,
            Vector3 center, Vector3 zeroAxis, params BaseModel[] objects)
            : base(machineNo, soundIndex, objects)
        {
            //if(angle < 0 || angle > MathHelper.Pi)
            //    throw new ArgumentOutOfRangeException("Angle must be between 0 and pi. Use a negative zeroAxis to simulate negative angles.");
            if(rotateTime <= 0)
                throw new ArgumentOutOfRangeException("rotateTime cannot be equal to or less than zero.");

            if(angle < 0)
            {
                negativeAngle = true;
                angle = -angle;
                atOrigin = false;
            }

            originalAxis = rotationAxis;

            //motorList = new List<RotateMotor>();
            joints = new List<WeldJoint>();
            baseJoint = new RevoluteJoint(null, modelList[0].Ent, center, rotationAxis);
            baseJoint.Motor.IsActive = true;
            baseJoint.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            baseJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 12;
            baseJoint.Motor.Settings.Servo.Goal = negativeAngle ? angle : 0;
            baseJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = angle / rotateTime;
            baseJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = angle / rotateTime;
            baseJoint.Motor.Basis.SetWorldAxes(rotationAxis, zeroAxis);
            baseJoint.Motor.TestAxis = zeroAxis;
            baseJoint.Limit.IsActive = true;
            baseJoint.Limit.MinimumAngle = 0;
            baseJoint.Limit.MaximumAngle = angle;
            baseJoint.Limit.Basis.SetWorldAxes(rotationAxis, zeroAxis);
            baseJoint.Limit.TestAxis = zeroAxis;

            timeStep = rotateTime;
            this.angle = angle;

            //foreach(Tube t in tubeList)
            //    t.LocalOffset = t.Ent.Position - center;

            if(modelList.Count > 1)
                foreach(BaseModel m in modelList)
                {
                    if(m == modelList[0]) // skip first element
                        continue;
                    //m.Ent.Orientation = Quaternion.Identity;
                    //m.Ent.CollisionInformation.LocalPosition = m.Ent.Position - center;
                    //m.Ent.Position = center;
                    //m.Ent.Orientation = m.OriginalOrientation; // Resets orientation
                    //motorList.Add(new RotateMotor(m, radiansToRotate) { Time = GameManager.Space.TimeStepSettings.TimeStepDuration });
                    WeldJoint j = new WeldJoint(baseJoint.Motor.ConnectionB, m.Ent);
                    j.IsActive = true;
                    //j.Limit.IsActive = true;
                    //j.Limit.MinimumAngle = 0;
                    joints.Add(j);
                }
            foreach(Tube t in tubeList)
                t.SetParent(baseJoint.Motor.ConnectionB);
                //motorList.Add(new RotateMotor(t, radiansToRotate, t.LocalOffset) { Time = GameManager.Space.TimeStepSettings.TimeStepDuration });
        }
        BepuEntity createCog(Vector3 position, float radius, int gears)
        {
            BepuEntity wheel = createWheel(position, 1, radius);

            float angleDelta = (MathHelper.Pi * 2.0f) / (float) gears;

            float cogHeight = radius * 0.2f;
            for (int i = 0; i < gears; i++)
            {
                float angle = ((float) i) * angleDelta;
                float x = (radius + (cogHeight / 2.0f)) * (float) Math.Sin(angle);
                float y = (radius + (cogHeight / 2.0f)) * (float) Math.Cos(angle);
                Vector3 cogPos = new Vector3(x, y, 0) + position;
                BepuEntity cog = createBox(cogPos, cogHeight, cogHeight, 1);
                cog.LoadContent();
                cog.body.Orientation = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1), angle);
                WeldJoint weld = new WeldJoint(wheel.body, cog.body);
                space.Add(weld);
            }

            return wheel;
        }
Beispiel #12
0
        public Joints(SoundEffect hn, SoundEffect rotv, seeSaw ss, HelicopterBase hb, HelicopterRotor hr, HelicopterSkid hs, HelicopterTail ht, HelicopterTailRotor htr, HelicopterClawHolder hch, HelicopterClawHinge hchinge, HelicopterClawItemHolder hcih)
        {
            engineOn = false;       // Set the engine to off

            hBase = hb;
            hRotor = hr;
            hSkid = hs;
            hTail = ht;
            hTailRotor = htr;
            hClawHolder = hch;
            hClawHinge = hchinge;
            hClawItemHolder = hcih;
            seeSaw = ss;

            helicopterNoise = hn;
            hnInstance = helicopterNoise.CreateInstance();          // New instance of sound effect
            hnInstance.Volume = 0.6f;
            hnInstance.IsLooped = true;

            rideOfTheValkyries = rotv;
            rotvInstance = rideOfTheValkyries.CreateInstance();     // New instance of sound effect
            rotvInstance.Volume = 0.6f;
            rotvInstance.IsLooped = true;

            hBaseRotorJoint = new RevoluteJoint(hBase.helicopter.body, hRotor.rotor.body, hBase.helicopter.body.Position, Vector3.Up);  // Joint for rotor on top of helicopter
            hBaseRotorJoint.Motor.Settings.MaximumForce = 200;
            hBaseRotorJoint.Motor.IsActive = false;

            // Well joints for skids on bottom of helicopter and tail, attach each entity to the helicopter
            hTailJoint = new WeldJoint(hTail.tail.body, hBase.helicopter.body);
            hSkidJoint1 = new WeldJoint(hSkid.skid1.body, hBase.helicopter.body);
            hSkidJoint2 = new WeldJoint(hSkid.skid2.body, hBase.helicopter.body);

            hTailRotorJoint = new RevoluteJoint(hTailRotor.tailRotor.body, hTail.tail.body, hTailRotor.tailRotor.body.Position, Vector3.Right); // Joint for rotor on tail of the helicopter
            hTailRotorJoint.Motor.Settings.MaximumForce = 180;
            hTailRotorJoint.Motor.IsActive = false;

            hClawHolderJoint = new SwivelHingeJoint(hBase.helicopter.body, hClawHolder.clawHolder.body, hBase.helicopter.body.Position, Vector3.Right);    // Joint for claw holder below helicopter

            hClawHolderJoint.HingeLimit.IsActive = true;
            hClawHolderJoint.HingeLimit.MinimumAngle = -MathHelper.Pi / 45;
            hClawHolderJoint.HingeLimit.MaximumAngle = MathHelper.Pi / 45;

            // 4 similar joints for hinge joints between the claw holder and a part of the claw
            // The hinges code was created with help from the examuse ple Bepu Physics demo available from the website
            hClawHingeJoint1 = new RevoluteJoint(hClawHolder.clawHolder.body, hClawHinge.clawHinge1.body, hClawHolder.clawHolder.body.Position, Vector3.Forward);
            hClawHingeJoint1.Motor.IsActive = true;
            hClawHingeJoint1.Motor.Settings.Mode = MotorMode.Servomechanism;
            hClawHingeJoint1.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            hClawHingeJoint1.Motor.Settings.Servo.SpringSettings.DampingConstant /= 20;     // Damping to quicken the claw contracting
            hClawHingeJoint1.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;   // Stop the claw from over moving on the axis

            hClawHingeJoint1.Limit.IsActive = true;
            hClawHingeJoint1.Limit.MinimumAngle = -MathHelper.TwoPi;
            hClawHingeJoint1.Limit.MaximumAngle = MathHelper.PiOver4;

            hClawHingeJoint2 = new RevoluteJoint(hClawHolder.clawHolder.body, hClawHinge.clawHinge2.body, hClawHolder.clawHolder.body.Position, Vector3.Backward);
            hClawHingeJoint2.Motor.IsActive = true;
            hClawHingeJoint2.Motor.Settings.Mode = MotorMode.Servomechanism;
            hClawHingeJoint2.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            hClawHingeJoint2.Motor.Settings.Servo.SpringSettings.DampingConstant /= 20;
            hClawHingeJoint2.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;

            hClawHingeJoint2.Limit.IsActive = true;
            hClawHingeJoint2.Limit.MinimumAngle = -MathHelper.TwoPi;
            hClawHingeJoint2.Limit.MaximumAngle = MathHelper.PiOver4;

            hClawHingeJoint3 = new RevoluteJoint(hClawHolder.clawHolder.body, hClawHinge.clawHinge3.body, hClawHolder.clawHolder.body.Position, Vector3.Right);
            hClawHingeJoint3.Motor.IsActive = true;
            hClawHingeJoint3.Motor.Settings.Mode = MotorMode.Servomechanism;
            hClawHingeJoint3.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            hClawHingeJoint3.Motor.Settings.Servo.SpringSettings.DampingConstant /= 20;
            hClawHingeJoint3.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;

            hClawHingeJoint3.Limit.IsActive = true;
            hClawHingeJoint3.Limit.MinimumAngle = -MathHelper.TwoPi;
            hClawHingeJoint3.Limit.MaximumAngle = MathHelper.PiOver4;

            hClawHingeJoint4 = new RevoluteJoint(hClawHolder.clawHolder.body, hClawHinge.clawHinge4.body, hClawHolder.clawHolder.body.Position, Vector3.Left);
            hClawHingeJoint4.Motor.IsActive = true;
            hClawHingeJoint4.Motor.Settings.Mode = MotorMode.Servomechanism;
            hClawHingeJoint4.Motor.Settings.Servo.Goal = -MathHelper.PiOver2;
            hClawHingeJoint4.Motor.Settings.Servo.SpringSettings.DampingConstant /= 20;
            hClawHingeJoint4.Motor.Settings.Servo.SpringSettings.StiffnessConstant /= 20;

            hClawHingeJoint4.Limit.IsActive = true;
            hClawHingeJoint4.Limit.MinimumAngle = -MathHelper.TwoPi;
            hClawHingeJoint4.Limit.MaximumAngle = MathHelper.PiOver4;

            // More weld joints as the claw pieces are made up off two different sections
            hClawItemHolderJoint1 = new WeldJoint(hClawHinge.clawHinge1.body, hClawItemHolder.clawItemHolder1.body);
            hClawItemHolderJoint2 = new WeldJoint(hClawHinge.clawHinge2.body, hClawItemHolder.clawItemHolder2.body);
            hClawItemHolderJoint3 = new WeldJoint(hClawHinge.clawHinge3.body, hClawItemHolder.clawItemHolder3.body);
            hClawItemHolderJoint4 = new WeldJoint(hClawHinge.clawHinge4.body, hClawItemHolder.clawItemHolder4.body);

            // Joint for the seesaw with the ball located on it
            seeSawJoint = new RevoluteJoint(seeSaw.seeSawHolder.body, seeSaw.seeSawBoard.body, seeSaw.seeSawHolder.body.Position, Vector3.Forward);

            revoluteJoints.Add(hBaseRotorJoint);
            revoluteJoints.Add(hTailRotorJoint);
            revoluteJoints.Add(hClawHingeJoint1);
            revoluteJoints.Add(hClawHingeJoint2);
            revoluteJoints.Add(hClawHingeJoint3);
            revoluteJoints.Add(hClawHingeJoint4);
            revoluteJoints.Add(seeSawJoint);

            weldJoints.Add(hTailJoint);
            weldJoints.Add(hSkidJoint1);
            weldJoints.Add(hSkidJoint2);
            weldJoints.Add(hClawItemHolderJoint1);
            weldJoints.Add(hClawItemHolderJoint2);
            weldJoints.Add(hClawItemHolderJoint3);
            weldJoints.Add(hClawItemHolderJoint4);

            entities.Add(hBase.helicopter);
            entities.Add(hRotor.rotor);
            entities.Add(hSkid.skid1);
            entities.Add(hSkid.skid2);
            entities.Add(hTail.tail);
            entities.Add(hTailRotor.tailRotor);
            entities.Add(hClawHolder.clawHolder);

            entities.Add(hClawHinge.clawHinge1);
            entities.Add(hClawHinge.clawHinge2);
            entities.Add(hClawHinge.clawHinge3);
            entities.Add(hClawHinge.clawHinge4);
            entities.Add(hClawItemHolder.clawItemHolder1);
            entities.Add(hClawItemHolder.clawItemHolder2);
            entities.Add(hClawItemHolder.clawItemHolder3);
            entities.Add(hClawItemHolder.clawItemHolder4);

            for (int i = 0; i < revoluteJoints.Count; i++)      // Add all the revolute joints to the space
            {
                Game1.Instance.Space.Add(revoluteJoints.ElementAt(i));
            }

            for (int i = 0; i < weldJoints.Count; i++)          // Add all the weld joints to the space
            {
                Game1.Instance.Space.Add(weldJoints.ElementAt(i));
            }

            Game1.Instance.Space.Add(hClawHolderJoint);     // Add the swivel hinge joint to the space
        }
Beispiel #13
0
 protected void StickToEntity(Entity entity)
 {
     StuckEntity = entity;
     Entity.AngularMomentum = Vector3.Zero;
     Entity.LinearMomentum = Vector3.Zero;
     mStickConstraint = new WeldJoint(StuckEntity, Entity);
     World.Space.Add(mStickConstraint);
     CollisionRules.AddRule(Entity, StuckEntity, CollisionRule.NoBroadPhase);
 }
        /// <summary>
        /// Makes a machine that automatically translates and user-rotates.
        /// </summary>
        /// <param name="machineNo">Machine number of the machine.</param>
        /// <param name="unitsToTranslate">The distance to translate from the origin.</param>
        /// <param name="pauseTime">The time in seconds to pause at each end.</param>
        /// <param name="centerOfRotation">The center of rotation based on the starting position.</param>
        /// <param name="rotateTime">Time to take to rotate.</param>
        /// <param name="degreesToRotate">The degrees on each axis to rotate.</param>
        /// <param name="models">The models that rotate.</param>
        /// <param name="angle">The angle to rotate.</param>
        /// <param name="rotationAxis">The axis to rotate on.</param>
        /// <param name="soundIndex">The sound to use for the machine.</param>
        /// <param name="stableModels">The models that don't rotate.</param>
        /// <param name="translationTime">The time to take to translate.</param>
        public RailMachine(int machineNo, int soundIndex, bool soundWhenMoves, Vector3 unitsToTranslate, float pauseTime, float translationTime,
            Vector3 centerOfRotation, float rotateTime, Vector3 rotationAxis, float angle, Vector3 zeroAxis, BaseModel[] stableModels,
            params BaseModel[] models)
            : base(machineNo, soundIndex, models)
        {
            if(stableModels.Length == 0)
                throw new ArgumentException("There must be at least one stable model.");
            if(models.Length == 0)
                throw new ArgumentException("There must be a least rotational model.");

            this.unitsToTranslate = unitsToTranslate;
            this.translationTime = translationTime;
            this.rotateTime = rotateTime;
            this.angle = angle;
            this.soundWhenMoves = soundWhenMoves;
            lengthToPause = pauseTime;
            originalAxis = rotationAxis;

            if(angle < 0)
            {
                negativeAngle = true;
                angle = -angle;
            }

            baseJoint = new PrismaticJoint(null, stableModels[0].Ent, stableModels[0].Ent.Position, Vector3.Normalize(unitsToTranslate), stableModels[0].Ent.Position);
            baseJoint.Motor.IsActive = true;
            baseJoint.Motor.Settings.Mode = MotorMode.Servomechanism;
            baseJoint.Motor.Settings.Servo.Goal = 0;
            baseJoint.Limit.Maximum = unitsToTranslate.Length();
            baseJoint.Limit.Minimum = 0;
            baseJoint.Limit.IsActive = true;
            baseJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = unitsToTranslate.Length() / translationTime;
            baseJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = unitsToTranslate.Length() / translationTime;
            baseJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            baseJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 2;

            rotateJoint = new RevoluteJoint(stableModels[0].Ent, models[0].Ent, centerOfRotation, rotationAxis);
            rotateJoint.Motor.IsActive = true;
            rotateJoint.Motor.Settings.Mode = BEPUphysics.Constraints.TwoEntity.Motors.MotorMode.Servomechanism;
            rotateJoint.Motor.Settings.Servo.SpringSettings.StiffnessConstant = 0;
            rotateJoint.Motor.Settings.Servo.SpringSettings.DampingConstant /= 4;
            rotateJoint.Motor.Settings.Servo.Goal = negativeAngle ? angle : 0;
            rotateJoint.Motor.Settings.Servo.MaxCorrectiveVelocity = angle / rotateTime;
            rotateJoint.Motor.Settings.Servo.BaseCorrectiveSpeed = angle / rotateTime;
            rotateJoint.Motor.Basis.SetWorldAxes(rotationAxis, zeroAxis);
            rotateJoint.Motor.TestAxis = zeroAxis;
            rotateJoint.Limit.IsActive = true;
            rotateJoint.Limit.MinimumAngle = 0;
            rotateJoint.Limit.MaximumAngle = angle;
            rotateJoint.Limit.Basis.SetWorldAxes(rotationAxis, zeroAxis);
            rotateJoint.Limit.TestAxis = zeroAxis;

            for(int i = 0; i < stableModels.Length - 1; i++)
            {
                WeldJoint j = new WeldJoint(stableModels[0].Ent, stableModels[i + 1].Ent);
                j.IsActive = true;
                welds.Add(j);
            }
            for(int i = 0; i < models.Length - 1; i++)
            {
                WeldJoint j = new WeldJoint(models[0].Ent, models[i + 1].Ent);
                j.IsActive = true;
                welds.Add(j);
            }
            foreach(Tube t in tubeList)
                t.SetParent(models[0].Ent);

            modelList.Clear();
            modelList.AddRange(stableModels);
            modelList.AddRange(models);

            //Vector3 radians = new Vector3(MathHelper.ToRadians(degreesToRotate.X),
            //    MathHelper.ToRadians(degreesToRotate.Y), MathHelper.ToRadians(degreesToRotate.Z));
            //radiansToRotate = Quaternion.CreateFromYawPitchRoll(radians.Y,
            //    radians.X, radians.Z);

            //for(int i = 1; i < modelList.Count; i++)
            //{
            //    BaseModel m = modelList[i];
            //    m.Ent.Orientation = Quaternion.Identity;
            //    m.Ent.CollisionInformation.LocalPosition = m.Ent.Position - centerOfRotation;
            //    m.Ent.Position = centerOfRotation;
            //    m.Ent.Orientation = m.OriginalOrientation; // Resets orientation
            //}
            //curve = new QuaternionSlerpCurve();
            //curve.ControlPoints.Add(0, Quaternion.Identity);
            //curve.ControlPoints.Add(rotateTime, radiansToRotate);
            //curve.PostLoop = CurveEndpointBehavior.Mirror;
            //curve.PreLoop = CurveEndpointBehavior.Mirror;
            timeStep = rotateTime * 1000;
        }