예제 #1
0
        void DrawShape(Fixture fixture, XForm xf, Color color)
        {
            Color coreColor = ColorEx.FromScRgb(0.9f, 0.6f, 0.6f);

            switch (fixture.ShapeType)
            {
            case ShapeType.Circle:
            {
                CircleShape circle = (CircleShape)fixture.GetShape();

                Vector2 center = MathUtils.Multiply(ref xf, circle._p);
                float   radius = circle._radius;
                Vector2 axis   = xf.R.col1;

                DebugDraw.DrawSolidCircle(center, radius, axis, color);
            }
            break;

            case ShapeType.Polygon:
            {
                PolygonShape poly        = (PolygonShape)fixture.GetShape();
                int          vertexCount = poly._vertexCount;
                Debug.Assert(vertexCount <= Settings.b2_maxPolygonVertices);
                FixedArray8 <Vector2> vertices = new FixedArray8 <Vector2>();

                for (int i = 0; i < vertexCount; ++i)
                {
                    vertices[i] = MathUtils.Multiply(ref xf, poly._vertices[i]);
                }

                DebugDraw.DrawSolidPolygon(ref vertices, vertexCount, color);
            }
            break;
            }
        }
예제 #2
0
        void DrawJoint(Joint joint)
        {
            Body  b1 = joint.GetBody1();
            Body  b2 = joint.GetBody2();
            XForm xf1, xf2;

            b1.GetXForm(out xf1);
            b2.GetXForm(out xf2);
            Vector2 x1 = xf1.Position;
            Vector2 x2 = xf2.Position;
            Vector2 p1 = joint.GetAnchor1();
            Vector2 p2 = joint.GetAnchor2();

            Color color = ColorEx.FromScRgb(0.5f, 0.8f, 0.8f);

            switch (joint.JointType)
            {
            case JointType.Distance:
                DebugDraw.DrawSegment(p1, p2, color);
                break;

            case JointType.Pulley:
            {
                PulleyJoint pulley = (PulleyJoint)joint;
                Vector2     s1     = pulley.GetGroundAnchor1();
                Vector2     s2     = pulley.GetGroundAnchor2();
                DebugDraw.DrawSegment(s1, p1, color);
                DebugDraw.DrawSegment(s2, p2, color);
                DebugDraw.DrawSegment(s1, s2, color);
            }
            break;

            case JointType.Mouse:
                // don't draw this
                break;

            default:
                DebugDraw.DrawSegment(x1, p1, color);
                DebugDraw.DrawSegment(p1, p2, color);
                DebugDraw.DrawSegment(x2, p2, color);
                break;
            }
        }
예제 #3
0
        /// Call this to draw shapes and other debug draw data.
        public void DrawDebugData()
        {
            if (DebugDraw == null)
            {
                return;
            }

            DebugDrawFlags flags = DebugDraw.Flags;

            if ((flags & DebugDrawFlags.Shape) == DebugDrawFlags.Shape)
            {
                for (Body b = _bodyList; b != null; b = b.GetNext())
                {
                    XForm xf;
                    b.GetXForm(out xf);
                    for (Fixture f = b.GetFixtureList(); f != null; f = f.GetNext())
                    {
                        if (b.IsStatic)
                        {
                            DrawShape(f, xf, ColorEx.FromScRgb(0.5f, 0.9f, 0.5f));
                        }
                        else if (b.IsSleeping)
                        {
                            DrawShape(f, xf, ColorEx.FromScRgb(0.5f, 0.5f, 0.9f));
                        }
                        else
                        {
                            DrawShape(f, xf, ColorEx.FromScRgb(0.9f, 0.9f, 0.9f));
                        }
                    }
                }
            }

            if ((flags & DebugDrawFlags.Joint) == DebugDrawFlags.Joint)
            {
                for (Joint j = _jointList; j != null; j = j.GetNext())
                {
                    if (j.JointType != JointType.Mouse)
                    {
                        DrawJoint(j);
                    }
                }
            }

            if ((flags & DebugDrawFlags.Pair) == DebugDrawFlags.Pair)
            {
                // TODO
            }

            if ((flags & DebugDrawFlags.AABB) == DebugDrawFlags.AABB)
            {
                Color      color = ColorEx.FromScRgb(0.9f, 0.3f, 0.9f);
                BroadPhase bp    = _contactManager._broadPhase;

                for (Body b = _bodyList; b != null; b = b.GetNext())
                {
                    for (Fixture f = b.GetFixtureList(); f != null; f = f.GetNext())
                    {
                        AABB aabb;
                        bp.GetAABB(f._proxyId, out aabb);
                        FixedArray8 <Vector2> vs = new FixedArray8 <Vector2>();
                        vs[0] = new Vector2(aabb.lowerBound.X, aabb.lowerBound.Y);
                        vs[1] = new Vector2(aabb.upperBound.X, aabb.lowerBound.Y);
                        vs[2] = new Vector2(aabb.upperBound.X, aabb.upperBound.Y);
                        vs[3] = new Vector2(aabb.lowerBound.X, aabb.upperBound.Y);

                        DebugDraw.DrawPolygon(ref vs, 4, color);
                    }
                }
            }

            if ((flags & DebugDrawFlags.CenterOfMass) == DebugDrawFlags.CenterOfMass)
            {
                for (Body b = _bodyList; b != null; b = b.GetNext())
                {
                    XForm xf;
                    b.GetXForm(out xf);
                    xf.Position = b.GetWorldCenter();
                    DebugDraw.DrawXForm(ref xf);
                }
            }
        }