0

我使用 Farseer Physics Engine 进行泵模拟。在那里的例子中,他们总是使用 texture2d 格式。但是该泵形状仅给出了 Point(x,y) 数组。

我想从那个点数组制作多边形或纹理2d。

PolygonTools.CreatePolygon 方法需要 int[] 和 width,而不是 point[]。

我不知道如何通过 int[] 和宽度制作多边形。

请帮忙。

4

1 回答 1

0

所以你希望从数组创建一个texture2d...嗯...我会尝试解释我将如何尝试这个,这不是工作示例,只是提示如何去做。

首先你需要找到 with 和 height,所以找到 max X 和 max Y 来创建空白纹理。

Texture2D blankTexture = new Texture2D(GraphicsDevice, maxX, maxY, false, SurfaceFormat.Color);

然后循环纹理并从数组中设置像素颜色

for(int i=0; i<blankTexture .width; i++)
{
  for(int j=0; j<blankTexture .height; j++)
  {
    // pixel = texture.GetPixel(i, j); 
    // loop over array, and if pointX in array = i and pointY in array = j then
    pixel.Color = Color.White; //
  }
}

我认为这是相当 cpu 昂贵的方式......但它可以工作。

于 2013-11-06T10:18:05.067 回答