textureOffset = 127 - textureOffset;
}
// adjustment for fish-eye distance = (distance » 8) * (cosine ( phi - angle ) » 8);
drawSpan ( distance, textureOffset, col);
}
}
void setVideoMode (int mode ) {
asm {
mov ax, mode int 10h
}
}
void setPalette ( RGB * palette ) {
for (int i = 0; i < 256; i++ ) // convert from 8-bit to 6-bit values {
palette [ij.red »= 2; palette [ij.green »= 2; palette [ij.blue »= 2;
}
asm { // really load palette via BIOS
push es mov ax, 1012h
mov bx, 0 // first color to set
mov cx, 256 // # of colors
les dx, palette // ES:DX == table of color values
int 10h
pop es
}
}
void initTables () {
initFixMath ();
for (int i = 0; i < SCREEN_WIDTH; i++ )
rayAngle [i] = rad2Angle ( atan (-swing + 2 * i * swing /
(SCREEN_WfDTH - 1)));
}
main () {
int done = 0;
Fixed ct = float2Fixed ( 0.3 );
Angle da = 5 * (ANGLE_90 / 90); '

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

angle = 0;
locX = float2Fixed ( 1.5 );
locY = float2Fixed ( 1.5);
swing = tan ( VIEW_WIDTH / 2 );
initTables (); setVideoMode ( 0x13 ); setPalette ( pic -> palette );
int start = clock ();
while ('.done ) {
draw View ();
if (bioskey (1 )) {
Fixed vx = cosine ( angle ); Fixed vy = sine ( angle ); Fixed x, y;
switch ( bioskey ( 0 )) {
case LEFT: angle -= da; break;
case RIGHT: angle += da; break;
case UP:
x = locX + (ct » 8) * (vx » 8); y = locY + (ct » 8) * (vy » 8);
if ( worldMap [fixed2int (y)][fixed2lnt (x)] == 11) {
locX = x; locY = y;
}
break;
case DOWN:
x = locX - (ct » 8) * (vx » 8); y = locY - (ct» 8) * (vy » 8);
if (worldMap [fixed2lnt (y)][fixed2lnt (x)] == '') {
locX = x; locY = y;
}
break;
case ESC: done = 1;
}
}

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

}
float totalTime = ( clock () - start) / CLKJTCK; setVideoMode ( 0x03 );
printf ("\nFrames rendered : %ld", totalFrames );
printf ("\nTota! time ( sec ) : %7.2f", totalTime );
printf ("\nFPS : %7.2ftotalFrames / totalTime );

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