示例#1
0
 public void set(Color4f color)
 {
     r = (byte) (255*color.x);
     g = (byte) (255*color.y);
     b = (byte) (255*color.z);
     a = (byte) 255;
 }
示例#2
0
 public override void drawParticlesWireframe(Vec2[] centers, float radius, ParticleColor[] colors, int count)
 {
     Color4f pcolorA = new Color4f(1f, 1f, 1f);
     for (int i = 0; i < count; i++)
     {
         Vec2 center = centers[i];
         Color4f color;
         if (colors == null)
         {
             color = pcolorA;
         }
         else
         {
             ParticleColor c = colors[i];
             color = new Color4f(c.r * 1f / 127, c.g * 1f / 127, c.b * 1f / 127, c.a * 1f / 127);
         }
         drawCircle(center, radius, color);
     }
 }
示例#3
0
        public override void drawCircle(Vec2 center, float radius, Color4f color)
        {
            int segments = 16;
            double increment = Math.PI * 2.0 / (double)segments;
            double theta = 0.0;

            Color xnaColor = new Color(color.x, color.y, color.z, color.w);

            for (int i = 0; i < segments; i++)
            {
                Vector2 v1 = new Vector2(center.x, center.y) + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));
                Vector2 v2 = new Vector2(center.x, center.y) + radius * new Vector2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment));

                _vertsLines[_lineCount * 2].Position = new Vector3(v1, 0.0f);
                _vertsLines[_lineCount * 2].Color = xnaColor;
                _vertsLines[_lineCount * 2 + 1].Position = new Vector3(v2, 0.0f);
                _vertsLines[_lineCount * 2 + 1].Color = xnaColor;
                _lineCount++;

                theta += increment;
            }
        }
示例#4
0
        /**
           * Draw a closed polygon provided in CCW order. This implementation uses
           * {@link #drawSegment(Vec2, Vec2, Color4f)} to draw each side of the polygon.
           *
           * @param vertices
           * @param vertexCount
           * @param color
           */
        public void drawPolygon(Vec2[] vertices, int vertexCount, Color4f color)
        {
            if (vertexCount == 1)
            {
                drawSegment(vertices[0], vertices[0], color);
                return;
            }

            for (int i = 0; i < vertexCount - 1; i += 1)
            {
                drawSegment(vertices[i], vertices[i + 1], color);
            }

            if (vertexCount > 2)
            {
                drawSegment(vertices[vertexCount - 1], vertices[0], color);
            }
        }
示例#5
0
 /**
    * Draw a line segment.
    *
    * @param p1
    * @param p2
    * @param color
    */
 public abstract void drawSegment(Vec2 p1, Vec2 p2, Color4f color);
示例#6
0
 /** Draws a circle with an axis */
 public void drawCircle(Vec2 center, float radius, Vec2 axis, Color4f color)
 {
     drawCircle(center, radius, color);
 }
示例#7
0
 public abstract void drawPoint(Vec2 argPoint, float argRadiusOnScreen, Color4f argColor);
示例#8
0
 public ParticleColor(Color4f color)
 {
     set(color);
 }
示例#9
0
 /**
    * Draw a circle.
    *
    * @param center
    * @param radius
    * @param color
    */
 public abstract void drawCircle(Vec2 center, float radius, Color4f color);
示例#10
0
 /**
    * Draw a string.
    *
    * @param x
    * @param y
    * @param s
    * @param color
    */
 public abstract void drawString(float x, float y, string s, Color4f color);
示例#11
0
 public override void drawSegment(Vec2 p1, Vec2 p2, Color4f color)
 {
     Color xnaColor = new Color(color.x, color.y, color.z);
     _vertsLines[_lineCount * 2].Position = new Vector3(p1.x, p1.y, 0.0f);
     _vertsLines[_lineCount * 2 + 1].Position = new Vector3(p2.x, p2.y, 0.0f);
     _vertsLines[_lineCount * 2].Color = _vertsLines[_lineCount * 2 + 1].Color = xnaColor;
     _lineCount++;
 }
