0

物理的な世界に囲まれたボディによって更新されるポリゴンを定義しようとしています。ここに私の試みがあります:

public Body _body;
public Shape _shape;
_primitiveBatch = new PrimitiveBatch(_game.GraphicsDevice);
_shape = new PolygonShape(_vertices, 1);
Vector2 _position = FarseerPolygon.getCenter(((PolygonShape)_shape).Vertices);
_body = new Body(_world);
_body.Position = _position;
_body.CreateFixture(_shape);
_body.BodyType = BodyType.Dynamic;
_body.Restitution = 0.9f;
_body.Friction = 1f;

体の位置は変わりますが、形は変わりません。Body.CreatePolygon も機能しません。私はここで立ち往生しているので、どんな助けも本当にありがたいです...ありがとう、

4

1 に答える 1

2

ポリゴンは位置を変更することは想定されていません。パフォーマンスの事です。FixtureとそのはShape「モデル空間」((0,0) に近い) に存在し、変化しないように設計されています。次に、Bodyその形状を「ワールド空間」に配置する変換を定義します。

を指定して、ワールド空間でポリゴンの個々のポイントを取得するには、次のようFixture fixtureにします。

var shape = fixture.Shape as PolygonShape;
Transform transform;
fixture.Body.GetTransform(out transform);

foreach(Vector2 vertex in shape.Vertices)
{
    Vector2 theTransformedVertex = MathUtils.Multiply(ref transform, vertex);
}

上記のコードが機能するには、Farseer からのこれらの使用が必要です。

using FarseerPhysics.Collision.Shapes;
using FarseerPhysics.Common;

(このコードは Farseer 3.3.1 に対して書かれています)

于 2013-01-15T02:36:11.020 に答える