Пример #1
0
        /// Initialize the proxy using the given shape. The shape
        /// must remain in scope while the proxy is in use.
        public void Set(Shape shape, int index)
        {
            switch (shape.ShapeType)
            {
            case ShapeType.Circle:
            {
                CircleShape circle = (CircleShape)shape;
                _vertices[0] = circle._p;
                _count       = 1;
                _radius      = circle._radius;
            }
            break;

            case ShapeType.Polygon:
            {
                PolygonShape polygon = (PolygonShape)shape;
                _vertices = polygon._vertices;
                _count    = polygon._vertexCount;
                _radius   = polygon._radius;
            }
            break;

            case ShapeType.Loop:
            {
                LoopShape loop = (LoopShape)shape;
                //Debug.Assert(0 <= index && index < loop._count);

                _buffer[0] = loop._vertices[index];
                if (index + 1 < loop._count)
                {
                    _buffer[1] = loop._vertices[index + 1];
                }
                else
                {
                    _buffer[1] = loop._vertices[0];
                }

                _vertices[0] = _buffer[0];
                _vertices[1] = _buffer[1];
                _count       = 2;
                _radius      = loop._radius;
            }
            break;

            case ShapeType.Edge:
            {
                EdgeShape edge = (EdgeShape)shape;
                _vertices[0] = edge._vertex1;
                _vertices[1] = edge._vertex2;
                _count       = 2;
                _radius      = edge._radius;
            }
            break;

            default:
                //Debug.Assert(false);
                break;
            }
        }
Пример #2
0
        /// Implement Shape.
        public override Shape Clone()
        {
            var loop = new LoopShape();

            loop._count    = _count;
            loop._radius   = _radius;
            loop._vertices = (Vector2[])_vertices.Clone();
            return(loop);
        }
Пример #3
0
        void DrawShape(Fixture fixture, Transform xf, Color color)
        {
            switch (fixture.ShapeType)
            {
            case ShapeType.Circle:
            {
                CircleShape circle = (CircleShape)fixture.GetShape();

                Vector2 center = MathUtils.Multiply(ref xf, circle._p);
                float   radius = circle._radius;
                Vector2 axis   = xf.R.col1;

                DebugDraw.DrawSolidCircle(center, radius, axis, color);
            }
            break;

            case ShapeType.Polygon:
            {
                PolygonShape poly        = (PolygonShape)fixture.GetShape();
                int          vertexCount = poly._vertexCount;
                //Debug.Assert(vertexCount <= Settings.b2_maxPolygonVertices);
                FixedArray8 <Vector2> vertices = new FixedArray8 <Vector2>();

                for (int i = 0; i < vertexCount; ++i)
                {
                    vertices[i] = MathUtils.Multiply(ref xf, poly._vertices[i]);
                }

                DebugDraw.DrawSolidPolygon(ref vertices, vertexCount, color);
            }
            break;

            case ShapeType.Edge:
            {
                EdgeShape edge = (EdgeShape)fixture.GetShape();
                Vector2   v1   = MathUtils.Multiply(ref xf, edge._vertex1);
                Vector2   v2   = MathUtils.Multiply(ref xf, edge._vertex2);
                DebugDraw.DrawSegment(v1, v2, color);
            }
            break;

            case ShapeType.Loop:
            {
                LoopShape loop  = (LoopShape)fixture.GetShape();
                int       count = loop._count;

                Vector2 v1 = MathUtils.Multiply(ref xf, loop._vertices[count - 1]);
                for (int i = 0; i < count; ++i)
                {
                    Vector2 v2 = MathUtils.Multiply(ref xf, loop._vertices[i]);
                    DebugDraw.DrawSegment(v1, v2, color);
                    v1 = v2;
                }
            }
            break;
            }
        }