public MementoDrag(EditorObject transformable) { Transformable = transformable; _polygonCoord = transformable.GetPolygonCoord(); _transform = null; if (_polygonCoord != null) { _parent = (IWall)transformable.Parent; } else { _transform = transformable.GetTransform(); } }
public static float EdgeIndexT(IPolygonCoord coord) { return coord.EdgeIndex + coord.EdgeT; }
public static Transform2 GetTransform(IList<Vector2> vertices, IPolygonCoord coord) { Transform2 transform = new Transform2(); LineF line = GetEdge(vertices, coord); transform.Position = line.Lerp(coord.EdgeT); transform.Rotation = -(float)MathExt.AngleVector(GetEdge(vertices, coord).GetNormal()); return transform; }
public static LineF GetEdge(IList<Vector2> vertices, IPolygonCoord coord) { Debug.Assert(vertices.Count >= 1, "Polygon must have at least 1 vertex."); return new LineF(vertices[coord.EdgeIndex], vertices[(coord.EdgeIndex + 1) % vertices.Count]); }
public static FixtureCoord GetFixtureEdgeCoord(Actor actor, IPolygonCoord coord) { Debug.Assert(actor.Body != null); Debug.Assert(coord != null); FixtureCoord fixtureCoord = coord as FixtureCoord; if (fixtureCoord != null) { Debug.Assert(actor == fixtureCoord.Actor); return fixtureCoord; } List<Vector2> fixtureContour = Actor.GetFixtureContour(actor); LineF edge = PolygonExt.GetEdge(fixtureContour, coord); Debug.Assert( edge[0] == fixtureContour[coord.EdgeIndex] && edge[1] == fixtureContour[(coord.EdgeIndex + 1) % fixtureContour.Count] ); if (!PolygonExt.IsInterior(fixtureContour)) { edge = edge.Reverse(); } foreach (Fixture f in actor.Body.FixtureList) { switch (f.Shape.ShapeType) { case ShapeType.Polygon: PolygonShape polygon = (PolygonShape)f.Shape; for (int i = 0; i < polygon.Vertices.Count; i++) { int iNext = (i + 1) % polygon.Vertices.Count; if ((edge[0] - (Vector2)polygon.Vertices[i]).Length < ERROR_MARGIN && (edge[1] - (Vector2)polygon.Vertices[iNext]).Length < ERROR_MARGIN) { //float edgeT = PolygonExt.IsInterior(fixtureContour) ? coord.EdgeT : 1 - coord.EdgeT; float edgeT = coord.EdgeT; return new FixtureCoord(f, i, edgeT); } } break; default: Debug.Fail("Cannot currently handle shapes other than polygons."); break; } } Debug.Fail("Could not find FixtureEdgeCoord."); return null; }