Search code examples
xnapolygontexture2dfarseer

how to make texture2d from just point array.(XNA, Farseer Physics Engine)


I use Farseer Physics Engine for pump simulation. In there Example, they always use texture2d format. But that pump shape is given just Point(x,y) Array.

I want to make polygon or texture2d from that point array.

PolygonTools.CreatePolygon method need int[] and width, not point[].

I don`t know how to make polygon by int[] and width.

please help.


Solution

  • so you wish to create a texture2d from array... hm... i will try explain how will i try this, this is not working example just hint how to do it.

    first you need to find with and height, so find max X and max Y to create blank texture.

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

    then loop over texture and set pixel color from your array

    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; //
      }
    }
    

    i think this is quite cpu expensive way... but it could work.