xTile --;
xStep =-1;
yStep = -tan ( angle );
xlntercept = xTile + 1;
dxTile =-1;
}
ylntercept = locY + ( xlntercept - locX ) * tan ( angle );
for(;;) {
yTile = ylntercept;
if ( xTile < 0 || xTile > 52 || yTile < 0 || yTile > 9 ) return 10000.0;
if ( worldMap [yTile][xTile] != " ) {
cell = xTile;
return ( xlntercept - locX ) / cos ( angle );
}
xlntercept += xStep; . ylntercept += yStep; xTile += dxTile;
}
}
float checkHWalls (float angle, int& cell) {
int xTile = (int) locX; int yTile = (int) locY; float xlntercept; float ylntercept; float xStep; float yStep; int dyTile;
if (fabs ( sin ( angle )) < 1e-7 ) return 10000.0;
if (angle <= ANGLE J 80)
{
yTile ++;
xStep = 1 / tan ( angle ); yStep = 1; ylntercept = yTile; dyTile =1;
}
else
{
yTile -;
yStep =-1; xStep = -1 / tan ( angle ); ylntercept = yTile + 1; dyTile =-1;
}

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

xlntercept = locX + ( ylntercept - locY ) / tan ( angle );
for (;;) {
xTile - xlntercept',
if ( xTile < 0 || xTile > 52 || yTile < 0 || yTile > 9 ) return 10000.0;
if ( worldMap [yTile][xTile] != " ) {
cell = 1000 + yTile;
return ( ylntercept - locY ) / sin ( angle );
}
xlntercept += xStep; ylntercept += yStep; yTile += dyTile;
}
} '
void drawView () {
float phi; float distance;
totalFrames++; lastCell = -1;
for (int col = 0; col < 320; col++ ) {
phi = angle + rayAngle [col]; if ( phi < 0 )
phi += 2 * M__PI;
else
if ( phi >= 2 * M_PI ) phi -=2*M_PI;
int c1,c2;
float d1 = checkVWalls ( phi, d ); float d2 = checkHWalls ( phi, c2 );
distance = d1;
if ( d2 < distance ) {
distance = d2; d = c2;
}
distance *= cos ( phi - angle ); // adjustment for fish-eye drawSpan ( distance, WALL_COLOR, col, d );
}
}
void setVideoMode (int mode ) {
asm {

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

mov ax, mode int 10h
}
}
void initTables () {
for (int i = 0; i < SCREEN_WIDTH; i++ )
rayAngle [i] = atan (-swing + 2 * i * swing / ( SCREEN_WIDTH -1 ));
I
main () {
int done = 0;

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