-1

I have problems drawing a box. I'm using coco2d + box2d in c++. Anyone know how can I view exactly the box that box2d is drawing? if I declare this:

b2PolygonShape bps; bps.SetAsBox(2/SCALE_RATIO, 2/SCALE_RATIO);

When another object collides with the box, I have some idea that limits of the box. But how can I view in the screen the 4 lines box that box2d is drawing?

This topic should help me? How to enable Box2d debug draw with Coco2d-x 3.0 beta 2

Thanks

tranthor
  • 1
  • 2

1 Answers1

0

Sounds like some misunderstanding might be occurring.

Box2D has a diagnostics drawing capability but ignore it from a conceptual perspective. From the Box2D FAQ:

Box2D is only a physics engine. How you draw stuff is up to you.

Instead of thinking of Box2D as "drawing" any lines, think of Box2D as simulating the physics of polygons or their edges and corners in the box colliding case. From Box2D's perspective, lengths are in meters, masses in kilograms, and times in seconds (MKS units). Where you place bodies, is conceptually only important in relative terms. I.e. what other bodies are nearby or soon to be. Whether placing bodies at a y value of say -10 is higher than a body at +10 however is up to how you render their locations and what you set gravity to. You can decide to render Box2D's version of y=-10 at the top of a window and y=+10 at the bottom.

If you're unclear about the transformation between your Box2D physical world and your graphics rendering, that's less about Box2D and more about recognizing how mathematical transformations work. From this perspective, you have scaling, translation, and rotation to understand. Higher level rendering APIs usually provide something like a transformation matrix for mapping conceptual points (like from the Box2D physics perspective) to points on your screen.

Hope this helps.

Louis Langholtz
  • 2,913
  • 3
  • 17
  • 40