private LineJointTest()
        {
            Body ground;
            {
                ground = BodyFactory.CreateBody(World);

                Vertices edge = PolygonTools.CreateEdge(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));
                PolygonShape shape = new PolygonShape(edge, 0);
                ground.CreateFixture(shape);
            }

            //-------------------------
            // FixedLineJoint example
            //-------------------------
            {
                PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 2.0f), 1);
                Body body = BodyFactory.CreateBody(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(0.0f, 7.0f);
                body.CreateFixture(shape);

                Vector2 axis = new Vector2(2.0f, 1.0f);
                axis.Normalize();

                _fixedLineJoint = new FixedLineJoint(body, new Vector2(0.0f, 8.5f), axis);
                _fixedLineJoint.MotorSpeed = 100.0f;
                _fixedLineJoint.MaxMotorForce = 100.0f;
                _fixedLineJoint.MotorEnabled = false;
                _fixedLineJoint.LowerLimit = -4.0f;
                _fixedLineJoint.UpperLimit = 4.0f;
                _fixedLineJoint.EnableLimit = true;
                World.AddJoint(_fixedLineJoint);
            }

            //-------------------------
            // LineJoint example
            //-------------------------
            {
                PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(0.5f, 2.0f), 1);
                Body body = BodyFactory.CreateBody(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(10.0f, 7.0f);
                body.CreateFixture(shape);

                Vector2 axis = new Vector2(2.0f, 1.0f);
                axis.Normalize();

                Vector2 anchor = new Vector2(0.0f, 1.5f);
                _lineJoint = new LineJoint(ground, body, ground.GetLocalPoint(body.GetWorldPoint(anchor)), anchor, axis);
                _lineJoint.MotorSpeed = 100.0f;
                _lineJoint.MaxMotorForce = 100.0f;
                _lineJoint.MotorEnabled = false;
                _lineJoint.LowerLimit = -4.0f;
                _lineJoint.UpperLimit = 4.0f;
                _lineJoint.EnableLimit = true;
                World.AddJoint(_lineJoint);
            }
        }
Пример #2
0
        private LineJointTest()
        {
            Body ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            {
                PolygonShape shape = new PolygonShape(1);
                shape.SetAsBox(0.5f, 2.0f);

                Body body = new Body(World);
                body.BodyType = BodyType.Dynamic;
                body.Position = new Vector2(0.0f, 7.0f);
                
                body.CreateFixture(shape);

                Vector2 axis = new Vector2(-1000.0f, -2.0f);
                axis.Normalize();

                LineJoint jd = new LineJoint(ground, body, new Vector2(0, 8.5f), axis);
                jd.MotorSpeed = 1.0f;
                jd.MaxMotorTorque = 1000.0f;
                jd.MotorEnabled = true;
                jd.Frequency = 1.0f;
                jd.DampingRatio = 0.2f;
                World.AddJoint(jd);

                PolygonShape shape2 = new PolygonShape(1);
                shape2.SetAsBox(0.5f, 2.0f);
                Body body2 = BodyFactory.CreatePolygon(World, shape2.Vertices, 0.5f);
                body2.BodyType = BodyType.Dynamic;
                body2.Position = new Vector2(10.0f, 7.0f);

                FixedLineJoint jdf = new FixedLineJoint(body2, new Vector2(10, 8.5f), axis);
                jdf.MotorSpeed = 1.0f;
                jdf.MaxMotorTorque = 1000.0f;
                jdf.MotorEnabled = true;
                jdf.Frequency = 1.0f;
                jdf.DampingRatio = 0.2f;
                World.AddJoint(jdf);
            }
        }