Beispiel #1
0
        public LineJoint()
        {
            Body ground = null;
            {
                PolygonShape shape = new PolygonShape();
                shape.SetAsEdge(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));

                BodyDef bd = new BodyDef();
                ground = m_world.CreateBody(bd);
                ground.CreateFixture(shape, 0.0f);
            }

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

                BodyDef bd = new BodyDef();
                bd.BodyType = BodyType.Dynamic;
                bd.Position = new Vec2(0.0f, 7.0f);
                Body body = m_world.CreateBody(bd);
                body.CreateFixture(shape, 1.0f);

                LineJointDef jd = new LineJointDef();
                Vec2 axis = new Vec2(2.0f, 1.0f);
                axis.Normalize();
                jd.Initialize(ground, body, new Vec2(0.0f, 8.5f), axis);
                jd.MotorSpeed = 0.0f;
                jd.MaxMotorForce = 100.0f;
                jd.EnableMotor = true;
                jd.LowerTranslation = -4.0f;
                jd.UpperTranslation = 4.0f;
                jd.EnableLimit = true;
                m_world.CreateJoint(jd);
            }
        }
Beispiel #2
0
        public Prismatic()
        {
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = m_world.CreateBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.SetAsEdge(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.CreateFixture(shape, 0.0f);
            }

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

                BodyDef bd = new BodyDef();
                bd.BodyType = BodyType.Dynamic;
                bd.Position = new Vec2(-10.0f, 10.0f);
                bd.Angle = 0.5f * (float)Math.PI;
                bd.AllowSleep = false;
                Body body = m_world.CreateBody(bd);
                body.CreateFixture(shape, 5.0f);

                PrismaticJointDef pjd = new PrismaticJointDef();

                // Bouncy limit
                Vec2 axis = new Vec2(2.0f, 1.0f);
                axis.Normalize();
                pjd.Initialize(ground, body, new Vec2(0.0f, 0.0f), axis);

                // Non-bouncy limit
                //pjd.Initialize(ground, body, new Vec2(-10.0f, 10.0f), new Vec2(1.0f, 0.0f));

                pjd.MotorSpeed = 10.0f;
                pjd.MaxMotorForce = 10000.0f;
                pjd.EnableMotor = true;
                pjd.LowerTranslation = 0.0f;
                pjd.UpperTranslation = 20.0f;
                pjd.EnableLimit = false;

                m_joint = (PrismaticJoint)m_world.CreateJoint(pjd);
            }
        }