不規則な2DスプライトFarseer3.3.1のボディを作成しようとしています。BodyFactory.CreateCompoundPolygonメソッドを使用して実行できますか?
1197 次
1 に答える
2
これは私のプロジェクトの1つからの方法です。それは私のアーキテクチャに少し固有ですが、自分で使用できるはずです。
考慮すべきことの1つは、スケーリングです。これは、よく知っているConvertUnits.ToSimUnitsなどに置き換えるのが最適です。
public static Body CreateBodyFromImage(Game game, World world, string textureName)
{
//Load the passed texture.
Texture2D polygonTexture = game.Content.Load<Texture2D>(textureName);
//Use an array to hold the textures data.
uint[] data = new uint[polygonTexture.Width * polygonTexture.Height];
//Transfer the texture data into the array.
polygonTexture.GetData(data);
//Find the verticals that make up the outline of the passed texture shape.
Vertices vertices = PolygonTools.CreatePolygon(data, polygonTexture.Width);
//For now we need to scale the vertices (result is in pixels, we use meters)
Vector2 scale = new Vector2(0.07f, 0.07f);
vertices.Scale(ref scale);
//Partition the concave polygon into a convex one.
var decomposedVertices = BayazitDecomposer.ConvexPartition(vertices);
//Create a single body, that has multiple fixtures to the polygon shapes.
return BodyFactory.CreateCompoundPolygon(world, decomposedVertices, 1f);
}
于 2011-08-26T09:21:41.187 に答える