public void DrawFixture(b2Fixture fixture) { b2Color color = new b2Color(0.95f, 0.95f, 0.6f); b2Transform xf = fixture.Body.Transform; switch (fixture.ShapeType) { case b2ShapeType.e_circle: { b2CircleShape circle = (b2CircleShape) fixture.Shape; b2Vec2 center = b2Math.b2Mul(xf, circle.Position); float radius = circle.Radius; m_debugDraw.DrawCircle(center, radius, color); } break; case b2ShapeType.e_polygon: { b2PolygonShape poly = (b2PolygonShape) fixture.Shape; int vertexCount = poly.VertexCount; Debug.Assert(vertexCount <= b2Settings.b2_maxPolygonVertices); b2Vec2[] vertices = new b2Vec2[b2Settings.b2_maxPolygonVertices]; for (int i = 0; i < vertexCount; ++i) { vertices[i] = b2Math.b2Mul(xf, poly.Vertices[i]); } m_debugDraw.DrawPolygon(vertices, vertexCount, color); } break; } }
protected override void Draw(Settings settings) { base.Draw(settings); b2Manifold manifold = new b2Manifold(); b2Collision.b2CollidePolygons(manifold, m_polygonA, ref m_transformA, m_polygonB, ref m_transformB); b2WorldManifold worldManifold = new b2WorldManifold(); worldManifold.Initialize(manifold, ref m_transformA, m_polygonA.Radius, ref m_transformB, m_polygonB.Radius); m_debugDraw.DrawString(5, m_textLine, "point count = {0}", manifold.pointCount); m_textLine += 15; { b2Color color = new b2Color(0.9f, 0.9f, 0.9f); b2Vec2[] v = new b2Vec2[b2Settings.b2_maxPolygonVertices]; for (int i = 0; i < m_polygonA.VertexCount; ++i) { v[i] = b2Math.b2Mul(m_transformA, m_polygonA.Vertices[i]); } m_debugDraw.DrawPolygon(v, m_polygonA.VertexCount, color); for (int i = 0; i < m_polygonB.VertexCount; ++i) { v[i] = b2Math.b2Mul(m_transformB, m_polygonB.Vertices[i]); } m_debugDraw.DrawPolygon(v, m_polygonB.VertexCount, color); } for (int i = 0; i < manifold.pointCount; ++i) { m_debugDraw.DrawPoint(worldManifold.points[i], 4.0f, new b2Color(0.9f, 0.3f, 0.3f)); } }
public void DrawPoint(b2Vec2 aP, float aSize, b2Color aColor) { CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawPoint(new CCPoint(mRatio * aP.x, mRatio * aP.y), 1, new CCColor4B(aColor.r, aColor.g, aColor.b, 1)); CCDrawingPrimitives.End(); }
public virtual void Draw(b2Draw draw) { b2Color c = new b2Color(0.4f, 0.5f, 0.7f); for (int i = 0; i < m_count - 1; ++i) { draw.DrawSegment(m_ps[i], m_ps[i + 1], c); } }
public override void DrawPolygon(b2Vec2[] vertices, int vertexCount, b2Color color) { b2Vec2[] alt = new b2Vec2[vertexCount]; for (int i = 0; i < vertexCount; i++) { alt[i] = vertices[i] * PTMRatio + _Center; } CCDrawingPrimitives.DrawPoly(alt, vertexCount, true, color); }
public override void DrawSolidPolygon(b2Vec2[] vertices, int vertexCount, b2Color color) { _list.Count = vertexCount; var alt = _list.Elements; for (int i = 0; i < vertexCount; i++) { alt[i] = vertices[i] * PTMRatio + _Center; } CCDrawingPrimitives.DrawSolidPoly(alt, vertexCount, color); }
public override void DrawCircle(b2Vec2 aCenter, float aRadius, b2Color aColor) { CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawCircle(new CCPoint(mRatio * aCenter.x, mRatio * aCenter.y), aRadius, 0, DEBUG_DRAW_CIRCLE_SEGMENTS, false, new CCColor4B(aColor.r, aColor.g, aColor.b, 1)); CCDrawingPrimitives.End(); }
public static void DrawPoints(b2Vec2[] points, int numberOfPoints, float size, b2Color color) { CCColor4B ccolor = new CCColor4B(color.r, color.g, color.b, 255); CCPoint pt = CCPoint.Zero; for (int i = 0; i < numberOfPoints; i++) { pt.X = points[i].x; pt.Y = points[i].y; DrawPoint(pt, size, ccolor); } }
public void DrawAABB(b2AABB aAabb, b2Color aColor) { mVertices[0] = new CCPoint(aAabb.LowerBound.x * mRatio, aAabb.LowerBound.y * mRatio); mVertices[1] = new CCPoint(aAabb.UpperBound.x * mRatio, aAabb.LowerBound.y * mRatio); mVertices[2] = new CCPoint(aAabb.UpperBound.x * mRatio, aAabb.UpperBound.y * mRatio); mVertices[3] = new CCPoint(aAabb.LowerBound.x * mRatio, aAabb.UpperBound.y * mRatio); CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawPoly(mVertices, 8, true, new CCColor4B(aColor.r, aColor.g, aColor.b, 1)); CCDrawingPrimitives.End(); }
public override void DrawPolygon(b2Vec2[] vertices, int vertexCount, b2Color color) { for (int i = 0; i < vertexCount - 1; i++) { DrawNode.AddLineVertex(vertices[i].ToVectorC4B(color.ToCCColor4B(), PTMRatio)); DrawNode.AddLineVertex(vertices[i+1].ToVectorC4B(color.ToCCColor4B(), PTMRatio)); } DrawNode.AddLineVertex(vertices[vertexCount - 1].ToVectorC4B(color.ToCCColor4B(), PTMRatio)); DrawNode.AddLineVertex(vertices[0].ToVectorC4B(color.ToCCColor4B(), PTMRatio)); }
protected override void Draw(Settings settings) { base.Draw(settings); for (int i = 0; i < e_actorCount; ++i) { Actor actor = m_actors[i]; if (actor.proxyId == b2_nullNode) continue; b2Color c = new b2Color(0.9f, 0.9f, 0.9f); if (actor == m_rayActor && actor.overlap) { c.Set(0.9f, 0.6f, 0.6f); } else if (actor == m_rayActor) { c.Set(0.6f, 0.9f, 0.6f); } else if (actor.overlap) { c.Set(0.6f, 0.6f, 0.9f); } m_debugDraw.DrawAABB(actor.aabb, c); } b2Color cc = new b2Color(0.7f, 0.7f, 0.7f); m_debugDraw.DrawAABB(m_queryAABB, cc); m_debugDraw.DrawSegment(m_rayCastInput.p1, m_rayCastInput.p2, cc); b2Color c1 = new b2Color(0.2f, 0.9f, 0.2f); b2Color c2 = new b2Color(0.9f, 0.2f, 0.2f); m_debugDraw.DrawPoint(m_rayCastInput.p1, 6.0f, c1); m_debugDraw.DrawPoint(m_rayCastInput.p2, 6.0f, c2); if (m_rayActor != null) { b2Color cr = new b2Color(0.2f, 0.2f, 0.9f); b2Vec2 p = m_rayCastInput.p1 + m_rayActor.fraction * (m_rayCastInput.p2 - m_rayCastInput.p1); m_debugDraw.DrawPoint(p, 6.0f, cr); } { int height = m_tree.GetHeight(); m_debugDraw.DrawString(5, m_textLine, "dynamic tree height = {0}", height); m_textLine += 15; } }
public override void DrawPolygon(b2Vec2[] aVertices, int aVertexCount, b2Color aColor) { for (int i = 0; i < DEBUG_DRAW_MAX_VERTICES && i < aVertexCount; i++) mVertices[i] = new CCPoint(mRatio * aVertices[i].x, mRatio * aVertices[i].y); CCPoint[] ar = new CCPoint[aVertices.Length]; for (int i = 0; i < aVertices.Length; i++) { ar[i] = new CCPoint(aVertices[i].x, aVertices[i].y); } CCDrawingPrimitives.Begin(); CCDrawingPrimitives.DrawPoly(ar, aVertexCount, true, new CCColor4B(aColor.r, aColor.g, aColor.b, 1)); CCDrawingPrimitives.End(); }
public override void DrawPolygon(b2Vec2[] vertices, int vertexCount, b2Color color) { if (!_primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } for (int i = 0; i < vertexCount - 1; i++) { _primitiveBatch.AddVertex(vertices[i].ToVector2(), color.ToColor(), PrimitiveType.LineList); _primitiveBatch.AddVertex(vertices[i + 1].ToVector2(), color.ToColor(), PrimitiveType.LineList); } _primitiveBatch.AddVertex(vertices[vertexCount - 1].ToVector2(), color.ToColor(), PrimitiveType.LineList); _primitiveBatch.AddVertex(vertices[0].ToVector2(), color.ToColor(), PrimitiveType.LineList); }
protected override void Draw(Settings settings) { base.Draw(settings); b2DistanceInput input = b2DistanceInput.Create(); input.proxyA.Set(m_polygonA, 0); input.proxyB.Set(m_polygonB, 0); input.transformA = m_transformA; input.transformB = m_transformB; input.useRadii = true; b2SimplexCache cache = b2SimplexCache.Create(); cache.count = 0; b2DistanceOutput output = new b2DistanceOutput(); b2Simplex.b2Distance(ref output, ref cache, ref input); m_debugDraw.DrawString(5, m_textLine, "distance = {0}", output.distance); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "iterations = {0}", output.iterations); m_textLine += 15; { b2Color color = new b2Color(0.9f, 0.9f, 0.9f); b2Vec2[] v = new b2Vec2[b2Settings.b2_maxPolygonVertices]; for (int i = 0; i < m_polygonA.VertexCount; ++i) { v[i] = b2Math.b2Mul(m_transformA, m_polygonA.Vertices[i]); } m_debugDraw.DrawPolygon(v, m_polygonA.VertexCount, color); for (int i = 0; i < m_polygonB.VertexCount; ++i) { v[i] = b2Math.b2Mul(m_transformB, m_polygonB.Vertices[i]); } m_debugDraw.DrawPolygon(v, m_polygonB.VertexCount, color); } b2Vec2 x1 = output.pointA; b2Vec2 x2 = output.pointB; b2Color c1 = new b2Color(1.0f, 0.0f, 0.0f); m_debugDraw.DrawPoint(x1, 4.0f, c1); b2Color c2 = new b2Color(1.0f, 1.0f, 0.0f); m_debugDraw.DrawPoint(x2, 4.0f, c2); }
public override void DrawSolidPolygon(b2Vec2[] vertices, int vertexCount, b2Color color) { if (vertexCount == 2) { DrawPolygon(vertices, vertexCount, color); return; } var colorFill = color.ToCCColor4B() * 0.5f; for (int i = 1; i < vertexCount - 1; i++) { DrawNode.AddLineVertex(vertices[0].ToVectorC4B(color.ToCCColor4B(), PTMRatio)); DrawNode.AddLineVertex(vertices[i].ToVectorC4B(color.ToCCColor4B(), PTMRatio)); DrawNode.AddLineVertex(vertices[i + 1].ToVectorC4B(color.ToCCColor4B(), PTMRatio)); } DrawPolygon(vertices, vertexCount, color); }
public override void DrawCircle(b2Vec2 center, float radius, b2Color color) { if (!_primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } const double increment = Math.PI * 2.0 / CircleSegments; double theta = 0.0; for (int i = 0, count = CircleSegments; i < count; i++) { b2Vec2 v1 = center + radius * new b2Vec2((float)Math.Cos(theta), (float)Math.Sin(theta)); b2Vec2 v2 = center + radius * new b2Vec2((float)Math.Cos(theta + increment), (float)Math.Sin(theta + increment)); _primitiveBatch.AddVertex(v1.ToVector2(), color.ToColor(), PrimitiveType.LineList); _primitiveBatch.AddVertex(v2.ToVector2(), color.ToColor(), PrimitiveType.LineList); theta += increment; } }
public override void DrawSolidPolygon(b2Vec2[] vertices, int vertexCount, b2Color color) { if (!_primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } if (vertexCount == 2) { DrawPolygon(vertices, vertexCount, color); return; } var colorFill = color.ToColor() * 0.5f; for (int i = 1; i < vertexCount - 1; i++) { _primitiveBatch.AddVertex(vertices[0].ToVector2(), colorFill, PrimitiveType.TriangleList); _primitiveBatch.AddVertex(vertices[i].ToVector2(), colorFill, PrimitiveType.TriangleList); _primitiveBatch.AddVertex(vertices[i + 1].ToVector2(), colorFill, PrimitiveType.TriangleList); } DrawPolygon(vertices, vertexCount, color); }
/// Draw a line segment. public abstract void DrawSegment(b2Vec2 p1, b2Vec2 p2, b2Color color);
/// Draw a solid circle. public abstract void DrawSolidCircle(b2Vec2 center, float radius, b2Vec2 axis, b2Color color);
/// Draw a solid closed polygon provided in CCW order. public abstract void DrawSolidPolygon(b2Vec2[] vertices, int vertexCount, b2Color color);
public void DrawPoint(b2Vec2 p, float size, b2Color color) { b2Vec2[] verts = new b2Vec2[4]; float hs = size / 2.0f; verts[0] = p + new b2Vec2(-hs, -hs); verts[1] = p + new b2Vec2(hs, -hs); verts[2] = p + new b2Vec2(hs, hs); verts[3] = p + new b2Vec2(-hs, hs); DrawSolidPolygon(verts, 4, color); }
public override void DrawSegment(b2Vec2 p1, b2Vec2 p2, b2Color color) { if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } primitiveBatch.AddVertex(p1.ToCCVector2() * PTMRatio , color.ToCCColor4B(), PrimitiveType.LineList); primitiveBatch.AddVertex(p2.ToCCVector2() * PTMRatio, color.ToCCColor4B(), PrimitiveType.LineList); }
public override void DrawSolidCircle(b2Vec2 center, float radius, b2Vec2 axis, b2Color color) { if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } const double increment = Math.PI * 2.0 / CircleSegments; double theta = 0.0; var colorFill = color.ToCCColor4B() * 0.5f; var centr = center.ToCCVector2(); CCVector2 v0 = center.ToCCVector2() + radius * new CCVector2((float) Math.Cos(theta), (float) Math.Sin(theta)); theta += increment; v0 *= PTMRatio; for (int i = 1; i < CircleSegments - 1; i++) { var v1 = centr + radius * new CCVector2((float) Math.Cos(theta), (float) Math.Sin(theta)); v1 *= PTMRatio; var v2 = centr + radius * new CCVector2((float) Math.Cos(theta + increment), (float) Math.Sin(theta + increment)); v2 *= PTMRatio; primitiveBatch.AddVertex(ref v0, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(ref v1, colorFill, PrimitiveType.TriangleList); primitiveBatch.AddVertex(ref v2, colorFill, PrimitiveType.TriangleList); theta += increment; } DrawCircle(center, radius, color); DrawSegment(center, center + axis * radius, color); }
public override void DrawSegment(b2Vec2 p1, b2Vec2 p2, b2Color color) { CCDrawingPrimitives.DrawLine(p1 * PTMRatio + _Center, p2 * PTMRatio + _Center, color); }
public override void DrawCircle(b2Vec2 center, float radius, b2Color color) { CCDrawingPrimitives.DrawCircle(center * PTMRatio + _Center, radius * PTMRatio, color); }
public void DrawAABB(b2AABB aabb, b2Color p1) { b2Vec2[] verts = new b2Vec2[4]; verts[0] = new b2Vec2(aabb.LowerBound.x, aabb.LowerBound.y); verts[1] = new b2Vec2(aabb.UpperBound.x, aabb.LowerBound.y); verts[2] = new b2Vec2(aabb.UpperBound.x, aabb.UpperBound.y); verts[3] = new b2Vec2(aabb.LowerBound.x, aabb.UpperBound.y); DrawPolygon(verts, 4, p1); }
public override void DrawCircle(b2Vec2 center, float radius, b2Color color) { if (!primitiveBatch.IsReady()) { throw new InvalidOperationException("BeginCustomDraw must be called before drawing anything."); } const double increment = Math.PI * 2.0 / CircleSegments; double theta = 0.0; var col = color.ToCCColor4B(); CCVector2 centr = center.ToCCVector2(); for (int i = 0, count = CircleSegments; i < count; i++) { CCVector2 v1 = (centr + radius * new CCVector2((float) Math.Cos(theta), (float) Math.Sin(theta))) * PTMRatio; CCVector2 v2 = (centr + radius * new CCVector2((float) Math.Cos(theta + increment), (float) Math.Sin(theta + increment))) * PTMRatio; primitiveBatch.AddVertex(ref v1, col, PrimitiveType.LineList); primitiveBatch.AddVertex(ref v2, col, PrimitiveType.LineList); theta += increment; } }
public static void DrawPoints(b2Vec2[] points, float size, b2Color color) { DrawPoints(points, points.Length, size, color); }
public override void DrawSolidCircle(b2Vec2 center, float radius, b2Vec2 axis, b2Color color) { DrawCircle(center, radius, color); }
protected virtual void Draw(Settings settings) { m_world.DrawDebugData(); if (settings.drawStats) { int bodyCount = m_world.BodyCount; int contactCount = m_world.ContactCount; int jointCount = m_world.JointCount; m_debugDraw.DrawString(5, m_textLine, "bodies/contacts/joints = {0}/{1}/{2}", bodyCount, contactCount, jointCount); m_textLine += 15; int proxyCount = m_world.GetProxyCount(); int height = m_world.GetTreeHeight(); int balance = m_world.GetTreeBalance(); float quality = m_world.GetTreeQuality(); m_debugDraw.DrawString(5, m_textLine, "proxies/height/balance/quality = {0}/{1}/{2}/{3}", proxyCount, height, balance, quality); m_textLine += 15; } #if PROFILING // Track maximum profile times { b2Profile p = m_world.Profile; m_maxProfile.step = Math.Max(m_maxProfile.step, p.step); m_maxProfile.collide = Math.Max(m_maxProfile.collide, p.collide); m_maxProfile.solve = Math.Max(m_maxProfile.solve, p.solve); m_maxProfile.solveInit = Math.Max(m_maxProfile.solveInit, p.solveInit); m_maxProfile.solveVelocity = Math.Max(m_maxProfile.solveVelocity, p.solveVelocity); m_maxProfile.solvePosition = Math.Max(m_maxProfile.solvePosition, p.solvePosition); m_maxProfile.solveTOI = Math.Max(m_maxProfile.solveTOI, p.solveTOI); m_maxProfile.broadphase = Math.Max(m_maxProfile.broadphase, p.broadphase); m_totalProfile.step += p.step; m_totalProfile.collide += p.collide; m_totalProfile.solve += p.solve; m_totalProfile.solveInit += p.solveInit; m_totalProfile.solveVelocity += p.solveVelocity; m_totalProfile.solvePosition += p.solvePosition; m_totalProfile.solveTOI += p.solveTOI; m_totalProfile.broadphase += p.broadphase; } if (settings.drawProfile) { b2Profile p = m_world.Profile; b2Profile aveProfile = new b2Profile(); if (m_stepCount > 0) { float scale = 1.0f / m_stepCount; aveProfile.step = scale * m_totalProfile.step; aveProfile.collide = scale * m_totalProfile.collide; aveProfile.solve = scale * m_totalProfile.solve; aveProfile.solveInit = scale * m_totalProfile.solveInit; aveProfile.solveVelocity = scale * m_totalProfile.solveVelocity; aveProfile.solvePosition = scale * m_totalProfile.solvePosition; aveProfile.solveTOI = scale * m_totalProfile.solveTOI; aveProfile.broadphase = scale * m_totalProfile.broadphase; } m_debugDraw.DrawString(5, m_textLine, "step [ave] (max) = {0:00000.00} [{1:000000.00}] ({2:000000.00})", p.step, aveProfile.step, m_maxProfile.step); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "collide [ave] (max) = {0:00000.00} [{1:000000.00}] ({2:000000.00})", p.collide, aveProfile.collide, m_maxProfile.collide); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solve [ave] (max) = {0:00000.00} [{1:000000.00}] ({2:000000.00})", p.solve, aveProfile.solve, m_maxProfile.solve); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solve init [ave] (max) = {0:00000.00} [{1:000000.00}] ({2:000000.00})", p.solveInit, aveProfile.solveInit, m_maxProfile.solveInit); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solve velocity [ave] (max) = {0:00000.00} [{1:000000.00}] ({2:000000.00})", p.solveVelocity, aveProfile.solveVelocity, m_maxProfile.solveVelocity); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solve position [ave] (max) = {0:00000.00} [{1:000000.00}] ({2:000000.00})", p.solvePosition, aveProfile.solvePosition, m_maxProfile.solvePosition); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "solveTOI [ave] (max) = {0:00000.00} [{1:000000.00}] ({2:000000.00})", p.solveTOI, aveProfile.solveTOI, m_maxProfile.solveTOI); m_textLine += 15; m_debugDraw.DrawString(5, m_textLine, "broad-phase [ave] (max) = {0:00000.00} [{1:000000.00}] ({2:000000.00})", p.broadphase, aveProfile.broadphase, m_maxProfile.broadphase); m_textLine += 15; } #endif if (m_mouseJoint != null) { b2Vec2 p1 = m_mouseJoint.GetAnchorB(); b2Vec2 p2 = m_mouseJoint.GetTarget(); b2Color c = new b2Color(); c.Set(0.0f, 1.0f, 0.0f); m_debugDraw.DrawPoint(p1, 4.0f, c); m_debugDraw.DrawPoint(p2, 4.0f, c); c.Set(0.8f, 0.8f, 0.8f); m_debugDraw.DrawSegment(p1, p2, c); } if (m_bombSpawning) { b2Color c = new b2Color(); c.Set(0.0f, 0.0f, 1.0f); m_debugDraw.DrawPoint(m_bombSpawnPoint, 4.0f, c); c.Set(0.8f, 0.8f, 0.8f); m_debugDraw.DrawSegment(m_mouseWorld, m_bombSpawnPoint, c); } if (settings.drawContactPoints) { //const float32 k_impulseScale = 0.1f; float k_axisScale = 0.3f; for (int i = 0; i < m_pointCount; ++i) { ContactPoint point = m_points[i]; if (point.state == b2PointState.b2_addState) { // Add m_debugDraw.DrawPoint(point.position, 10.0f, new b2Color(0.3f, 0.95f, 0.3f)); } else if (point.state == b2PointState.b2_persistState) { // Persist m_debugDraw.DrawPoint(point.position, 5.0f, new b2Color(0.3f, 0.3f, 0.95f)); } if (settings.drawContactNormals == 1) { b2Vec2 p1 = point.position; b2Vec2 p2 = p1 + k_axisScale * point.normal; m_debugDraw.DrawSegment(p1, p2, new b2Color(0.9f, 0.9f, 0.9f)); } else if (settings.drawContactForces == 1) { //b2Vec2 p1 = point->position; //b2Vec2 p2 = p1 + k_forceScale * point->normalForce * point->normal; //DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } if (settings.drawFrictionForces == 1) { //b2Vec2 tangent = b2Cross(point->normal, 1.0f); //b2Vec2 p1 = point->position; //b2Vec2 p2 = p1 + k_forceScale * point->tangentForce * tangent; //DrawSegment(p1, p2, b2Color(0.9f, 0.9f, 0.3f)); } } } }