{
firstAvailable -> next = NULL; firstAvailable -> prev = NULL;
if ( s != NULL )
* firstAvailable = * s;
return firstAvailable++;
}
else
return NULL;
Span * res = free;
free = free -> next;
res -> next = NULL; res -> prev = NULL;
if (s!=NULL) * res = * s;
return res;
}
// deallocate span // (return to free span list)
void freeSpan ( Span * span )
{
span -> next = free; free = span;
}
};
extern SpanPool * pool;
class SBuffer {
public:
Span ** head;
int . screenHeight;

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

SBuffer (int height)
head = new Span * [screenHeight = height]; reset ();
-SBuffer ()
delete [] head;
void reset () pool -> freeAII ();
for (register int i = 0; i < screenHeight; i++ )
head [i] = pool -> allocSpan ();
head [i] -> prev = NULL; head [i] -> next = NULL;
}
}
void addSpan (int line, Span * span ); void addPoly ( const Polygon3D& poly );
int compareSpans ( const Span * s1, const Span * s2 ); #endif
2) //File sbuffer.cpp
//
// SBuffer management routines
//
#include <mem.h> #include "SBuffer.h"
SpanPool * pool = NULL;
'//
// compare spans s1 and s2, s1 being the inserted span // return positive if s2 cannot obscure s1 (s1 is nearer) //
int compareSpans ( const Span * s1, const Span * s2 ) {
// try to check max/min depths float s1 MinlnvZ, sIMaxInvZ; float s2MinlnvZ, s2MaxlnvZ;
// compute min/max for 1/z for s1 if ( s1 -> invZ1 < s1 -> invZ2 )
{
s1 MinlnvZ = s1 -> invZ1; sIMaxInvZ = s1 -> invZ2;
}
else
10. YflarieHne HeBMflMMbix hmhmm h noBepxHOCTe
{
sIMinlnvZ = s1 -> invZ2; s1 MaxInvZ = s1 -> invZ1;
}
// compute min/max for 1/z for s2 if ( s2 -> invZ1 < s2 -> invZ2 )
{
s2MinlnvZ = s2 -> invZ1; s2MaxlnvZ = s2 -> invZ2;
}
else
{
s2MinlnvZ = s2 -> invZ2; s2MaxlnvZ = s2 -> invZ1;
}
// compare inverse depths if ( s1 MinlnvZ >= s2MaxlnvZ ) return 1;
if ( s2MinlnvZ >= sIMaxInvZ ) return -1;
// if everything fails then try // direct approach
float f 1 = s1 -> f ( s2 -> x1, s2 -> invZ1 ); float f2 = s1 -> f ( s2 -> x2, s2 -> invZ2 ); int res = 0;

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