Span * tempSpan = pool.-> aliocSpan ( curSpan );
curSpan -> clipAtX2 ( newSpan -> x1 ); newSpan -> insertAfter ( curSpan ); tempSpan -> clipAtXI ( newSpan -> x2 );
if (ItempSpan -> isEmpty ())
tempSpan -> insertAfter ( newSpan ); else
pool -> freeSpan (tempSpan ); return;
}
else return;
}
}
if (newSpan -> isEmpty ()) return;
prevSpan = curSpan; curSpan = curSpan -> next;
}
newSpan -> insertAfter ( prevSpan );
}
static int findEdge (int& i, int dir, const Polygon3D& p ) {
for(;;) {
int i1 = i + dir:
if (i1< 0 )
i1 = p.numVertices -1;

Компьютерная графика. Полигональные модели

else
if (i1 >= p.numVertices ) i1 = 0;
»
if ( p.vertices [i1].y < p.vertices [i].y ) return -1;
else
if ( p.vertices [i1].y == p.vertices [i].y ) i = i1;
else
return i1;
}
}
void SBuffer:: addPoly ( const Polygon3D& poly )
{
int yMin = (int) poly.vertices [0].y;
int yMax = (int) poly.vertices [0].y;
int topPointlndex = 0;
for (int i = 1; i < poly.numVertices; i++ ) if ( poly.vertices [i].y <
poly.vertices [topPointlndex].y) topPointlndex = i;
else
if ( poly.vertices [i].y > yMax ) yMax = (int) poly.vertices [i].y;
yMin = (int) poly.vertices [topPointlndex].y;
if ( yMin == yMax ) // degenerate polygon {
int iMin = 0; int iMax = 0;
for (i = 1; i < poly.numVertices; i++ ) if ( poly.vertices [i].x <
poly.vertices [iMin].x) iMin = i;
else
if ( poly.vertices [i].x >
poly.vertices [iMax].x) iMax = i;
Span * span = pool -> allocSpan ();
span -> x1 = poly.vertices [iMinJ.x; span -> x2 = poly.vertices [iMax].x; span -> invZ1 =1.0/ poly.vertices [iMinJ.z; span -> invZ2 = 1.0 / poly.vertices [iMax].z; span -> facet = (Polygon3D *) &poly;
addSpan ( yMin, span );
return;
}
int i1, MNext;

10. Удаление невидимых линий и поверхностей

int i2, i2Next;
i1 = topPointlndex;
11 Next = findEdge (i1, -1, poly );
12 = topPointlndex; i2Next = findEdge (\2, 1, poly );
float x1 = poly.vertices [i1].x;
float x2 = poly.vertices [i2].x;

⇐ Предыдущая| |Следующая ⇒