public void DrawAABB(AABB aabb, Color color) { FP.Vector2[] verts = new FP.Vector2[4]; verts[0] = new FP.Vector2(aabb.LowerBound.X, aabb.LowerBound.Y); verts[1] = new FP.Vector2(aabb.UpperBound.X, aabb.LowerBound.Y); verts[2] = new FP.Vector2(aabb.UpperBound.X, aabb.UpperBound.Y); verts[3] = new FP.Vector2(aabb.LowerBound.X, aabb.UpperBound.Y); DrawPolygon(verts.ToMGVector2(), 4, color); }
public void DrawShape(Fixture fixture, FP.Transform xf, Color color) { switch (fixture.Shape.ShapeType) { case ShapeType.Circle: { CircleShape circle = (CircleShape)fixture.Shape; FP.Vector2 center = FP.MathUtils.Mul(ref xf, circle.Position); float radius = circle.Radius; FP.Vector2 axis = FP.MathUtils.Mul(xf.q, new FP.Vector2(1.0f, 0.0f)); DrawSolidCircle(center, radius, axis, color); } break; case ShapeType.Polygon: { PolygonShape poly = (PolygonShape)fixture.Shape; int vertexCount = poly.Vertices.Count; Debug.Assert(vertexCount <= Settings.MaxPolygonVertices); for (int i = 0; i < vertexCount; ++i) { _tempVertices[i] = FP.MathUtils.Mul(ref xf, poly.Vertices[i]); } DrawSolidPolygon(_tempVertices, vertexCount, color); } break; case ShapeType.Edge: { EdgeShape edge = (EdgeShape)fixture.Shape; FP.Vector2 v1 = FP.MathUtils.Mul(ref xf, edge.Vertex1); FP.Vector2 v2 = FP.MathUtils.Mul(ref xf, edge.Vertex2); DrawSegment(v1, v2, color); } break; case ShapeType.Chain: { ChainShape chain = (ChainShape)fixture.Shape; for (int i = 0; i < chain.Vertices.Count - 1; ++i) { FP.Vector2 v1 = FP.MathUtils.Mul(ref xf, chain.Vertices[i]); FP.Vector2 v2 = FP.MathUtils.Mul(ref xf, chain.Vertices[i + 1]); DrawSegment(v1, v2, color); } } break; } }
public override void DrawTransform(ref FP.Transform transform) { const float axisScale = 0.4f; FP.Vector2 p1 = transform.p; FP.Vector2 p2 = p1 + axisScale * transform.q.GetXAxis(); debugRenderer.DrawSegment(p1, p2, Color.Red); p2 = p1 + axisScale * transform.q.GetYAxis(); debugRenderer.DrawSegment(p1, p2, Color.Green); }
public override void DrawSegment(FP.Vector2 start, FP.Vector2 end, float red, float green, float blue) { debugRenderer.DrawSegment(start, end, new Color(red, green, blue)); }
public override void DrawSolidCircle(FP.Vector2 center, float radius, FP.Vector2 axis, float red, float green, float blue) { debugRenderer.DrawSolidCircle(center.ToMGVector2(), ConvertUnits.ToDisplayUnits(radius), axis.ToMGVector2(), new Color(red, green, blue)); }
/// <summary> /// Call this to draw shapes and other debug draw data. /// </summary> private void DrawDebugData() { if ((Flags & DebugViewFlags.Controllers) == DebugViewFlags.Controllers) { for (int i = 0; i < World.ControllerList.Count; i++) { Controller controller = World.ControllerList[i]; BuoyancyController buoyancy = controller as BuoyancyController; if (buoyancy != null) { AABB container = buoyancy.Container; debugRenderer.DrawAABB(container, Color.LightBlue); } SeaCurrentsController seaCurrents = controller as SeaCurrentsController; if (seaCurrents != null) { debugRenderer.DrawCircle(seaCurrents.Position, seaCurrents.Radius, Color.LightBlue); FP.Vector2 dir = seaCurrents.Direction; dir.Normalize(); debugRenderer.DrawArrow(seaCurrents.Position, seaCurrents.Position + dir * seaCurrents.Strength, 5, 8, true, Color.Green); } } } if ((Flags & DebugViewFlags.Shape) == DebugViewFlags.Shape) { foreach (Body b in World.BodyList) { FP.Transform xf; b.GetTransform(out xf); foreach (Fixture f in b.FixtureList) { if (b.Enabled == false) { debugRenderer.DrawShape(f, xf, InactiveShapeColor); } else if (b.BodyType == BodyType.Static) { debugRenderer.DrawShape(f, xf, StaticShapeColor); } else if (b.BodyType == BodyType.Kinematic) { debugRenderer.DrawShape(f, xf, KinematicShapeColor); } else if (b.Awake == false) { debugRenderer.DrawShape(f, xf, SleepingShapeColor); } else { debugRenderer.DrawShape(f, xf, DefaultShapeColor); } if (f.Body == SelectedBody) { Color color = new Color(0.9f, 0.3f, 0.3f); IBroadPhase bp = World.ContactManager.BroadPhase; for (int t = 0; t < f.ProxyCount; ++t) { FixtureProxy proxy = f.Proxies[t]; AABB aabb; bp.GetFatAABB(proxy.ProxyId, out aabb); debugRenderer.DrawAABB(aabb, color); } } } } } if ((Flags & DebugViewFlags.ContactPoints) == DebugViewFlags.ContactPoints) { const float axisScale = 0.3f; for (int i = 0; i < _pointCount; ++i) { ContactPoint point = _points[i]; if (point.State == PointState.Add) { debugRenderer.DrawPoint(point.Position, 0.1f, new Color(0.3f, 0.95f, 0.3f)); } else if (point.State == PointState.Persist) { debugRenderer.DrawPoint(point.Position, 0.1f, new Color(0.3f, 0.3f, 0.95f)); } if ((Flags & DebugViewFlags.ContactNormals) == DebugViewFlags.ContactNormals) { Vector2 p1 = point.Position; Vector2 p2 = p1 + axisScale * point.Normal; debugRenderer.DrawSegment(p1, p2, new Color(0.4f, 0.9f, 0.4f)); } } _pointCount = 0; } if ((Flags & DebugViewFlags.PolygonPoints) == DebugViewFlags.PolygonPoints) { foreach (Body body in World.BodyList) { foreach (Fixture f in body.FixtureList) { PolygonShape polygon = f.Shape as PolygonShape; if (polygon != null) { FP.Transform xf; body.GetTransform(out xf); for (int i = 0; i < polygon.Vertices.Count; i++) { Vector2 tmp = FP.MathUtils.Mul(ref xf, polygon.Vertices[i]).ToMGVector2(); debugRenderer.DrawPoint(tmp, 0.1f, Color.Red); } } } } } if ((Flags & DebugViewFlags.Joint) == DebugViewFlags.Joint) { foreach (Joint j in World.JointList) { debugRenderer.DrawJoint(j); } } if ((Flags & DebugViewFlags.AABB) == DebugViewFlags.AABB) { Color color = new Color(0.9f, 0.3f, 0.9f); IBroadPhase bp = World.ContactManager.BroadPhase; foreach (Body body in World.BodyList) { if (body.Enabled == false) { continue; } foreach (Fixture f in body.FixtureList) { for (int t = 0; t < f.ProxyCount; ++t) { FixtureProxy proxy = f.Proxies[t]; AABB aabb; bp.GetFatAABB(proxy.ProxyId, out aabb); debugRenderer.DrawAABB(aabb, color); } } } } if ((Flags & DebugViewFlags.CenterOfMass) == DebugViewFlags.CenterOfMass) { foreach (Body b in World.BodyList) { FP.Transform xf; b.GetTransform(out xf); xf.p = b.WorldCenter; DrawTransform(ref xf); } } if (SelectedBody != null) { debugRenderer.DrawArrow(SelectedBody.Position, SelectedBody.Position + SelectedBody.LinearVelocity, 4, 8, false, Color.Green); } }
public void DrawJoint(Joint joint) { if (!joint.Enabled) { return; } Body b1 = joint.BodyA; Body b2 = joint.BodyB; FP.Transform xf1; b1.GetTransform(out xf1); FP.Vector2 x2 = FP.Vector2.Zero; // WIP David if (!joint.IsFixedType()) { FP.Transform xf2; b2.GetTransform(out xf2); x2 = xf2.p; } FP.Vector2 p1 = joint.WorldAnchorA; FP.Vector2 p2 = joint.WorldAnchorB; FP.Vector2 x1 = xf1.p; Color color = new Color(0.5f, 0.8f, 0.8f); switch (joint.JointType) { case JointType.Distance: DrawSegment(p1, p2, color); break; case JointType.Pulley: PulleyJoint pulley = (PulleyJoint)joint; FP.Vector2 s1 = b1.GetWorldPoint(pulley.LocalAnchorA); FP.Vector2 s2 = b2.GetWorldPoint(pulley.LocalAnchorB); DrawSegment(p1, p2, color); DrawSegment(p1, s1, color); DrawSegment(p2, s2, color); break; case JointType.FixedMouse: DrawPoint(p1, 0.5f, new Color(0.0f, 1.0f, 0.0f)); DrawSegment(p1, p2, new Color(0.8f, 0.8f, 0.8f)); break; case JointType.Revolute: DrawSegment(x1, p1, color); DrawSegment(p1, p2, color); DrawSegment(x2, p2, color); DrawSolidCircle(p2, 0.1f, FP.Vector2.Zero, Color.Red); DrawSolidCircle(p1, 0.1f, FP.Vector2.Zero, Color.Blue); break; case JointType.FixedAngle: //Should not draw anything. break; case JointType.FixedRevolute: DrawSegment(x1, p1, color); DrawSolidCircle(p1, 0.1f, FP.Vector2.Zero, Color.Pink); break; case JointType.FixedLine: DrawSegment(x1, p1, color); DrawSegment(p1, p2, color); break; case JointType.FixedDistance: DrawSegment(x1, p1, color); DrawSegment(p1, p2, color); break; case JointType.FixedPrismatic: DrawSegment(x1, p1, color); DrawSegment(p1, p2, color); break; case JointType.Gear: DrawSegment(x1, x2, color); break; default: DrawSegment(x1, p1, color); DrawSegment(p1, p2, color); DrawSegment(x2, p2, color); break; } }
public void DrawArrow(FP.Vector2 start, FP.Vector2 end, float length, float width, bool drawStartIndicator, Color color) { DrawArrow(start.ToMGVector2(), end.ToMGVector2(), length, width, drawStartIndicator, color); }
public void DrawPoint(FP.Vector2 p, float size, Color color) { DrawPoint(p.ToMGVector2(), ConvertUnits.ToDisplayUnits(size), color); }
public void DrawSegment(FP.Vector2 start, FP.Vector2 end, Color color) { DrawSegment(start.ToMGVector2(), end.ToMGVector2(), color); }
public void DrawSolidCircle(FP.Vector2 center, float radius, FP.Vector2 axis, Color color) { DrawSolidCircle(center.ToMGVector2(), ConvertUnits.ToDisplayUnits(radius), new Vector2(axis.X, axis.Y), color); }
public void DrawCircle(FP.Vector2 center, float radius, Color color) { DrawCircle(center.ToMGVector2(), ConvertUnits.ToDisplayUnits(radius), color); }