예제 #1
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);
        }
예제 #2
0
        public RopeSample(Microsoft.Xna.Framework.Game game)
            : base(game)
        {
            // Add basic force effects.
            Simulation.ForceEffects.Add(new Gravity());
            Simulation.ForceEffects.Add(new Damping());

            // Add a ground plane.
            RigidBody groundPlane = new RigidBody(new PlaneShape(Vector3F.UnitY, 0))
            {
                Name       = "GroundPlane", // Names are not required but helpful for debugging.
                MotionType = MotionType.Static,
            };

            Simulation.RigidBodies.Add(groundPlane);

            const float  capsuleHeight = 0.6f;
            CapsuleShape shape         = new CapsuleShape(0.15f, capsuleHeight);

            for (int i = 0; i < 20; i++)
            {
                // A segment of the rope:
                RigidBody body = new RigidBody(shape)
                {
                    Pose = new Pose(new Vector3F(0, 1 + i * capsuleHeight, 0)),
                };
                Simulation.RigidBodies.Add(body);

                if (i > 0)
                {
                    // Connect the last body with the current body using a UniversalJoint that
                    // allows rotations on two axes (no twist).
                    RigidBody      lastBody  = Simulation.RigidBodies[i];
                    UniversalJoint ballJoint = new UniversalJoint
                    {
                        BodyA = lastBody,
                        // This attachment point is a the top of the first capsule.
                        // The universal joint allows rotations around the first and the second axis.
                        // The last axis is the twist axis where no rotation is allowed.
                        // --> To define the constraint anchor orientation:
                        // The columns are the axes. We set the local x axis in the first column and the
                        // -z axis in the second column. The third column is y axis about which no rotation
                        // is allowed.
                        // (All three columns are orthonormal and form a valid rotation matrix.)
                        AnchorPoseALocal = new Pose(new Vector3F(0, capsuleHeight / 2, 0),
                                                    new Matrix33F(1, 0, 0,
                                                                  0, 0, 1,
                                                                  0, -1, 0)),

                        BodyB = body,
                        // This attachment point is at the bottom of the second capsule.
                        // The anchor orientation is defined as above.
                        AnchorPoseBLocal = new Pose(new Vector3F(0, -capsuleHeight / 2, 0),
                                                    new Matrix33F(1, 0, 0,
                                                                  0, 0, 1,
                                                                  0, -1, 0)),

                        // Disable collision between body A and B.
                        CollisionEnabled = false,

                        // ErrorReduction and Softness are tweaked to create an appropriate amount
                        // of springiness and damping.
                        ErrorReduction = 0.1f,
                        Softness       = 0.0001f,

                        // We allow a +/- 60° rotation around the first and the second constraint axis.
                        Minimum = -new Vector2F(MathHelper.ToRadians(60), MathHelper.ToRadians(60)),
                        Maximum = new Vector2F(MathHelper.ToRadians(60), MathHelper.ToRadians(60))
                    };
                    Simulation.Constraints.Add(ballJoint);
                }
                else
                {
                    // This is the first body. There is no former body to link too.
                    // We set a velocity for this body to give the rope an initial movement.
                    body.LinearVelocity = new Vector3F(1, 0, 0);
                }
            }
        }
        /// <summary>
        /// Constructs a new demo.
        /// </summary>
        /// <param name="game">Game owning this demo.</param>
        public DogbotDemo(DemosGame game)
            : base(game)
        {
            Entity body = new Box(new Vector3(0, 0, 0), 4, 2, 2, 20);

            Space.Add(body);

            Entity head = new Cone(body.Position + new Vector3(3.2f, .3f, 0), 1.5f, .7f, 4);

            head.OrientationMatrix = Matrix3x3.CreateFromAxisAngle(Vector3.Forward, MathHelper.PiOver2);
            Space.Add(head);

            //Attach the head to the body
            var universalJoint = new UniversalJoint(body, head, head.Position + new Vector3(-.8f, 0, 0));

            Space.Add(universalJoint);
            //Keep the head from swinging around too much.
            var angleLimit = new SwingLimit(body, head, Vector3.Right, Vector3.Right, MathHelper.PiOver4);

            Space.Add(angleLimit);

            var tail = new Box(body.Position + new Vector3(-3f, 1f, 0), 1.6f, .1f, .1f, 4);

            Space.Add(tail);
            //Keep the tail from twisting itself off.
            universalJoint = new UniversalJoint(body, tail, tail.Position + new Vector3(.8f, 0, 0));
            Space.Add(universalJoint);

            //Give 'em some floppy ears.
            var ear = new Box(head.Position + new Vector3(-.2f, 0, -.65f), .01f, .7f, .2f, 1);

            Space.Add(ear);

            var ballSocketJoint = new BallSocketJoint(head, ear, head.Position + new Vector3(-.2f, .35f, -.65f));

            Space.Add(ballSocketJoint);

            ear = new Box(head.Position + new Vector3(-.2f, 0, .65f), .01f, .7f, .3f, 1);
            Space.Add(ear);

            ballSocketJoint = new BallSocketJoint(head, ear, head.Position + new Vector3(-.2f, .35f, .65f));
            Space.Add(ballSocketJoint);


            Box              arm;
            Cylinder         shoulder;
            PointOnLineJoint pointOnLineJoint;

            //*************  First Arm   *************//
            arm = new Box(body.Position + new Vector3(-1.8f, -.5f, 1.5f), .5f, 3, .2f, 20);
            Space.Add(arm);

            shoulder = new Cylinder(body.Position + new Vector3(-1.8f, .3f, 1.25f), .1f, .7f, 10);
            shoulder.OrientationMatrix = Matrix3x3.CreateFromAxisAngle(Vector3.Right, MathHelper.PiOver2);
            Space.Add(shoulder);

            //Connect the shoulder to the body.
            var axisJoint = new RevoluteJoint(body, shoulder, shoulder.Position, Vector3.Forward);

            //Motorize the connection.
            axisJoint.Motor.IsActive = true;
            axisJoint.Motor.Settings.VelocityMotor.GoalVelocity = 1;

            Space.Add(axisJoint);

            //Connect the arm to the shoulder.
            axisJoint = new RevoluteJoint(shoulder, arm, shoulder.Position + new Vector3(0, .6f, 0), Vector3.Forward);
            Space.Add(axisJoint);

            //Connect the arm to the body.
            pointOnLineJoint = new PointOnLineJoint(arm, body, arm.Position, Vector3.Up, arm.Position + new Vector3(0, -.4f, 0));
            Space.Add(pointOnLineJoint);


            shoulder.OrientationMatrix *= Matrix3x3.CreateFromAxisAngle(Vector3.Forward, MathHelper.Pi); //Force the walker's legs out of phase.

            //*************  Second Arm   *************//
            arm = new Box(body.Position + new Vector3(1.8f, -.5f, 1.5f), .5f, 3, .2f, 20);
            Space.Add(arm);

            shoulder = new Cylinder(body.Position + new Vector3(1.8f, .3f, 1.25f), .1f, .7f, 10);
            shoulder.OrientationMatrix = Matrix3x3.CreateFromAxisAngle(Vector3.Right, MathHelper.PiOver2);
            Space.Add(shoulder);

            //Connect the shoulder to the body.
            axisJoint = new RevoluteJoint(body, shoulder, shoulder.Position, Vector3.Forward);

            //Motorize the connection.
            axisJoint.Motor.IsActive = true;
            axisJoint.Motor.Settings.VelocityMotor.GoalVelocity = 1;

            Space.Add(axisJoint);

            //Connect the arm to the shoulder.
            axisJoint = new RevoluteJoint(shoulder, arm, shoulder.Position + new Vector3(0, .6f, 0), Vector3.Forward);
            Space.Add(axisJoint);


            //Connect the arm to the body.
            pointOnLineJoint = new PointOnLineJoint(arm, body, arm.Position, Vector3.Up, arm.Position + new Vector3(0, -.4f, 0));
            Space.Add(pointOnLineJoint);

            //*************  Third Arm   *************//
            arm = new Box(body.Position + new Vector3(-1.8f, -.5f, -1.5f), .5f, 3, .2f, 20);
            Space.Add(arm);

            shoulder = new Cylinder(body.Position + new Vector3(-1.8f, .3f, -1.25f), .1f, .7f, 10);
            shoulder.OrientationMatrix = Matrix3x3.CreateFromAxisAngle(Vector3.Right, MathHelper.PiOver2);
            Space.Add(shoulder);

            //Connect the shoulder to the body.
            axisJoint = new RevoluteJoint(body, shoulder, shoulder.Position, Vector3.Forward);

            //Motorize the connection.
            axisJoint.Motor.IsActive = true;
            axisJoint.Motor.Settings.VelocityMotor.GoalVelocity = 1;

            Space.Add(axisJoint);

            //Connect the arm to the shoulder.
            axisJoint = new RevoluteJoint(shoulder, arm, shoulder.Position + new Vector3(0, .6f, 0), Vector3.Forward);
            Space.Add(axisJoint);

            //Connect the arm to the body.
            pointOnLineJoint = new PointOnLineJoint(arm, body, arm.Position, Vector3.Up, arm.Position + new Vector3(0, -.4f, 0));
            Space.Add(pointOnLineJoint);


            shoulder.OrientationMatrix *= Matrix3x3.CreateFromAxisAngle(Vector3.Forward, MathHelper.Pi); //Force the walker's legs out of phase.

            //*************  Fourth Arm   *************//
            arm = new Box(body.Position + new Vector3(1.8f, -.5f, -1.5f), .5f, 3, .2f, 20);
            Space.Add(arm);

            shoulder = new Cylinder(body.Position + new Vector3(1.8f, .3f, -1.25f), .1f, .7f, 10);
            shoulder.OrientationMatrix = Matrix3x3.CreateFromAxisAngle(Vector3.Right, MathHelper.PiOver2);
            Space.Add(shoulder);

            //Connect the shoulder to the body.
            axisJoint = new RevoluteJoint(body, shoulder, shoulder.Position, Vector3.Forward);

            //Motorize the connection.
            axisJoint.Motor.IsActive = true;
            axisJoint.Motor.Settings.VelocityMotor.GoalVelocity = 1;

            Space.Add(axisJoint);

            //Connect the arm to the shoulder.
            axisJoint = new RevoluteJoint(shoulder, arm, shoulder.Position + new Vector3(0, .6f, 0), Vector3.Forward);
            Space.Add(axisJoint);

            //Connect the arm to the body.
            pointOnLineJoint = new PointOnLineJoint(arm, body, arm.Position, Vector3.Up, arm.Position + new Vector3(0, -.4f, 0));
            Space.Add(pointOnLineJoint);

            //Add some ground.
            Space.Add(new Box(new Vector3(0, -3.5f, 0), 20f, 1, 20f));

            game.Camera.Position = new Vector3(0, 2, 20);
        }
