I'm constructing a Body
(a box2d body using AndEngine) using multiple Fixture
s and later I need to get the world position of these Fixture
s.
Currently I am trying something like this;
// Declarations
Body body;
Fixture centerFixture;
Fixture leftFixture;
Vector2 centerPos = new Vector2(0, 0);
Vector2 leftPos = new Vector2(-1.5f, -1.5f);
void setup() {
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(new Vector2(10, 10));
body = physicsWorld.createBody(bodyDef);
PolygonShape centerShape = new PolygonShape();
centerShape.setAsBox(1, 1, centerPos, 0);
FixtureDef centerDef = new FixtureDef();
centerDef.density=1;
centerDef.shape=centerShape;
centerFixture = body.createFixture(centerDef);
PolygonShape leftShape = new PolygonShape();
leftShape.setAsBox(0.5f, 0.5f, leftPos, 0);
FixtureDef leftDef = new FixtureDef();
leftDef.density=1;
leftDef.shape=centerShape;
leftFixture = body.createFixtureleftDef);
}
void someFunction() {
Transform transform = body.getTransform();
Vector2 temp = new Vector2(leftPos);
// These two seems to not be the center of the fixture
Vector2 worldPosition = transform.mul(temp);
Vector2 pixelPosition = new Vector2(worldPosition.x * PhysicsConstants.PIXELS_PER_METER, worldPosition.y * PhysicsConstants.PIXELS_PER_METER);
}
But is seems that as the body
rotates the worldPosition
is off.
How do I get the world position of the Fixture
?