[xmoto-dev] polygon gap pb fixed

[ Thread Index | Date Index | More lists.tuxfamily.org/xmoto-dev Archives ]


Hi,

i think i fixed the gap problem
(
* [14:04] <keesj> I think it is a well knwn problem that every developer gets when spliting area's in two
[14:05] <keesj> it's a pixel rounding problem
[14:07] <keesj> http://www.gameprogrammer.com/5-poly.html
[14:07] <keesj> If pixels that fall on an edge are counted as part of the polygon then pixels on an edge between two polygons will be filled in by both polygons. Filling the pixel twice is wasteful. And, in an animation it can cause a "twinkling" effect along the edge. If edge pixels are not part of the polygon then edges never get colored and you get gaps between polygons. Really ugly.
)

I applied an algo than rasmus sent me today (make polygon slighly larger on rendering) 0.003 seems to be a good value. To much will make pixels appear over the grass.

Nicolas

   /* fix the gap problem with polygons */
float a = 0.003; /* seems to be a good value, put negativ value to make it worst */
   for(int k=0; k<pPoly->nNumVertices; k++) {
     Vector2f V = Vector2f(pPoly->pVertices[k].x - v_center.x,
               pPoly->pVertices[k].y - v_center.y);
     if(V.length() != 0.0) {
       V.normalize();
       V *= a;
       pPoly->pVertices[k].x += V.x;
       pPoly->pVertices[k].y += V.y;
     }
   }



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/