enabling the debug draw

Discuss issues specific the Python port of Box2D
poorya
Posts: 1
Joined: Thu Apr 17, 2014 4:26 am

enabling the debug draw

Postby poorya » Thu Apr 17, 2014 4:50 am

Hi everyone

I'm using box2d and pyglet to make a simple demo.
All I want is to enable the debug draw method to see what's going on underneath, so I don't have to put test sprites for everything i draw.

I've used box2d in Java before, and in Java, it's as simple as enabling the debug renderer and it's done! But I don't know if that's possible in python.
I saw some solutions suggesting that I should implement the class b2draw manually and put my code in the draw methods. I tried it to some extend but I have no clue what i'm doing. :?

so here's the code from the b2Draw class that I'm trying to change to make it draw a circle so far:

Code: Select all

class DebugDraw(Box2D.b2Draw):
    def __init__(self):
        super(DebugDraw,self).__init__()

    def DrawCircle(self, *args, **kwargs):

        """
        DrawCircle(b2Draw self, b2Vec2 center, float32 radius, b2Color color)
        Draw a circle.
        """
        return _Box2D.b2Draw_DrawCircle(self, *args, **kwargs)


Could someone point me to the right direction ?
Thanks

tuschcarsten
Posts: 2
Joined: Fri Aug 07, 2015 12:47 am

Re: enabling the debug draw

Postby tuschcarsten » Sat Aug 08, 2015 5:35 am

Hi,

even if this post is really old, I'll try to answer as good as I can, for the case that someone comes across this thread having the same problem.

Your implementation of the Box2D.b2Draw class should override the draw-methods in order to tell Box2D how to draw.
That means that your DrawCircle-Method should contain pyglet code, which draws a circle, using the parameters center, radius and color.

I dodn't know how you do it in pyglet, but in pygame you use this to draw a circle:

Code: Select all

pygame.draw.circle(surface, color, pos, radius, thickness)

Where the surface is the pygame surface you want to draw on, the color is a 4-tuple (r,g,b,a), pos is a 2-tuple (x,y), radius is an int and thickness is also an int (the thickness of the line which is drawn).

You should be able to translate this into pyglet.

The other methods (DrawPolygon etc.) should be implemented similarly.


Return to “Python”



Who is online

Users browsing this forum: No registered users and 1 guest