public override void DrawPolygon(b2Vec2[] vertices, int vertexCount, b2Color color)
        {
            if (!_primitiveBatch.IsReady())
            {
                throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");
            }
            for (int i = 0; i < vertexCount - 1; i++)
            {
                _primitiveBatch.AddVertex(vertices[i].ToVector2(), color.ToColor(), PrimitiveType.LineList);
                _primitiveBatch.AddVertex(vertices[i + 1].ToVector2(), color.ToColor(), PrimitiveType.LineList);
            }

            _primitiveBatch.AddVertex(vertices[vertexCount - 1].ToVector2(), color.ToColor(), PrimitiveType.LineList);
            _primitiveBatch.AddVertex(vertices[0].ToVector2(), color.ToColor(), PrimitiveType.LineList);
        }
        public override void DrawSolidPolygon(b2Vec2[] vertices, int vertexCount, b2Color color)
        {
            if (!_primitiveBatch.IsReady())
            {
                throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");
            }
            if (vertexCount == 2)
            {
                DrawPolygon(vertices, vertexCount, color);
                return;
            }

            var colorFill = color.ToColor() * 0.5f;
 
            for (int i = 1; i < vertexCount - 1; i++)
            {
                _primitiveBatch.AddVertex(vertices[0].ToVector2(), colorFill, PrimitiveType.TriangleList);
                _primitiveBatch.AddVertex(vertices[i].ToVector2(), colorFill, PrimitiveType.TriangleList);
                _primitiveBatch.AddVertex(vertices[i + 1].ToVector2(), colorFill, PrimitiveType.TriangleList);
            }
                DrawPolygon(vertices, vertexCount, color);
        }
Exemple #3
0
        public override void DrawCircle(b2Vec2 center, float radius, b2Color color)
        {
            if (!_primitiveBatch.IsReady())
            {
                throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");
            }
            const double increment = Math.PI * 2.0 / CircleSegments;
            double theta = 0.0;

            var col = color.ToColor();
            Vector2 centr = center.ToVector2();

            for (int i = 0, count = CircleSegments; i < count; i++)
            {
                Vector2 v1 = centr + radius * new Vector2((float) Math.Cos(theta), (float) Math.Sin(theta));
                Vector2 v2 = centr +
                             radius *
                             new Vector2((float) Math.Cos(theta + increment), (float) Math.Sin(theta + increment));

                _primitiveBatch.AddVertex(ref v1, col, PrimitiveType.LineList);
                _primitiveBatch.AddVertex(ref v2, col, PrimitiveType.LineList);

                theta += increment;
            }
        }
Exemple #4
0
 public override void DrawSegment(b2Vec2 p1, b2Vec2 p2, b2Color color)
 {
     if (!_primitiveBatch.IsReady())
     {
         throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");
     }
     _primitiveBatch.AddVertex(p1.ToVector2(), color.ToColor(), PrimitiveType.LineList);
     _primitiveBatch.AddVertex(p2.ToVector2(), color.ToColor(), PrimitiveType.LineList);
 }
Exemple #5
0
        public override void DrawSolidCircle(b2Vec2 center, float radius, b2Vec2 axis, b2Color color)
        {
            if (!_primitiveBatch.IsReady())
            {
                throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything.");
            }
            const double increment = Math.PI * 2.0 / CircleSegments;
            double theta = 0.0;

            var colorFill = color.ToColor() * 0.5f;
            var centr = center.ToVector2();

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

            for (int i = 1; i < CircleSegments - 1; i++)
            {
                var v1 = centr + radius * new Vector2((float) Math.Cos(theta), (float) Math.Sin(theta));
                var v2 = centr +
                         radius * new Vector2((float) Math.Cos(theta + increment), (float) Math.Sin(theta + increment));

                _primitiveBatch.AddVertex(ref v0, colorFill, PrimitiveType.TriangleList);
                _primitiveBatch.AddVertex(ref v1, colorFill, PrimitiveType.TriangleList);
                _primitiveBatch.AddVertex(ref v2, colorFill, PrimitiveType.TriangleList);

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

            DrawSegment(center, center + axis * radius, color);
        }