public override void DrawSolidCircle(Vec2 center, float radius, Vec2 axis, ColorF color) { float k_segments = (int)(1024.0f * (radius / 50)); float k_increment = (float)(2.0f * Math.PI / k_segments); float theta = 0.0f; Gl.glEnable(Gl.GL_BLEND); Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glColor4f(0.5f * color.R, 0.5f * color.G, 0.5f * color.B, 0.5f); Gl.glBegin(Gl.GL_TRIANGLE_FAN); for (int i = 0; i < k_segments; ++i) { Vec2 v = center + radius * new Vec2((float)Math.Cos(theta), (float)Math.Sin(theta)); Gl.glVertex2f(v.X, v.Y); theta += k_increment; } Gl.glEnd(); Gl.glDisable(Gl.GL_BLEND); theta = 0.0f; Gl.glColor4f(color.R, color.G, color.B, 1.0f); Gl.glBegin(Gl.GL_LINE_LOOP); for (int i = 0; i < k_segments; ++i) { Vec2 v = center + radius * new Vec2((float)Math.Cos(theta), (float)Math.Sin(theta)); Gl.glVertex2f(v.X, v.Y); theta += k_increment; } Gl.glEnd(); Vec2 p = center + radius * axis; Gl.glBegin(Gl.GL_LINES); Gl.glVertex2f(center.X, center.Y); Gl.glVertex2f(p.X, p.Y); Gl.glEnd(); }
public override void DrawSegment(Vec2 p1, Vec2 p2, ColorF color) { Gl.glColor3f(color.R, color.G, color.B); Gl.glBegin(Gl.GL_LINES); Gl.glVertex2f(p1.X, p1.Y); Gl.glVertex2f(p2.X, p2.Y); Gl.glEnd(); }
public void DrawPoint(Vec2 p, float size, ColorF color) { Gl.glPointSize(size); Gl.glBegin(Gl.GL_POINTS); Gl.glColor3f(color.R, color.G, color.B); Gl.glVertex2f(p.X, p.Y); Gl.glEnd(); Gl.glPointSize(1.0f); }
public void DrawAABB(AABB aabb, ColorF c) { Gl.glColor3f(c.R, c.G, c.B); Gl.glBegin(Gl.GL_LINE_LOOP); Gl.glVertex2f(aabb.LowerBound.X, aabb.LowerBound.Y); Gl.glVertex2f(aabb.UpperBound.X, aabb.LowerBound.Y); Gl.glVertex2f(aabb.UpperBound.X, aabb.UpperBound.Y); Gl.glVertex2f(aabb.LowerBound.X, aabb.UpperBound.Y); Gl.glEnd(); }
public override void DrawPolygon(Vec2[] vertices, int vertexCount, ColorF color) { Gl.glColor3f(color.R, color.G, color.B); Gl.glBegin(Gl.GL_LINE_LOOP); for (int i = 0; i < vertexCount; ++i) { Gl.glVertex2f(vertices[i].X, vertices[i].Y); } Gl.glEnd(); }
public override void DrawCircle(Vec2 center, float radius, ColorF color) { float k_segments = (int)(1024.0f * (radius / 50)); float k_increment = (float)(2.0f * Math.PI / k_segments); float theta = 0.0f; Gl.glColor3f(color.R, color.G, color.B); Gl.glBegin(Gl.GL_LINE_LOOP); for (int i = 0; i < k_segments; ++i) { Vec2 v = center + radius * new Vec2((float)Math.Cos(theta), (float)Math.Sin(theta)); Gl.glVertex2f(v.X, v.Y); theta += k_increment; } Gl.glEnd(); }
void UpdateDraw() { // Process events renderWindow.DispatchEvents(); // Clear the window renderWindow.Clear(); Gl.glClearColor((float)BackColor.R / 255.0f, (float)BackColor.G / 255.0f, (float)BackColor.B / 255.0f, 1); Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT); Gl.glMatrixMode(Gl.GL_MODELVIEW); Gl.glLoadIdentity(); // Draw //test.m_world.DrawDebugData(); //DrawTest(); Gl.glBegin(Gl.GL_LINES); Gl.glColor4ub(0, 255, 0, 64); Gl.glVertex2f(0, 10); Gl.glVertex2f(0, -10); Gl.glColor4ub(255, 0, 0, 64); Gl.glVertex2f(10, 0); Gl.glVertex2f(-10, 0); Gl.glEnd(); if (!_testing) { foreach (var x in WorldObject.Bodies) { var xf = new Transform(x.Body.Position, new Mat22(x.Body.Angle)); foreach (var fixture in x.Fixtures) { ColorF color = new ColorF(0.9f, 0.7f, 0.7f); if (SelectedNode.NodeType == SelectedNodeType.Body && x == SelectedNode.BodyNode) color = new ColorF(1, 1, 0); else if (HoverBody != null && x.Body == HoverBody.Body) color = new ColorF(1, 0, 0); else if (!x.Body.Active) color = new ColorF(0.5f, 0.5f, 0.3f); else if (x.Body.BodyType == BodyType.Static) color = new ColorF(0.5f, 0.9f, 0.5f); else if (x.Body.BodyType == BodyType.Kinematic) color = new ColorF(0.5f, 0.5f, 0.9f); else if (x.Body.Awake) color = new ColorF(0.6f, 0.6f, 0.6f); debugDraw.DrawShape(fixture.Fixture, xf, color); } debugDraw.DrawTransform(xf); } if (HoverBody != null && !string.IsNullOrEmpty(HoverBody.Name)) { Vec2 p = ConvertScreenToWorld(CursorPos.X, CursorPos.Y); TestDebugDraw.DrawStringFollow(p.X, p.Y, HoverBody.Name); } /*foreach (var x in WorldObject.Joints) { Vec2 a1 = Vec2.Empty, a2 = Vec2.Empty; switch (x.Joint.JointType) { case JointType.Revolute: a1 = ((RevoluteJointDef)x.Joint).LocalAnchorA; a2 = ((RevoluteJointDef)x.Joint).LocalAnchorB; break; case JointType.Friction: a1 = ((FrictionJointDef)x.Joint).LocalAnchorA; a2 = ((FrictionJointDef)x.Joint).LocalAnchorB; break; case JointType.Line: a1 = ((LineJointDef)x.Joint).LocalAnchorA; a2 = ((LineJointDef)x.Joint).LocalAnchorB; break; case JointType.Prismatic: a1 = ((PrismaticJointDef)x.Joint).LocalAnchorA; a2 = ((PrismaticJointDef)x.Joint).LocalAnchorB; break; case JointType.Weld: a1 = ((WeldJointDef)x.Joint).LocalAnchorA; a2 = ((WeldJointDef)x.Joint).LocalAnchorB; break; } debugDraw.DrawJoint(x, a1, a2, WorldObject.Bodies[x.BodyAIndex].Body, WorldObject.Bodies[x.BodyBIndex].Body); }*/ } else _world.DrawDebugData(); renderWindow.Display(); }
public void DrawJoint(Box2CS.Serialize.JointDefSerialized x, Vec2 p1, Vec2 p2, BodyDef bodyA, BodyDef bodyB) { Transform xf1 = new Transform(bodyA.Position, new Mat22(bodyA.Angle)); Transform xf2 = new Transform(bodyB.Position, new Mat22(bodyB.Angle)); Vec2 x1 = xf1.Position; Vec2 x2 = xf2.Position; p1 = xf1 * p1; p2 = xf2 * p2; ColorF color = new ColorF(0.5f, 0.8f, 0.8f); switch (x.Joint.JointType) { case JointType.Distance: DrawSegment(p1, p2, color); break; case JointType.Pulley: { PulleyJointDef pulley = (PulleyJointDef)x.Joint; Vec2 s1 = pulley.GroundAnchorA; Vec2 s2 = pulley.GroundAnchorB; DrawSegment(s1, p1, color); DrawSegment(s2, p2, color); DrawSegment(s1, s2, color); } break; case JointType.Revolute: { RevoluteJointDef rjd = (RevoluteJointDef)x.Joint; if (rjd.EnableLimit) { Vec2 startPos = p1; Vec2 sinCos = new Vec2(-(float)Math.Cos((rjd.UpperAngle + rjd.ReferenceAngle) - (float)Math.PI / 2), -(float)Math.Sin((rjd.UpperAngle + rjd.ReferenceAngle) - (float)Math.PI / 2)); var end = startPos + (sinCos * 3); DrawSegment(startPos, end, new ColorF(0, 0.65f, 0.65f)); sinCos = new Vec2(-(float)Math.Cos((rjd.LowerAngle + rjd.ReferenceAngle) - (float)Math.PI / 2), -(float)Math.Sin((rjd.LowerAngle + rjd.ReferenceAngle) - (float)Math.PI / 2)); end = startPos + (sinCos * 3); DrawSegment(startPos, end, new ColorF(0, 0.65f, 0.65f)); DrawArc(startPos, 3, (-rjd.LowerAngle - rjd.ReferenceAngle), (-rjd.UpperAngle - rjd.ReferenceAngle)); } DrawCircle(p1, 0.75f, new ColorF(0, 0.65f, 0.65f)); DrawSegment(x1, p1, color); DrawSegment(p1, p2, color); DrawSegment(x2, p2, color); } break; default: case JointType.Unknown: DrawSegment(x1, p1, color); DrawSegment(p1, p2, color); DrawSegment(x2, p2, color); break; } }
public override void DrawSolidPolygon(Vec2[] vertices, int vertexCount, ColorF color) { Gl.glColor4f(0.5f * color.R, 0.5f * color.G, 0.5f * color.B, 0.5f); Gl.glBegin(Gl.GL_TRIANGLE_FAN); for (int i = 0; i < vertexCount; ++i) { Gl.glVertex2f(vertices[i].X, vertices[i].Y); } Gl.glEnd(); Gl.glColor4f(color.R, color.G, color.B, 1.0f); Gl.glBegin(Gl.GL_LINE_LOOP); for (int i = 0; i < vertexCount; ++i) { Gl.glVertex2f(vertices[i].X, vertices[i].Y); } Gl.glEnd(); }
public void DrawShape(FixtureDef fixture, Transform xf, ColorF color) { switch (fixture.Shape.ShapeType) { case ShapeType.Circle: { CircleShape circle = (CircleShape)fixture.Shape; Vec2 center = (xf * circle.Position); float radius = circle.Radius; Vec2 axis = xf.R.Col1; DrawSolidCircle(center, radius, axis, color); } break; case ShapeType.Polygon: { PolygonShape poly = (PolygonShape)fixture.Shape; int vertexCount = poly.VertexCount; //b2Assert(vertexCount <= b2_maxPolygonVertices); for (int i = 0; i < vertexCount; ++i) drawVertices[i] = (xf * poly.Vertices[i]); DrawSolidPolygon(drawVertices, vertexCount, color); } break; } }
public abstract void DrawSolidPolygon(Vec2[] vertices, int vertexCount, ColorF color);
public abstract void DrawSolidCircle(Vec2 center, float radius, Vec2 axis, ColorF color);
public abstract void DrawSegment(Vec2 p1, Vec2 p2, ColorF color);
public abstract void DrawCircle(Vec2 center, float radius, ColorF color);
public override void DrawSolidPolygon(Vec2[] vertices, int vertexCount, ColorF color) { Gl.glEnable(Gl.GL_BLEND); Gl.glBlendFunc(Gl.GL_SRC_ALPHA, Gl.GL_ONE_MINUS_SRC_ALPHA); Gl.glColor4f(0.5f * color.R, 0.5f * color.G, 0.5f * color.B, 0.5f); Gl.glBegin(Gl.GL_TRIANGLE_FAN); for (int i = 0; i < vertexCount; ++i) { Gl.glVertex2f(vertices[i].X, vertices[i].Y); } Gl.glEnd(); Gl.glDisable(Gl.GL_BLEND); Gl.glColor4f(color.R, color.G, color.B, 1.0f); Gl.glBegin(Gl.GL_LINE_LOOP); for (int i = 0; i < vertexCount; ++i) { Gl.glVertex2f(vertices[i].X, vertices[i].Y); } Gl.glEnd(); }