I'm reading Chris Hecker's Texture Mapping articles and for the life of me I can't understand how he's using the Y order of vertices to determine if the middle vertex was on the 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 he writes:
if (BottomCompare > MiddleCompare)
{
MiddleIsLeft = 0;
Left = &TopToBottom; Right = &TopToMiddle;
}
else
{
MiddleIsLeft = 1;
Left = &TopToMiddle; Right = &TopToBottom;
}
My questions:
- How are we relying on the Y order to tell if the middle vertex is left or right? It's really confusing cause the sorting is only done on Y, there was no mention of X.
- Obviously, the
BottomCompare
andMiddleCompare
variables exist to achieve the comparison. In the first half of the comparison (the 'if'),MiddleCompare
equalsMiddle
andBottomCompare
equalsBottom
. But in the second half (the 'else')BottomCompare
equals3
whenBottom
equals0
, andMiddleCompare
equals3
whenMiddle
equals0
. Why is that?