Ejemplo n.º 1
0
        public void DebugDraw()
        {
            if (_space == null)
            {
                return;
            }

            DrawString(15, 15, string.Format("Step: {0}", _space.stamp));
            DrawString(15, 50, string.Format("Bodies : {0}/{1}", _space.dynamicBodies.Count + _space.staticBodies.Count, _space.dynamicBodies.Capacity));
            DrawString(15, 80, string.Format("Arbiters: {0}/{1}", _space.arbiters.Count, _space.arbiters.Capacity));

            if (Flags.HasFlag(PhysicsDrawFlags.All) || Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.Shapes))
            {
                _space.EachShape(DrawShape);
            }

            if (Flags.HasFlag(PhysicsDrawFlags.Joints) || Flags.HasFlag(PhysicsDrawFlags.All))
            {
                _space.EachConstraint(DrawConstraint);
            }

            var contacts = 0;

            if (Flags.HasFlag(PhysicsDrawFlags.All) || Flags.HasFlag(PhysicsDrawFlags.ContactPoints))
            {
                for (var i = 0; i < _space.arbiters.Count; i++)
                {
                    for (int j = 0; j < _space.arbiters[i].contacts.Count; j++)
                    {
                        Draw(_space.arbiters[i].contacts[j]);
                    }
                    contacts += _space.arbiters[i].contacts.Count;
                }
            }

            DrawString(15, 110, "Contact points: " + contacts);
            DrawString(15, 140, string.Format("Nodes:{1} Leaf:{0} Pairs:{2}", cp.numLeaves, cp.numNodes, cp.numPairs));

            base.Draw();
            base.Clear();
        }
Ejemplo n.º 2
0
        public void DrawShape(cpShape shape)
        {
            cpBody  body  = shape.body;
            cpColor color = cp.GetShapeColor(shape);              // ColorForBody(body);

            switch (shape.shapeType)
            {
            case cpShapeType.Circle: {
                cpCircleShape circle = (cpCircleShape)shape;

                if (Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    drawDelegate.Draw(circle.bb);
                }

                if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    drawDelegate.Draw(circle, color);
                }
            }
            break;

            case cpShapeType.Segment: {
                cpSegmentShape seg = (cpSegmentShape)shape;
                if (Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    drawDelegate.Draw(seg.bb);
                }

                if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    drawDelegate.Draw(seg, color);
                }
            }
            break;

            case cpShapeType.Polygon: {
                cpPolyShape poly = (cpPolyShape)shape;
                if (Flags.HasFlag(PhysicsDrawFlags.BB) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    drawDelegate.Draw(poly.bb);
                }

                if (Flags.HasFlag(PhysicsDrawFlags.Shapes) || Flags.HasFlag(PhysicsDrawFlags.All))
                {
                    drawDelegate.Draw(poly, color);
                }
            }
            break;

            default:
                cp.AssertHard(false, "Bad assertion in DrawShape()");
                break;
            }
        }