Beispiel #1
0
    private void testQueryAABB()
    {
        Vector3 mousePos        = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        b2WorldQueryCallback cb = delegate(b2Fixture fixture) {
            b2Body body = fixture.GetBody();
            body.SetAwake(true);
            return(true);
        };

        float  w    = 200 / ptm_ratio;
        float  h    = 200 / ptm_ratio;
        b2AABB aabb = b2AABB.MakeWH(w, h, mousePos.x, mousePos.y);

        _world.QueryAABB(cb, aabb);

        b2Vec2[] vertices = new b2Vec2[] {
            new b2Vec2(aabb.lowerBound.x, aabb.lowerBound.y),
            new b2Vec2(aabb.upperBound.x, aabb.lowerBound.y),
            new b2Vec2(aabb.upperBound.x, aabb.upperBound.y),
            new b2Vec2(aabb.lowerBound.x, aabb.upperBound.y)
        };
        b2Color color = new b2Color(1.0f, 0.0f, 0.0f);

        _debugDraw.DrawPolygon(vertices, vertices.Length, color);
    }
Beispiel #2
0
    private void testQueryShape_poly()
    {
        Vector3 mousePos        = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        b2WorldQueryCallback cb = delegate(b2Fixture fixture) {
            b2Body body = fixture.GetBody();
            body.SetAwake(true);
            return(true);
        };

        b2Vec2[] vertices = new b2Vec2[4];
        vertices [0] = new b2Vec2(-100.0f / ptm_ratio, 0.0f / ptm_ratio);
        vertices [1] = new b2Vec2(0.0f / ptm_ratio, 100.0f / ptm_ratio);
        vertices [2] = new b2Vec2(100.0f / ptm_ratio, 0.0f / ptm_ratio);
        vertices [3] = new b2Vec2(0.0f / ptm_ratio, -200.0f / ptm_ratio);
        b2PolygonShape shape = b2PolygonShape.AsArray(vertices, vertices.Length);

        b2Transform transform = new b2Transform(new b2Vec2(mousePos.x, mousePos.y), b2Mat22.FromAngle(0));

        _world.QueryShape(cb, shape, transform);

        for (int i = 0; i < vertices.Length; i++)
        {
            vertices[i].x += mousePos.x;
            vertices[i].y += mousePos.y;
        }
        b2Color color = new b2Color(1.0f, 0.0f, 0.0f);

        _debugDraw.DrawPolygon(vertices, vertices.Length, color);
    }
Beispiel #3
0
        /**返回位置下的刚体*/
        private b2Body getPosBody(float x, float y)
        {
            b2Body b = null;

            b2WorldQueryCallback cb = delegate(b2Fixture fixture) {
                b = fixture.GetBody();
                return(false);
            };

            _world.QueryPoint(cb, new b2Vec2(x, y));
            return(b);
        }
Beispiel #4
0
    private void testQueryShape_circle()
    {
        Vector3 mousePos        = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        b2WorldQueryCallback cb = delegate(b2Fixture fixture) {
            b2Body body = fixture.GetBody();
            body.SetAwake(true);
            return(true);
        };

        b2CircleShape shape = new b2CircleShape(200.0f / ptm_ratio);

        b2Transform transform = new b2Transform(new b2Vec2(mousePos.x, mousePos.y), b2Mat22.FromAngle(0));

        _world.QueryShape(cb, shape, transform);

        b2Color color = new b2Color(1.0f, 0.0f, 0.0f);

        _debugDraw.DrawCircle(new b2Vec2(mousePos.x, mousePos.y), 200.0f / ptm_ratio, color);
    }