如何在Libgdx Box2d中获取一个物体的每个夹具的位置?似乎固定装置没有位置吸气器。如果这个问题是幼稚的,但我才刚开始学习Box2d。
发布于 2013-10-06 18:14:12
从您的box2d身体中获取所有夹具的列表。每个夹具都有其形状。如果形状是CircleShape类型,那么您可以使用一个getPosition()方法。然而,检索到的位置相对于box2d主体在b2World中的位置。
发布于 2013-11-02 13:41:00
一旦您了解了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!简单!
但是如果你有一个多边形而不是一个圆呢?再放轻松点!只需将转换应用到形状中的每个顶点。
https://stackoverflow.com/questions/19211881
复制相似问题