Project290.Physics.Collision.DistanceProxy.Set C# (CSharp) Method

Set() public method

Initialize the proxy using the given shape. The shape must remain in scope while the proxy is in use.
public Set ( Shape shape, int index ) : void
shape Project290.Physics.Collision.Shapes.Shape The shape.
index int The index.
return void
        public void Set(Shape shape, int index)
        {
            switch (shape.ShapeType)
            {
                case ShapeType.Circle:
                    {
                        CircleShape circle = (CircleShape) shape;
                        Vertices = new Vertices(1);
                        Vertices.Add(circle.Position);
                        Radius = circle.Radius;
                    }
                    break;

                case ShapeType.Polygon:
                    {
                        PolygonShape polygon = (PolygonShape) shape;
                        Vertices = polygon.Vertices;
                        Radius = polygon.Radius;
                    }
                    break;

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

                        Buffer[0] = loop.Vertices[index];
                        if (index + 1 < loop.Vertices.Count)
                        {
                            Buffer[1] = loop.Vertices[index + 1];
                        }
                        else
                        {
                            Buffer[1] = loop.Vertices[0];
                        }

                        Vertices = new Vertices(2);
                        Vertices.Add(Buffer[0]);
                        Vertices.Add(Buffer[1]);
                        Radius = loop.Radius;
                    }
                    break;

                case ShapeType.Edge:
                    {
                        EdgeShape edge = (EdgeShape) shape;
                        Vertices = new Vertices(2);
                        Vertices.Add(edge.Vertex1);
                        Vertices.Add(edge.Vertex2);
                        Radius = edge.Radius;
                    }
                    break;

                default:
                    Debug.Assert(false);
                    break;
            }
        }