{
locX = things [i].x; locY = things [ij.y; locZ =0;
angle = (Angle) (( 0x40001 * things [ij.angle ) / 90 ); break;
}
setVideoMode (0x13 );
docket start = clock ();
while (Idone ) {
drawView (); if ( bioskey (1 ))
switch ( bioskey ( 0 ))
{
case UP:
locX += fixed2lnt ( 81 * cosine ( angle )); locY += fixed2lnt ( 81 * sine ( angle )); break;
case DOWN:
locX -= fixed2lnt ( 81 * cosine ( angle )); locY -= fixed2lnt ( 81 * sine ( angle )); break;
case LEFT:
angle+= 1024; break;
case RIGHT: angle-=1024; break;
case CtrlLeft:
locX += fixed2lnt ( 81 *
cosine (angle+ANGLE_90)); locY += fixed2lnt ( 81 *
sine (angle+ANGLE_90));
break;
case CtrlRight:
locX += fixed2lnt ( 81 *
cosine (angle-ANGLE_90) ); locY += fixed2lnt ( 81 *
sine (angle-ANGLE_90));
break;
case ESC: done = 1; break;
}
13. Элементы виртуальной реальное
}
float totalTime = ( clock () - start) / CLK_TCK; setVideoMode (0x03 );
printf ("\nFrames rendered : %7ld", totalFrames );
printf ("\nTotal time ( sec ) : %7.2f, totalTime );
printf ("\nFPS : %7.2fH, totalFrames / totalTime );
}
void drawView ()
{
curSector = NULL; // now unknown
for (int i = 0; i < SCREEN_WIDTH; i++ ) // reset horizon lines {
topLine [i] = 0;
bottomLine [i] = SCREENJHEIGHT -1;
}
drawNode ( numNodes -1 ); // start drawing with root
toiaflFrames++;
}
int viewerOnRight (int node ) {
Node * n = &nodes [node];
return n->dy * (long)( JocX - n->x ) >= n->dx * (long)( locY - n->y );
}
int frontFacing (int from, int to ) \
{
return (long)( vertices [from].x - vertices [to].x ) * (long)( locY - vertices [to].y ) >=
(long)( vertices [from].y - vertices [to].y ) * (long)( locX - vertices [to].x );
}
void drawNode ( unsigned node )
{
if ( node & 0x8000 ) // if it's a ssector => draw it drawSubSector ( node & 0x7FFF );
else
if ( viewerOnRight ( node ))// otherwise draw tree in { // front-to-back order
drawNode ( nodes [node].rightNode );
drawNode ( nodes [nodej.leftNode );
}
else
{
drawNode ( nodes [node].leftNode ); drawNode ( nodes [node].rightNode );