Пример #1
0
 // Use this for initialization
 protected override IntPtr Init()
 {
     DistanceJointDef jd = new DistanceJointDef(other.body, body.body);
     jd.Initialize(other.body,body.body,anchor1, anchor2);
     jd.frequencyHz = frequencyHz;
     jd.dampingRatio = dampingRatio;
     return API.CreateDistanceJoint( B2DWorld.instance.world, jd );
 }
Пример #2
0
 public static extern IntPtr CreateDistanceJoint( IntPtr w, DistanceJointDef def );
Пример #3
0
 public static extern IntPtr CreateDistanceJoint(IntPtr w, DistanceJointDef def);
Пример #4
0
    void CreateLeg(float s, Vector2 wheelAnchor)
    {
        Vector2 p1 = new Vector2(5.4f * s, -6.1f);
        Vector2 p2 = new Vector2(7.2f * s, -1.2f);
        Vector2 p3 = new Vector2(4.3f * s, -1.9f);
        Vector2 p4 = new Vector2(3.1f * s, 0.8f);
        Vector2 p5 = new Vector2(6.0f * s, 1.5f);
        Vector2 p6 = new Vector2(2.5f * s, 3.7f);

        ShapeDef sp = new ShapeDef(1.0f);
        sp.groupIndex = -1;
        Vector2[] vertices1 = new Vector2[3];
        Vector2[] vertices2 = new Vector2[3];
        if( s > 0.0f )
        {
            vertices1[0] = p1;
            vertices1[1] = p2;
            vertices1[2] = p3;

            vertices2[0] = Vector2.zero;
            vertices2[1] = p5-p4;
            vertices2[2] = p6-p4;
        }
        else
        {
            vertices1[0] = p1;
            vertices1[1] = p3;
            vertices1[2] = p2;

            vertices2[0] = Vector2.zero;
            vertices2[1] = p6-p4;
            vertices2[2] = p5-p4;
        }

        BodyDef bd1 = new BodyDef(BodyType.DYNAMIC_BODY);
        BodyDef bd2 = new BodyDef(BodyType.DYNAMIC_BODY);
        bd1.position = m_offset;
        bd2.position = p4 + m_offset;

        bd1.angularDamping = 10.0f;
        bd2.angularDamping = 10.0f;

        var body1 = API.CreateBody(world,bd1);
        var body2 = API.CreateBody(world,bd2);
        API.AddPolygonShape(body1, vertices1,vertices1.Length,sp);
        API.AddPolygonShape(body2, vertices2,vertices2.Length,sp);

        DistanceJointDef djd = new DistanceJointDef();
        djd.dampingRatio = 0.5f;
        djd.frequencyHz = 10.0f;

        djd.Initialize(body1,body2,p2+m_offset, p5+m_offset);
        API.CreateDistanceJoint(world, djd );

        djd.Initialize(body1, body2, p3 + m_offset, p4 + m_offset);
        API.CreateDistanceJoint(world, djd );

        djd.Initialize(body1, m_wheel, p3 + m_offset, wheelAnchor + m_offset);
        API.CreateDistanceJoint(world, djd );

        djd.Initialize(body2, m_wheel, p6 + m_offset, wheelAnchor + m_offset);
        API.CreateDistanceJoint(world, djd );

        RevoluteJointDef rjd = new RevoluteJointDef();
        rjd.Initialize(body2, m_chassis,p4+m_offset);
        API.CreateRevoluteJoint(world,rjd);
    }