private void DrawFixture(Fixture fixture) { var color = Color.FromArgb(242, 242, 153); var xf = fixture.Body.GetTransform(); switch (fixture.Shape) { case CircleShape circle: { var center = MathUtils.Mul(xf, circle.Position); var radius = circle.Radius + 0.01f; _drawer.DrawCircle(center, radius, color); } break; case PolygonShape polygonShape: { var vertexCount = polygonShape.Count; Debug.Assert(vertexCount <= Settings.MaxPolygonVertices); var vertices = new Vector2[Settings.MaxPolygonVertices]; for (var i = 0; i < vertexCount; ++i) { var v = MathUtils.Mul(xf, polygonShape.Vertices[i]); v.X += 0.01f; v.Y += 0.01f; vertices[i] = v; } _drawer.DrawPolygon(vertices, vertexCount, color); } break; } }
public override void OnRender() { var manifold = new Manifold(); CollisionUtils.CollidePolygons(ref manifold, _polygonA, _transformA, _polygonB, _transformB); var worldManifold = new WorldManifold(); worldManifold.Initialize(manifold, _transformA, _polygonA.Radius, _transformB, _polygonB.Radius); DrawString($"point count = {manifold.PointCount}"); { var color = Color.FromArgb(230, 230, 230); var v = new Vector2[Settings.MaxPolygonVertices]; for (var i = 0; i < _polygonA.Count; ++i) { v[i] = MathUtils.Mul(_transformA, _polygonA.Vertices[i]); } Drawer.DrawPolygon(v, _polygonA.Count, color); for (var i = 0; i < _polygonB.Count; ++i) { v[i] = MathUtils.Mul(_transformB, _polygonB.Vertices[i]); } Drawer.DrawPolygon(v, _polygonB.Count, color); } for (var i = 0; i < manifold.PointCount; ++i) { Drawer.DrawPoint(worldManifold.Points[i], 4.0f, Color.FromArgb(230, 77, 77)); } }
protected override void OnRender() { DrawString("Press g to generate a new random convex hull"); DrawString("Press a to toggle random convex hull auto generation"); var shape = new PolygonShape(); shape.Set(_points); var drawLine = new Vector2[shape.Count + 1]; Array.Copy(shape.Vertices.ToArray(), drawLine, shape.Count); drawLine[drawLine.Length - 1] = shape.Vertices[0]; Drawer.DrawPolygon(drawLine, drawLine.Length, Color.FromArgb(0.9f, 0.9f, 0.9f)); for (var i = 0; i < _count; ++i) { Drawer.DrawPoint(_points[i], 3.0f, Color.FromArgb(0.3f, 0.9f, 0.3f)); Drawer.DrawString(_points[i] + new Vector2(0.05f, 0.05f), i.ToString()); } Drawer.DrawPoint(Vector2.Zero, 5f, Color.Yellow); if (_auto && !TestSettings.Pause) { Generate(); } }
public override void OnRender() { DrawString("Press g to generate a new random convex hull"); DrawString("Press a to toggle random convex hull auto generation"); var shape = new PolygonShape(); shape.Set(_points); var drawLine = new Vector2[shape.Count + 1]; Array.Copy(shape.Vertices.ToArray(), drawLine, shape.Count); drawLine[drawLine.Length - 1] = shape.Vertices[0]; Drawer.DrawPolygon(drawLine, drawLine.Length, Color.FromArgb(230, 230, 230)); _contents.Clear(); var points = _points.Select(e => TestSettings.Camera.WorldToScreenPoint(e.ToUnityVector2())) .Select(e => new UnityEngine.Vector2(e.x, Screen.height - e.y)) .ToArray(); for (var i = 0; i < _count; ++i) { Drawer.DrawPoint(_points[i], 10.0f, Color.FromArgb(77, 230, 77)); WriteString(points[i] + new UnityEngine.Vector2(0.5f, 0.5f), $"{i}"); } Drawer.DrawPoint(Vector2.Zero, 5f, Color.Yellow); if (_auto && !TestSettings.Pause) { Generate(); } }
protected override void OnRender() { DrawString("Keys: a: automate, c: create, d: destroy, m: move"); DrawString("Blue: overlap"); DrawString("Green: ray actor"); DrawString("Red: ray actor & overlap"); Color c; for (var i = 0; i < ActorCount; ++i) { var actor = _actors[i]; if (actor.ProxyId == BroadPhase.NullProxy) { continue; } c = Color.FromArgb(0.9f, 0.9f, 0.9f); if (actor == _rayActor && actor.Overlap) { c = Color.FromArgb(0.9f, 0.6f, 0.6f); } else if (actor == _rayActor) { c = Color.FromArgb(0.6f, 0.9f, 0.6f); } else if (actor.Overlap) { c = Color.FromArgb(0.6f, 0.6f, 0.9f); } Drawer.DrawAABB(actor.AABB, c); } c = Color.FromArgb(0.7f, 0.7f, 0.7f); Drawer.DrawAABB(_queryAABB, c); Drawer.DrawSegment(_rayCastInput.P1, _rayCastInput.P2, c); var c1 = Color.FromArgb(0.2f, 0.9f, 0.2f); var c2 = Color.FromArgb(0.9f, 0.2f, 0.2f); Drawer.DrawPoint(_rayCastInput.P1, 6.0f, c1); Drawer.DrawPoint(_rayCastInput.P2, 6.0f, c2); if (_rayActor != null) { var cr = Color.FromArgb(0.2f, 0.2f, 0.9f); var p = _rayCastInput.P1 + _rayActor.Fraction * (_rayCastInput.P2 - _rayCastInput.P1); Drawer.DrawPoint(p, 6.0f, cr); } { var height = _tree.GetHeight(); DrawString($"dynamic tree height = {height}"); } }
public void DrawAABB(AABB aabb, Color color) { var vs = new Vector2 [4]; vs[0].Set(aabb.LowerBound.X, aabb.LowerBound.Y); vs[1].Set(aabb.UpperBound.X, aabb.LowerBound.Y); vs[2].Set(aabb.UpperBound.X, aabb.UpperBound.Y); vs[3].Set(aabb.LowerBound.X, aabb.UpperBound.Y); Drawer.DrawPolygon(vs, 4, color); }
public override void OnRender() { var input = new DistanceInput(); input.ProxyA.Set(_polygonA, 0); input.ProxyB.Set(_polygonB, 0); input.TransformA = _transformA; input.TransformB = _transformB; input.UseRadii = true; var cache = new SimplexCache(); DistanceAlgorithm.Distance(out var output, ref cache, input); DrawString($"distance = {output.Distance}"); DrawString($"iterations = {output.Iterations}"); { var color = Color.FromArgb(230, 230, 230); var v = new Vector2[Settings.MaxPolygonVertices]; for (var i = 0; i < _polygonA.Count; ++i) { v[i] = MathUtils.Mul(_transformA, _polygonA.Vertices[i]); } Drawer.DrawPolygon(v, _polygonA.Count, color); for (var i = 0; i < _polygonB.Count; ++i) { v[i] = MathUtils.Mul(_transformB, _polygonB.Vertices[i]); } Drawer.DrawPolygon(v, _polygonB.Count, color); } var x1 = output.PointA; var x2 = output.PointB; var c1 = Color.FromArgb(255, 0, 0); Drawer.DrawPoint(x1, 4.0f, c1); var c2 = Color.FromArgb(255, 255, 0); Drawer.DrawPoint(x2, 4.0f, c2); }
/// <inheritdoc /> protected override void OnRender() { DrawString("Press 1-5 to drop stuff"); DrawString("Press 'a' to (de)activate some bodies"); DrawString("Press 'd' to destroy a body"); var callback = new PolyShapesCallback(Drawer) { Circle = { Radius = 2.0f } }; callback.Circle.Position.Set(0.0f, 1.1f); callback.Circle.ComputeAABB(out var aabb, callback.Transform, 0); callback.Transform.SetIdentity(); World.QueryAABB(callback, aabb); var color = Color.FromArgb(102, 178, 204); Drawer.DrawCircle(callback.Circle.Position, callback.Circle.Radius, color); }
protected override void OnRender() { DrawString("Keys: (s) pause"); Drawer.DrawPoint(_linearOffset, 4.0f, Color.FromArgb(230, 230, 230)); }
/// <inheritdoc /> public override void OnRender() { DrawString("Press 1-5 to drop stuff"); DrawString("Press 'a' to (de)activate some bodies"); DrawString("Press 'd' to destroy a body"); var k = -1; if (Input.GetKeyDown(KeyCode.Alpha1)) { k = 0; } if (Input.GetKeyDown(KeyCode.Alpha2)) { k = 1; } if (Input.GetKeyDown(KeyCode.Alpha3)) { k = 2; } if (Input.GetKeyDown(KeyCode.Alpha4)) { k = 3; } if (Input.GetKeyDown(KeyCode.Alpha5)) { k = 4; } if (k > -1) { Create(k); } if (Input.GetKeyDown(KeyCode.A)) { for (var i = 0; i < MaxBodies; i += 2) { if (_bodies[i] != null) { var active = _bodies[i].IsActive; _bodies[i].IsActive = !active; } } } if (Input.GetKeyDown(KeyCode.D)) { DestroyBody(); } var callback = new PolyShapesCallback(Drawer) { Circle = { Radius = 2.0f } }; callback.Circle.Position.Set(0.0f, 1.1f); callback.Circle.ComputeAABB(out var aabb, callback.Transform, 0); callback.Transform.SetIdentity(); World.QueryAABB(callback, aabb); var color = Color.FromArgb(102, 178, 204); Drawer.DrawCircle(callback.Circle.Position, callback.Circle.Radius, color); }