internal static void Destroy(Shape s) { switch (s.GetType()) { case ShapeType.CircleShape: { if (s != null) { ((IDisposable)s).Dispose(); } s = null; break; } case ShapeType.PolygonShape: { if (s != null) { ((IDisposable)s).Dispose(); } s = null; break; } default: { Box2DXDebug.Assert(false); break; } } }
public static float Distance(out Vec2 x1, out Vec2 x2, Shape shape1, XForm xf1, Shape shape2, XForm xf2) { x1 = new Vec2(); x2 = new Vec2(); ShapeType type1 = shape1.GetType(); ShapeType type2 = shape2.GetType(); if (type1 == ShapeType.CircleShape && type2 == ShapeType.CircleShape) { return(DistanceCC(out x1, out x2, (CircleShape)shape1, xf1, (CircleShape)shape2, xf2)); } if (type1 == ShapeType.PolygonShape && type2 == ShapeType.CircleShape) { return(DistancePC(out x1, out x2, (PolygonShape)shape1, xf1, (CircleShape)shape2, xf2)); } if (type1 == ShapeType.CircleShape && type2 == ShapeType.PolygonShape) { return(DistancePC(out x2, out x1, (PolygonShape)shape2, xf2, (CircleShape)shape1, xf1)); } if (type1 == ShapeType.PolygonShape && type2 == ShapeType.PolygonShape) { return(DistanceGeneric(out x1, out x2, (PolygonShape)shape1, xf1, (PolygonShape)shape2, xf2)); } return(0.0f); }
internal static void Destroy(Shape s) { switch (s.GetType()) { case ShapeType.CircleShape: if (s is IDisposable) { (s as IDisposable).Dispose(); } s = null; break; case ShapeType.PolygonShape: if (s is IDisposable) { (s as IDisposable).Dispose(); } s = null; break; default: Box2DXDebug.Assert(false); break; } }
/// Initialize the proxy using the given shape. The shape /// must remain in scope while the proxy is in use. public void Set(Shape shape) { switch (shape.GetType()) { case ShapeType.CircleShape: { CircleShape circle = (CircleShape)shape; _vertices = new Vec2[1]; _vertices[0] = circle._p; _count = 1; _radius = circle._radius; } break; case ShapeType.PolygonShape: { PolygonShape polygon = (PolygonShape)shape; _vertices = polygon.Vertices; _count = polygon.VertexCount; _radius = polygon._radius; } break; default: Box2DXDebug.Assert(false); break; } }
internal static void Destroy(Shape s) { switch (s.GetType()) { case ShapeType.CircleShape: { if (s != null) { ((IDisposable)s).Dispose(); } s = null; break; } case ShapeType.PolygonShape: { if (s != null) { ((IDisposable)s).Dispose(); } s = null; break; } default: { Box2DXDebug.Assert(false); break; } } }
private void DrawShape(Shape shape, XForm xf, Color color, bool core) { Color coreColor = new Color(0.9f, 0.6f, 0.6f); switch (shape.GetType()) { case ShapeType.CircleShape: { CircleShape circle = (CircleShape)shape; Vec2 center = Common.Math.Mul(xf, circle.GetLocalPosition()); float radius = circle.GetRadius(); Vec2 axis = xf.R.Col1; _debugDraw.DrawSolidCircle(center, radius, axis, color); if (core) { _debugDraw.DrawCircle(center, radius - Settings.ToiSlop, coreColor); } } break; case ShapeType.PolygonShape: { PolygonShape poly = (PolygonShape)shape; int vertexCount = poly.VertexCount; Vec2[] localVertices = poly.GetVertices(); Box2DXDebug.Assert(vertexCount <= Settings.MaxPolygonVertices); Vec2[] vertices = new Vec2[Settings.MaxPolygonVertices]; for (int i = 0; i < vertexCount; ++i) { vertices[i] = Common.Math.Mul(xf, localVertices[i]); } _debugDraw.DrawSolidPolygon(vertices, vertexCount, color); if (core) { Vec2[] localCoreVertices = poly.GetCoreVertices(); for (int i = 0; i < vertexCount; ++i) { vertices[i] = Common.Math.Mul(xf, localCoreVertices[i]); } _debugDraw.DrawPolygon(vertices, vertexCount, coreColor); } } break; } }
private void DrawShape(Shape shape, XForm xf, Color color, bool core) { Color color2 = new Color(0.9f, 0.6f, 0.6f); switch (shape.GetType()) { case ShapeType.CircleShape: { CircleShape circleShape = (CircleShape)shape; Vec2 center = Box2DX.Common.Math.Mul(xf, circleShape.GetLocalPosition()); float radius = circleShape.GetRadius(); Vec2 col = xf.R.Col1; this._debugDraw.DrawSolidCircle(center, radius, col, color); if (core) { this._debugDraw.DrawCircle(center, radius - Settings.ToiSlop, color2); } break; } case ShapeType.PolygonShape: { PolygonShape polygonShape = (PolygonShape)shape; int vertexCount = polygonShape.VertexCount; Vec2[] vertices = polygonShape.GetVertices(); Box2DXDebug.Assert(vertexCount <= Settings.MaxPolygonVertices); Vec2[] array = new Vec2[Settings.MaxPolygonVertices]; for (int i = 0; i < vertexCount; i++) { array[i] = Box2DX.Common.Math.Mul(xf, vertices[i]); } this._debugDraw.DrawSolidPolygon(array, vertexCount, color); if (core) { Vec2[] coreVertices = polygonShape.GetCoreVertices(); for (int i = 0; i < vertexCount; i++) { array[i] = Box2DX.Common.Math.Mul(xf, coreVertices[i]); } this._debugDraw.DrawPolygon(array, vertexCount, color2); } break; } } }
public static Contact Create(Shape shape1, Shape shape2) { if (s_initialized == false) { InitializeRegisters(); s_initialized = true; } ShapeType type1 = shape1.GetType(); ShapeType type2 = shape2.GetType(); Box2DXDebug.Assert(ShapeType.UnknownShape < type1 && type1 < ShapeType.ShapeTypeCount); Box2DXDebug.Assert(ShapeType.UnknownShape < type2 && type2 < ShapeType.ShapeTypeCount); ContactCreateFcn createFcn = s_registers[(int)type1][(int)type2].CreateFcn; if (createFcn != null) { if (s_registers[(int)type1][(int)type2].Primary) { return createFcn(shape1, shape2); } else { Contact c = createFcn(shape2, shape1); for (int i = 0; i < c.GetManifoldCount(); ++i) { Manifold m = c.GetManifolds()[i]; m.Normal = -m.Normal; } return c; } } else { return null; } }
/// Initialize the proxy using the given shape. The shape /// must remain in scope while the proxy is in use. public void Set(Shape shape) { switch (shape.GetType()) { case ShapeType.CircleShape: { CircleShape circle = (CircleShape)shape; _vertices = new Vec2[1]; _vertices[0] = circle._p; _count = 1; _radius = circle._radius; } break; case ShapeType.PolygonShape: { PolygonShape polygon = (PolygonShape)shape; _vertices = polygon.Vertices; _count = polygon.VertexCount; _radius = polygon._radius; } break; default: Box2DXDebug.Assert(false); break; } }
internal static void Destroy(Shape s) { switch (s.GetType()) { case ShapeType.CircleShape: if (s is IDisposable) (s as IDisposable).Dispose(); s = null; break; case ShapeType.PolygonShape: if (s is IDisposable) (s as IDisposable).Dispose(); s = null; break; default: Box2DXDebug.Assert(false); break; } }
public static Contact Create(Shape shape1, Shape shape2) { if (!Contact.s_initialized) { Contact.InitializeRegisters(); Contact.s_initialized = true; } ShapeType type = shape1.GetType(); ShapeType type2 = shape2.GetType(); Box2DXDebug.Assert(ShapeType.UnknownShape < type && type < ShapeType.ShapeTypeCount); Box2DXDebug.Assert(ShapeType.UnknownShape < type2 && type2 < ShapeType.ShapeTypeCount); ContactCreateFcn createFcn = Contact.s_registers[(int)type][(int)type2].CreateFcn; Contact result; if (createFcn != null) { if (Contact.s_registers[(int)type][(int)type2].Primary) { result = createFcn(shape1, shape2); } else { Contact contact = createFcn(shape2, shape1); for (int i = 0; i < contact.GetManifoldCount(); i++) { Manifold manifold = contact.GetManifolds()[i]; manifold.Normal = -manifold.Normal; } result = contact; } } else { result = null; } return result; }