Пример #1
0
        internal PulleyJoint(IWorldPool argWorldPool, PulleyJointDef def)
            : base(argWorldPool, def)
        {
            m_groundAnchorA.set(def.groundAnchorA);
            m_groundAnchorB.set(def.groundAnchorB);
            m_localAnchorA.set(def.localAnchorA);
            m_localAnchorB.set(def.localAnchorB);

            Debug.Assert(def.ratio != 0.0f);
            m_ratio = def.ratio;

            m_lengthA = def.lengthA;
            m_lengthB = def.lengthB;

            m_constant = def.lengthA + m_ratio*def.lengthB;
            m_impulse = 0.0f;
        }
Пример #2
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }
            float y = 16.0f;
            float L = 12.0f;
            float a = 1.0f;
            float b = 2.0f;
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);

                CircleShape circle = new CircleShape();
                circle.m_radius = 2.0f;

                circle.m_p.set(-10.0f, y + b + L);
                ground.createFixture(circle, 0.0f);

                circle.m_p.set(10.0f, y + b + L);
                ground.createFixture(circle, 0.0f);
            }

            {

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(a, b);

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;

                bd.position.set(-10.0f, y);
                Body body1 = getWorld().createBody(bd);
                body1.createFixture(shape, 5.0f);

                bd.position.set(10.0f, y);
                Body body2 = getWorld().createBody(bd);
                body2.createFixture(shape, 5.0f);

                PulleyJointDef pulleyDef = new PulleyJointDef();
                Vec2 anchor1 = new Vec2(-10.0f, y + b);
                Vec2 anchor2 = new Vec2(10.0f, y + b);
                Vec2 groundAnchor1 = new Vec2(-10.0f, y + b + L);
                Vec2 groundAnchor2 = new Vec2(10.0f, y + b + L);
                pulleyDef.initialize(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, 2.0f);

                m_joint1 = (PulleyJoint) getWorld().createJoint(pulleyDef);
            }
        }