Drawing Box2d Output - Getting VerticesBlitzMax Modules Forums/Brucey's Modules/Drawing Box2d Output - Getting Vertices
| Hello, I've been trying to find out how to draw my shapes in box2d. I wanted to convert the HelloWorld program to use an arbitrary polygon (rather than a box) and draw its output. (instead of printing it).|
I would guess that you could use Debug Draw, but I'm not sure how to use this outside of the example programs. Could anyone give an example?
Is it possible to use my own drawing commands? - if I could get the positions of all the vertices then I could just draw a line between them. I would like this, since it would make me feel I could easily change the way objects are drawn. The HelloWorld program, only returns a single position (presumably at the origin of the object), and an angle. I know CHipmunk has a GetVerts method that returns all the vertex positions in the shape. Does box2D have one? (I can't find it in the manual).
| You could use |
Local _debugDraw:b2DebugDraw = New debugDraw
in conjunction with
Do not forget to create the debugDraw Type like this :
Type debugDraw Extends b2DebugDraw ... End Type
Every methods to implement inside your new debugDraw type is explain in the documentation.
There's example of this rendering Type inside "render.bmx"
You can use your own drawing commands as well.
Implementing the DebugDraw type is the best solution to render things like "Gridwar".
You could also store the array of vertices inside the userdata of every shape or simply add a 'Field vertices:b2Vec2' inside every Type of your game if you're using Oriented Object design.
As shape cannot be modified in real time (without "re-creating" them) it's not necessarily useful to know each vertices for rendering fixed image of them. Angle and position should be enough.
| Ok Thanks. I just thought it would be useful to know the position of each and every vertex, although I suppose you can work them out if you have the angle and position anyway. Thank you again.|