示例#12
0
        private void DrawSolidPolygon(Vec2[] vertices, int count, Color4f color, bool outline)
        {
            if (count == 2)
            {
                drawPolygon(vertices, count, color);
                return;
            }

            Color colorFill = new Color(color.x, color.y, color.z) * (outline ? 0.5f : 1.0f);

            for (int i = 1; i < count - 1; i++)
            {
                _vertsFill[_fillCount * 3].Position = new Vector3(vertices[0].x, vertices[0].y, 0.0f);
                _vertsFill[_fillCount * 3].Color = colorFill;

                _vertsFill[_fillCount * 3 + 1].Position = new Vector3(vertices[i].x, vertices[i].y, 0.0f);
                _vertsFill[_fillCount * 3 + 1].Color = colorFill;

                _vertsFill[_fillCount * 3 + 2].Position = new Vector3(vertices[i+1].x, vertices[i+1].y, 0.0f);
                _vertsFill[_fillCount * 3 + 2].Color = colorFill;

                _fillCount++;
            }

            if (outline)
            {
                drawPolygon(vertices, count, color);
            }
        }
示例#13
0
 public StringData(float x, float y, string s, Color4f color)
 {
     this.x = x;
     this.y = y;
     this.s = s;
     this.color = new Color(color.x, color.y, color.z, color.w);
 }
示例#14
0
 public override void drawString(float x, float y, string s, Color4f color)
 {
     _stringData.Add(new StringData(x, y, s, color));
 }
示例#15
0
 public override void drawSolidPolygon(Vec2[] vertices, int count, Color4f color)
 {
     DrawSolidPolygon(vertices, count, color, true);
 }
示例#16
0
        public override void drawSolidCircle(Vec2 center, float radius, Vec2 axis, Color4f color)
        {
            int segments = 16;
            double increment = Math.PI * 2.0 / (double)segments;
            double theta = 0.0;

            Color colorFill = new Color(color.x,color.y, color.z) * 0.5f;

            Vector2 v0 = new Vector2(center.x, center.y) + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));
            theta += increment;

            for (int i = 1; i < segments - 1; i++)
            {
                Vector2 v1 = new Vector2(center.x, center.y) + radius * new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta));
                Vector2 v2 = new Vector2(center.x, center.y) + radius * new Vector2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment));

                _vertsFill[_fillCount * 3].Position = new Vector3(v0, 0.0f);
                _vertsFill[_fillCount * 3].Color = colorFill;

                _vertsFill[_fillCount * 3 + 1].Position = new Vector3(v1, 0.0f);
                _vertsFill[_fillCount * 3 + 1].Color = colorFill;

                _vertsFill[_fillCount * 3 + 2].Position = new Vector3(v2, 0.0f);
                _vertsFill[_fillCount * 3 + 2].Color = colorFill;

                _fillCount++;

                theta += increment;
            }
            drawCircle(center, radius, color);

            if (axis != zero)
                drawSegment(center,  center.add(axis).mul(radius), color);
        }
示例#17
0
 /**
    * Draw a solid circle.
    *
    * @param center
    * @param radius
    * @param axis
    * @param color
    */
 public abstract void drawSolidCircle(Vec2 center, float radius, Vec2 axis, Color4f color);
示例#18
0
        /**
           * @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.TestbedSettings)
           */
        public override void step(TestbedSettings settings)
        {
            base.step(settings);

            PolyShapesCallback callback = new PolyShapesCallback(getWorld().getPool());
            callback.m_circle.m_radius = 2.0f;
            callback.m_circle.m_p.set(0.0f, 2.1f);
            callback.m_transform.setIdentity();
            callback.debugDraw = getDebugDraw();

            AABB aabb = new AABB();
            callback.m_circle.computeAABB(aabb, callback.m_transform, 0);

            getWorld().queryAABB(callback, aabb);

            Color4f color = new Color4f(0.4f, 0.7f, 0.8f);
            getDebugDraw().drawCircle(callback.m_circle.m_p, callback.m_circle.m_radius, color);

            addTextLine("Press 1-5 to drop stuff");
            addTextLine("Press 'a' to (de)activate some bodies");
            addTextLine("Press 'd' to destroy a body");
            addTextLine("Up to 30 bodies in the target circle are highlighted");
        }
