Box2d夹具位置

Mus*_*afa 3 java box2d libgdx

如何在Libgdx Box2d中获得一体的每个夹具的位置?看起来固定装置没有位置吸气剂.索里,如果这个问题是noobish但我刚开始学习Box2d.

小智 9

一旦你知道,这很容易Transform.

我们以圆形夹具为例,因为它们最容易展示.

// we need to get the body's position, let's use a Vector2 to store it.
Vector2 vec = new Vector2();
Body body = fixture.getBody();

// what is this magic? Why, it's a wonderful object that transforms fixture
// position information based on the body's position!
Transform transform = body.getTransform();

CircleShape shape = (CircleShape) fixture.getShape();
vec.set(shape.getPosition());
// apply the transformation
transform.mul(vec);
// now vec.x and vec.y will be what you want!
Run Code Online (Sandbox Code Playgroud)

简单!

但是如果你有一个多边形而不是圆形怎么办?再简单!只需将变换应用于形状中的每个顶点即可.