Ejemplo n.º 1
0
        public bool reportFixture(Fixture fixture)
        {
            if (m_count == e_maxCount)
            {
                return false;
            }

            Body body = fixture.getBody();
            Shape shape = fixture.getShape();

            bool overlap = p.getCollision().testOverlap(shape, 0, m_circle, 0, body.getTransform(),
                m_transform);

            if (overlap)
            {
                DrawFixture(fixture);
                ++m_count;
            }

            return true;
        }
Ejemplo n.º 2
0
        private void DrawFixture(Fixture fixture)
        {
            Color4f color = new Color4f(0.95f, 0.95f, 0.6f);
            Transform xf = fixture.getBody().getTransform();

            switch (fixture.getType())
            {
                case ShapeType.CIRCLE:
                {
                    CircleShape circle = (CircleShape) fixture.getShape();

                    Vec2 center = Transform.mul(xf, circle.m_p);
                    float radius = circle.m_radius;

                    debugDraw.drawCircle(center, radius, color);
                }
                    break;

                case ShapeType.POLYGON:
                {
                    PolygonShape poly = (PolygonShape) fixture.getShape();
                    int vertexCount = poly.m_count;
                    Debug.Assert(vertexCount <= Settings.maxPolygonVertices);
                    Vec2[] vertices = new Vec2[Settings.maxPolygonVertices];

                    for (int i = 0; i < vertexCount; ++i)
                    {
                        vertices[i] = Transform.mul(xf, poly.m_vertices[i]);
                    }

                    debugDraw.drawPolygon(vertices, vertexCount, color);
                }
                    break;
                default:
                    break;
            }
        }
Ejemplo n.º 3
0
        private void drawShape(Fixture fixture, Transform xf, Color4f color, bool wireframe)
        {
            switch (fixture.getType())
            {
                case ShapeType.CIRCLE:
                {
                    CircleShape circle = (CircleShape) fixture.getShape();

                    // Vec2 center = Mul(xf, circle.m_p);
                    Transform.mulToOutUnsafe(xf, circle.m_p, ref center);
                    float radius = circle.m_radius;
                    xf.q.getXAxis(axis);

                    if (fixture.getUserData() != null && fixture.getUserData().Equals(LIQUID_INT))
                    {
                        Body b = fixture.getBody();
                        liquidOffset.set(b.m_linearVelocity);
                        float linVelLength = b.m_linearVelocity.length();
                        if (averageLinearVel == -1)
                        {
                            averageLinearVel = linVelLength;
                        }
                        else
                        {
                            averageLinearVel = .98f*averageLinearVel + .02f*linVelLength;
                        }
                        liquidOffset.mulLocal(liquidLength/averageLinearVel/2);
                        circCenterMoved.set(center);
                        circCenterMoved.addLocal(liquidOffset);
                        center.subLocal(liquidOffset);
                        m_debugDraw.drawSegment(center, circCenterMoved, liquidColor);
                        return;
                    }
                    if (wireframe)
                    {
                        m_debugDraw.drawCircle(center, radius, axis, color);
                    }
                    else
                    {
                        m_debugDraw.drawSolidCircle(center, radius, axis, color);
                    }
                }
                    break;

                case ShapeType.POLYGON:
                {
                    PolygonShape poly = (PolygonShape) fixture.getShape();
                    int vertexCount = poly.m_count;
                    Debug.Assert(vertexCount <= Settings.maxPolygonVertices);
                    Vec2[] vertices = tlvertices.get(Settings.maxPolygonVertices);

                    for (int i = 0; i < vertexCount; ++i)
                    {
                        // vertices[i] = Mul(xf, poly.m_vertices[i]);
                        Transform.mulToOutUnsafe(xf, poly.m_vertices[i], ref vertices[i]);
                    }
                    if (wireframe)
                    {
                        m_debugDraw.drawPolygon(vertices, vertexCount, color);
                    }
                    else
                    {
                        m_debugDraw.drawSolidPolygon(vertices, vertexCount, color);
                    }
                }
                    break;
                case ShapeType.EDGE:
                {
                    EdgeShape edge = (EdgeShape) fixture.getShape();
                    Transform.mulToOutUnsafe(xf, edge.m_vertex1, ref v1);
                    Transform.mulToOutUnsafe(xf, edge.m_vertex2, ref v2);
                    m_debugDraw.drawSegment(v1, v2, color);
                }
                    break;
                case ShapeType.CHAIN:
                {
                    ChainShape chain = (ChainShape) fixture.getShape();
                    int count = chain.m_count;
                    Vec2[] vertices = chain.m_vertices;

                    Transform.mulToOutUnsafe(xf, vertices[0], ref v1);
                    for (int i = 1; i < count; ++i)
                    {
                        Transform.mulToOutUnsafe(xf, vertices[i], ref v2);
                        m_debugDraw.drawSegment(v1, v2, color);
                        m_debugDraw.drawCircle(v1, 0.05f, color);
                        v1.set(v2);
                    }
                }
                    break;
                default:
                    break;
            }
        }