示例#19
0
 /**
    * Draw a solid closed polygon provided in CCW order.
    *
    * @param vertices
    * @param vertexCount
    * @param color
    */
 public abstract void drawSolidPolygon(Vec2[] vertices, int vertexCount, Color4f color);
示例#20
0
        public override void drawPoint(Vec2 p, float size, Color4f color)
        {
            Vec2[] verts = new Vec2[4];
            float hs = size / 2.0f;
            verts[0] = p.add(new Vec2(-hs, -hs));
            verts[1] = p.add(new Vec2(hs, -hs));
            verts[2] = p.add(new Vec2(hs, hs));
            verts[3] = p.add(new Vec2(-hs, hs));

            DrawSolidPolygon(verts, 4, color, true);
        }
示例#21
0
 public void drawString(Vec2 pos, string s, Color4f color)
 {
     drawString(pos.x, pos.y, s, color);
 }
示例#22
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;
            }
        }
示例#23
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;
            }
        }
示例#24
0
        public override void step(TestbedSettings settings)
        {
            m_rayActor = null;
            for (int i = 0; i < _e_actorCount; ++i)
            {
                m_actors[i].fraction = 1.0f;
                m_actors[i].overlap = false;
            }

            if (m_automated == true)
            {
                int actionCount = MathUtils.max(1, _e_actorCount >> 2);

                for (int i = 0; i < actionCount; ++i)
                {
                    Action();
                }
            }

            Query();
            RayCast();
            Vec2[] vecs = vecPool.get(4);

            for (int i = 0; i < _e_actorCount; ++i)
            {
                Actor actor = m_actors[i];
                if (actor.proxyId == -1)
                    continue;

                Color4f c = new Color4f(0.9f, 0.9f, 0.9f);
                if (actor == m_rayActor && actor.overlap)
                {
                    c.set(0.9f, 0.6f, 0.6f);
                }
                else if (actor == m_rayActor)
                {
                    c.set(0.6f, 0.9f, 0.6f);
                }
                else if (actor.overlap)
                {
                    c.set(0.6f, 0.6f, 0.9f);
                }
                actor.aabb.getVertices(vecs);
                getDebugDraw().drawPolygon(vecs, 4, c);
            }

            Color4f c2 = new Color4f(0.7f, 0.7f, 0.7f);
            m_queryAABB.getVertices(vecs);
            getDebugDraw().drawPolygon(vecs, 4, c2);

            getDebugDraw().drawSegment(m_rayCastInput.p1, m_rayCastInput.p2, c2);

            Color4f c1 = new Color4f(0.2f, 0.9f, 0.2f);
            Color4f c3 = new Color4f(0.9f, 0.2f, 0.2f);
            getDebugDraw().drawPoint(m_rayCastInput.p1, 6.0f, c1);
            getDebugDraw().drawPoint(m_rayCastInput.p2, 6.0f, c3);

            if (m_rayActor != null)
            {
                Color4f cr = new Color4f(0.2f, 0.2f, 0.9f);
                m_rayCastInput.p2.sub(m_rayCastInput.p1);
                m_rayCastInput.p2.mulLocal(m_rayActor.fraction);
                m_rayCastInput.p2.addLocal(m_rayCastInput.p1);
                Vec2 p = m_rayCastInput.p2;
                getDebugDraw().drawPoint(p, 6.0f, cr);
            }

            ++m_stepCount;

            if (settings.getSetting(TestbedSettings.DrawTree).enabled)
            {
                m_tree.drawTree(getDebugDraw());
            }

            getDebugDraw().drawString(5, 30,
                "(c)reate proxy, (d)estroy proxy, (a)utomate", Color4f.WHITE);
        }