예제 #4
0
        public static void AddRollingBeats(Scene scene, TransformNode parentTrans)
        {
            Vector3 size     = new Vector3(10.0f, 0.25f, 0.25f);
            Vector3 location = new Vector3(0, 3, 3);

            GeometryNode bar;
            // //////////////////////////////////////////////////////////////////
            //
            // Create a bar and attach it to the world with a hinge with limits
            //
            // //////////////////////////////////////////////////////////////////
            {
                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = location;
                pileTrans.Rotation    = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.PiOver2);

                Material barMat = new Material();
                barMat.Diffuse       = Color.Purple.ToVector4();
                barMat.Specular      = Color.White.ToVector4();
                barMat.SpecularPower = 10;

                bar          = new GeometryNode("Bar");
                bar.Model    = new Cylinder(size.Y, size.Y, size.X, 20);
                bar.Material = barMat;
                bar.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                bar.AddToPhysicsEngine   = true;
                bar.Physics.Interactable = true;
                bar.Physics.Collidable   = true;
                bar.Physics.Shape        = ShapeType.Cylinder;
                bar.Physics.Mass         = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(bar);

                Vector3 pivot = location + parentTrans.Translation;
                Vector3 pin   = Vector3.UnitY;
                pivot.X -= size.X * 0.5f;

                HingeJoint joint = new HingeJoint(pivot, pin);
                joint.NewtonHingeCallback = doubleDoor;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(bar.Physics, null, joint);
            }

            // /////////////////////////////////////////////////////////////////
            //
            // Add a sliding visualObject with limits
            //
            ////////////////////////////////////////////////////////////////////
            {
                Vector3 beatLocation = location;
                Vector3 beatSize     = new Vector3(0.5f, 2.0f, 2.0f);

                beatLocation.X += size.X * 0.25f;

                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = beatLocation;

                Material beatMat = new Material();
                beatMat.Diffuse       = Color.Red.ToVector4();
                beatMat.Specular      = Color.White.ToVector4();
                beatMat.SpecularPower = 10;

                GeometryNode beat = new GeometryNode("Beat Slider");
                beat.Model    = new Box(beatSize);
                beat.Material = beatMat;
                beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                beat.AddToPhysicsEngine   = true;
                beat.Physics.Interactable = true;
                beat.Physics.Collidable   = true;
                beat.Physics.Shape        = ShapeType.Box;
                beat.Physics.Mass         = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(beat);

                Vector3 pivot = beatLocation + parentTrans.Translation;
                Vector3 pin   = Vector3.UnitX;

                sliderLimit.X = ((location.X - beatLocation.X) - size.X * 0.5f);
                sliderLimit.Y = ((location.X - beatLocation.X) + size.X * 0.5f);

                SliderJoint joint = new SliderJoint(pivot, pin);
                sliderUpdate = delegate(IntPtr slider, ref Newton.NewtonHingeSliderUpdateDesc desc)
                {
                    float distance = Newton.NewtonSliderGetJointPosit(slider);
                    if (distance < sliderLimit.X)
                    {
                        // if the distance is smaller than the predefine interval, stop the slider
                        desc.m_Accel = Newton.NewtonSliderCalculateStopAccel(slider, ref desc, sliderLimit.X);
                        return(1);
                    }
                    else if (distance > sliderLimit.Y)
                    {
                        // if the distance is larger than the predefine interval, stop the slider
                        desc.m_Accel = Newton.NewtonSliderCalculateStopAccel(slider, ref desc, sliderLimit.Y);
                        return(1);
                    }

                    // no action need it if the joint angle is with the limits
                    return(0);
                };
                joint.NewtonSliderCallback = sliderUpdate;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint);
            }

            // /////////////////////////////////////////////////////////////////
            //
            // Add a corkscrew visualObject with limits
            //
            // /////////////////////////////////////////////////////////////////
            {
                Vector3 beatLocation = location;
                Vector3 beatSize     = new Vector3(0.5f, 2.0f, 2.0f);

                beatLocation.X -= size.X * 0.25f;

                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = beatLocation;

                Material beatMat = new Material();
                beatMat.Diffuse       = Color.YellowGreen.ToVector4();
                beatMat.Specular      = Color.White.ToVector4();
                beatMat.SpecularPower = 10;

                GeometryNode beat = new GeometryNode("Beat Corkscrew");
                beat.Model    = new Box(beatSize);
                beat.Material = beatMat;
                beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                beat.AddToPhysicsEngine   = true;
                beat.Physics.Interactable = true;
                beat.Physics.Collidable   = true;
                beat.Physics.Shape        = ShapeType.Box;
                beat.Physics.Mass         = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(beat);

                Vector3 pivot = beatLocation + parentTrans.Translation;
                Vector3 pin   = Vector3.UnitX;

                corkscrewLimit.X = ((location.X - beatLocation.X) - size.X * 0.5f);
                corkscrewLimit.Y = ((location.X - beatLocation.X) + size.X * 0.5f);

                CorkscrewJoint joint = new CorkscrewJoint(pivot, pin);
                corkscrewUpdate = delegate(IntPtr corkscrew, Newton.NewtonHingeSliderUpdateDesc[] desc)
                {
                    // no action need it if the joint angle is with the limits
                    uint retCode = 0;

                    float distance = Newton.NewtonCorkscrewGetJointPosit(corkscrew);

                    // The first entry in NewtonHingeSliderUpdateDesc control the screw linear acceleration
                    if (distance < corkscrewLimit.X)
                    {
                        // if the distance is smaller than the predefine interval, stop the slider
                        desc[0].m_Accel = Newton.NewtonCorkscrewCalculateStopAccel(corkscrew,
                                                                                   ref desc[0], corkscrewLimit.X);
                        retCode |= 1;
                    }
                    else if (distance > corkscrewLimit.Y)
                    {
                        // if the distance is larger than the predefine interval, stop the slider
                        desc[0].m_Accel = Newton.NewtonCorkscrewCalculateStopAccel(corkscrew, ref
                                                                                   desc[0], corkscrewLimit.Y);
                        retCode |= 1;
                    }

                    // The second entry in NewtonHingeSliderUpdateDesc control the screw angular acceleration.
                    // Make s small screw motor by setting the angular acceleration of the screw axis
                    // We are not going to limit the angular rotation of the screw, but is we did we should
                    // or return code with 2
                    float omega = Newton.NewtonCorkscrewGetJointOmega(corkscrew);
                    desc[1].m_Accel = 1.5f - 0.2f * omega;

                    // or with 0x10 to tell newton this axis is active
                    retCode |= 2;

                    // return the code
                    return(retCode);
                };
                joint.NewtonCorkscrewCallback = corkscrewUpdate;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint);
            }

            // /////////////////////////////////////////////////////////////////
            //
            // Add a universal joint visualObject with limits
            //
            // /////////////////////////////////////////////////////////////////
            {
                Vector3 beatLocation = location;
                Vector3 beatSize     = new Vector3(0.5f, 2.0f, 2.0f);

                beatLocation.X -= size.X * 0.45f;

                TransformNode pileTrans = new TransformNode();
                pileTrans.Translation = beatLocation;

                Material beatMat = new Material();
                beatMat.Diffuse       = Color.YellowGreen.ToVector4();
                beatMat.Specular      = Color.White.ToVector4();
                beatMat.SpecularPower = 10;

                GeometryNode beat = new GeometryNode("Beat Universal");
                beat.Model    = new Box(beatSize);
                beat.Material = beatMat;
                beat.Model.ShadowAttribute = ShadowAttribute.ReceiveCast;

                beat.AddToPhysicsEngine   = true;
                beat.Physics.Interactable = true;
                beat.Physics.Collidable   = true;
                beat.Physics.Shape        = ShapeType.Box;
                beat.Physics.Mass         = 2.0f;

                parentTrans.AddChild(pileTrans);
                pileTrans.AddChild(beat);

                Vector3 pivot = beatLocation + parentTrans.Translation;
                Vector3 pin0  = Vector3.UnitX;
                Vector3 pin1  = Vector3.UnitY;

                universalLimit.X = -30.0f * MathHelper.Pi / 180.0f;
                universalLimit.Y = 30.0f * MathHelper.Pi / 180.0f;

                UniversalJoint joint = new UniversalJoint(pivot, pin0, pin1);
                universalUpdate = delegate(IntPtr universal, Newton.NewtonHingeSliderUpdateDesc[] desc)
                {
                    // no action need it if the joint angle is with the limits
                    uint retCode = 0;

                    float omega = Newton.NewtonUniversalGetJointOmega0(universal);
                    desc[0].m_Accel = -1.5f - 0.2f * omega;
                    retCode        |= 1;

                    float angle = Newton.NewtonUniversalGetJointAngle1(universal);
                    if (angle < universalLimit.X)
                    {
                        desc[1].m_Accel = Newton.NewtonUniversalCalculateStopAlpha1(universal, ref desc[1],
                                                                                    universalLimit.X);
                        retCode |= 2;
                    }
                    else if (angle > universalLimit.Y)
                    {
                        desc[1].m_Accel = Newton.NewtonUniversalCalculateStopAlpha1(universal, ref desc[1],
                                                                                    universalLimit.Y);
                        retCode |= 2;
                    }

                    // return the code
                    return(retCode);
                };
                joint.NewtonUniversalCallback = universalUpdate;

                ((NewtonPhysics)scene.PhysicsEngine).CreateJoint(beat.Physics, bar.Physics, joint);
            }
        }
