[英]Box2d fixture position
如何在Libgdx Box2d中獲得一體的每個夾具的位置? 看起來固定裝置沒有位置吸氣劑。 索里,如果這個問題是noobish但我剛開始學習Box2d。
一旦你了解了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!
簡單!
但是如果你有一個多邊形而不是圓形怎么辦? 再簡單! 只需將變換應用於形狀中的每個頂點即可。
從你的box2d機構獲取所有燈具的列表。 為每個夾具得到它的形狀 。 如果形狀是CircleShape類型,那么您可以使用getPosition()方法。 但是,檢索到的位置是相對於b2World中box2d主體的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.