DebugDraw and How to Account for PTM

Topics: Physics
Mar 22, 2014 at 7:16 PM
I believe I am working with the latest source code and have noted in the box2d debugdraw setup that there is no accounting for the PTM ratio so that, for instance, shapes will get drawn to the correct size and location on your game screen when enabled.

Background:
I followed the Box2dTest source code to get my debug draw in place, but did not see any shapes being drawn. Tracing into the source code (sweetness!), I noted that the vertices that were being extracted remained in their box2d transforms when passed off to the drawing functions (e.g., CCBox2dDraw.DrawSolidPolygon)

I was able to get polygon shapes to be visible on the screen by modify CCBox2dDraw.DrawSolidPolygon as follows:

var vert0 = new b2Vec2(vertices[0].x * 50f, vertices[0].y * 50f);
var vert1 = new b2Vec2(vertices[i].x * 50f, vertices[i].y * 50f);
var vert2 = new b2Vec2(vertices[i + 1].x * 50f, vertices[i+1].y * 50f);

_primitiveBatch.AddVertex(vert0.ToVector2(), colorFill, PrimitiveType.TriangleList);
_primitiveBatch.AddVertex(vert1.ToVector2(), colorFill, PrimitiveType.TriangleList);
_primitiveBatch.AddVertex(vert2.ToVector2(), colorFill, PrimitiveType.TriangleList);

Where 50f in the code above is my PTM_RATIO. Is the ability to specify your PTM_RATIO to debugdraw coming in a furture release or am I mistaken in how I am doing this?

Let me know when you get a chance.

Cheers,
Bill

P.S., This is a cool framework.
Coordinator
Mar 22, 2014 at 7:52 PM
Yo Bill!

There are 3 box2d sets of tests.
  1. Farseer "box2d"
  2. Old skool box2d
  3. The coolest and fastest .NET box2d
Start with the #3 tests and you will see that the PTM_RATIO is being used. Box2d doesn't do any of that for you - that's up to you. The PTM ratio is for the mapping of your box2d world to your visible world. The box2d framework won't do any transforms in that regard.

Here is where you start:

https://github.com/Cocos2DXNA/cocos2d-xna/tree/master/tests/tests/classes/tests/Box2DTestBet(Box2D)

here is how the tests manage the world setup:

https://github.com/Cocos2DXNA/cocos2d-xna/blob/master/tests/tests/classes/tests/Box2DTestBet(Box2D)/Test.cs

What you need to look at is the CCBox2dDraw class.