예제 #5
0
        public ICollisionJoint[] LoadSimulationJoints(
            ICollisionShape[] objects)
        {
            var xmlDoc = new XmlDocument();

            xmlDoc.Load(FileNameObjectProperties);

            XmlNodeList xmlList = xmlDoc.SelectNodes(nodePathJoints);

            ICollisionJoint[] joints = new ICollisionJoint[xmlList.Count];

            for (int i = 0; i < xmlList.Count; i++)
            {
                //Object index A
                int indexA = Convert.ToInt32(xmlList[i][objectIndexAAttribute].InnerText);

                //Object index B
                int indexB = Convert.ToInt32(xmlList[i][objectIndexBAttribute].InnerText);

                XmlNodeList jointPropertiesList = xmlList[i].SelectNodes(jointProperties);

                ICollisionJoint[] joint = new ICollisionJoint[jointPropertiesList.Count];

                for (int j = 0; j < jointPropertiesList.Count; j++)
                {
                    //Joint type
                    var jointType = (JointType)Convert.ToInt32(jointPropertiesList[j][this.jointType].InnerText);

                    //Restore coefficient
                    double K = Convert.ToDouble(jointPropertiesList[j][restoreCoeffAttribute].InnerText);

                    //Stretch coefficient
                    double C = Convert.ToDouble(jointPropertiesList[j][stretchCoeffAttribute].InnerText);

                    //Position
                    var startAnchorPosition = new Vector3d(
                        Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["x"].Value),
                        Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["y"].Value),
                        Convert.ToDouble(jointPropertiesList[j][positionJointAttribute].Attributes["z"].Value));

                    //Action Axis
                    var actionAxis = new Vector3d(
                        Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["x"].Value),
                        Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["y"].Value),
                        Convert.ToDouble(jointPropertiesList[j][this.actionAxis].Attributes["z"].Value));

                    switch (jointType)
                    {
                    case JointType.Fixed:
                        joint [j] = new FixedJoint(
                            objects[indexA],
                            objects[indexB],
                            K,
                            C);
                        break;

                    case JointType.BallAndSocket:
                        joint[j] = new BallAndSocketJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            K,
                            C);
                        break;

                    case JointType.Slider:
                        joint[j] = new SliderJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            K,
                            C);

                        joint[j].SetLinearLimit(Convert.ToDouble(jointPropertiesList[j][linearLimitMin].InnerText), Convert.ToDouble(jointPropertiesList[j][linearLimitMax].InnerText));

                        break;

                    case JointType.Piston:
                        joint[j] = new PistonJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            K,
                            C);

                        joint[j].SetAxis1AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));

                        joint[j].SetLinearLimit(
                            Convert.ToDouble(jointPropertiesList[j][linearLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][linearLimitMax].InnerText));

                        break;

                    case JointType.Hinge:
                        joint[j] = new HingeJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            K,
                            C);

                        joint[j].SetAxis1AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));

                        joint[j].SetAxis1Motor(3.0, 0.15);
                        break;

                    case JointType.Universal:
                        joint[j] = new UniversalJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            new Vector3d(1.0, 0.0, 0.0),
                            K,
                            C);

                        joint[j].SetAxis1AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));
                        joint[j].SetAxis2AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));
                        break;

                    case JointType.Hinge2:
                        joint[j] = new Hinge2Joint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            actionAxis,
                            new Vector3d(1.0, 0.0, 0.0),
                            K,
                            1.0,
                            C);

                        joint[j].SetAxis1AngularLimit(
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMin].InnerText),
                            Convert.ToDouble(jointPropertiesList[j][angularLimitMax].InnerText));

                        //joint[j].SetAxis2Motor(4.0, 3.0);

                        break;

                    case JointType.Angular:
                        joint[j] = new AngularJoint(
                            objects[indexA],
                            objects[indexB],
                            startAnchorPosition,
                            new Vector3d(1.0, 0.0, 0.0),
                            new Vector3d(0.0, 1.0, 0.0),
                            0.16,
                            0.008,
                            0.008);

                        break;
                    }
                    joints[i] = joint[j];
                }
            }

            return(joints);
        }