switch (_bios_keybrd (_KEYBRD__READ ))
{
case UP:
locX += fixed2lnt (8l*cosine(angle)); locY += fixed2lnt (8l*sine (angle)); break;
case DOWN:
locX -= fixed2lnt (8l*cosine (angle)); locY -= fixed2lnt (8l*sine (angle)); break;
case LEFT:
angle += 1024; break;
case RIGHT:
angle -= 1024; break;
case CtrlLeft:
locX += fixed2lnt ( 81 *

13. Элементы виртуальной реальност

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;
}
}
float totalTime = ( clock () - start) / CLK_TCK; setVideoMode (0x03 );
printf ("\nFrames rendered : %7ld", totalFrames );
printf ("\nTotal time ( sec ) : %7.2f, totalTime );
printf ("\nFPS : %7.2r, totalFrames / totalTime );
}
void drawView () {
curSector = NULL; // now unknown
colsLeft = SCREEN_WIDTH;
for (int i = 0; i < SCREEN_WIDTH; i++ ) // reset horizon lines {
colFilled [i] =0; topLine [i] = 0;
bottomLine [i] = SCREENJHEIGHT -1;
}
drawNode ( numNodes -1 ); // start drawing with root
totalFrames++;
}
// check whether the bounding box is in the viewing frustrum int boxInVCone ( BBox& box )
{
Angle leftAngle = angle + 0x2000;
if (leftAngle < ANGLE_90 ) {
if ( box.x2 > locX ) return 1;
}
else
if (leftAngle < ANGLE J 80) {
if ( box.y2 > locY ) return 1;

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

}
else
if (leflAngle < ANGLE_270 ) {
if ( box.xl < locX ) return 1;
}
else
if ( box.yl < locY ) return 1;
}
return 0;
}
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
{
if ( colsLeft > 0 && boxInVCone ( nodes [node].rightBox )) drawNode ( nodes [nodeJ.rightNode );
if ( colsLeft > 0 && boxInVCone ( nodes [nodeJJeftBox )) drawNode ( nodes [nodeJ.leftNode );
}
else
{
if ( colsLeft > 0 && boxInVCone ( nodes [node].leftBox )) drawNode ( nodes [node].leftNode );

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