Body b;
while ((b=box2d.physics.PhysicssWorld.world.getBodyList().getNext())!=null) {
Shape shape;
while ((shape=b.getShapeList().getNext())!=null) {
Log.e("name",""+b.getUserData().toString()+" "+shape+" ");
opengl.saveMatrix();
Meshes.select(b.getUserData().toString())
.translate((b.getPosition().x)*RATIO, (b.getPosition().y)*RATIO)
.rotate((int) ((int) b.getAngle()* (180 / Math.PI)), 0, 0, 1)
.draw(shape, 1,1,1);
opengl.loadMatrix();
}
}
I d like to get my bodies’s shape, but i cant get anything, only null.. why?
never run this line: Log.e(“name”,””+b.getUserData().toString()+” “+shape+” “);
so shape=b.getShapeList().getNext()) always null…
I’m just starting out with Box2D myself. So far as I understand the library, the primary means of getting the shapes of bodies is through their fixtures. From the fixture you get a b2Shape pointer – but, because its methods are virtual, you’ll probably need to cast it as a b2PolygonShape/b2CircleShape pointer for it to be useful. Here’s some code along those lines:
Some other things to note: the .getNext() function of b2Body returns a pointer – this is an implementation of a linked list. The same is true for b2Fixture::GetNext(). There’s some unfamiliar stuff (to me) in your code, so I can’t say for sure, but it might work fine if you simply go through and make sure your variables match up with the return types of the Box2D functions.