c++ - Knowing if middle vertex is left or right when sorting a triangle vertices by Y? -


i'm reading chris hecker's texture mapping articles , life of me can't understand how he's using y order of vertices determine if middle vertex on left or right.

sorting code:

    if (y0 < y1)     {         if (y2 < y0)         {             top = 2; middle = 0; bottom = 1;             middlecompare = 0; bottomcompare = 1;         }         else         {             top = 0;             if (y1 < y2)             {                 middle = 1; bottom = 2;                 middlecompare = 1; bottomcompare = 2;             }             else             {                 middle = 2; bottom = 1;                 middlecompare = 2; bottomcompare = 1;             }         }     }     else     {         if (y2 < y1)         {             top = 2; middle = 1; bottom = 0;             middlecompare = 1; bottomcompare = 0;         }         else         {             top = 1;             if (y0 < y2)             {                 middle = 0; bottom = 2;                 middlecompare = 3; bottomcompare = 2;             }             else             {                 middle = 2; bottom = 0;                 middlecompare = 2; bottomcompare = 3;             }         }     } 

then writes:

if (bottomcompare > middlecompare) {     middleisleft = 0;     left = &toptobottom; right = &toptomiddle; } else {     middleisleft = 1;     left = &toptomiddle; right = &toptobottom; } 

my questions:

  • how relying on y order tell if middle vertex left or right? it's confusing cause sorting done on y, there no mention of x.
  • obviously, bottomcompare , middlecompare variables exist achieve comparison. in first half of comparison (the 'if'), middlecompare equals middle , bottomcompare equals bottom. in second half (the 'else') bottomcompare equals 3 when bottom equals 0, , middlecompare equals 3 when middle equals 0. why that?

what missing is:

  1. the polygon winding rule.

    the vertexes of triangle/polygon should in specific order cw/ccw.

  2. you should deciding target side line not point.

    deciding single point mistake points in both sides.

so example if:

  • order cw
  • x+ axis goes right
  • y+ axis goes down
  • vertexes a,b,c

example

then decide left/right side change in y axis. while rasterizing of outlines (ab,bc,ca) @ y change between first , last point. example ab line:

dy = (b.y-a.y) if (dy> 0) right if (dy< 0) left if (dy==0) both 

for more info see related q/a closed convex polygon filling.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -