* vptr = FLOOR_COLOR;
}
float checkVWalls (float angle ) {
int xTile = (int) locX; // cell indices int yTile = (int) k>cY;
float xlntercept; // intercept point
float ylntercept;
float xStep; // intercept steps
float yStep; int dxTile;
if (fabs ( cos ( angle )) < 1e-7 ) return 10000.0;
if ( angle >= ANGLE_270 || angle <= ANGLE_90 ) {
xTile ++;
xStep = 1;
yStep = tan (angle);
xlntercept -xTile;
dxTile = 1;
}
else
{
xTile --;
xStep = -1; yStep = -tan ( angle ); xlntercept = xTile + 1; dxTile =-1;
}
// find interception point 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] != '')
return ( xlntercept - locX ) / cos ( angle );
xlntercept += xStep; ylntercept += yStep; xTile += dxTile;

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

}
}
float checkHWalls (float angle ) {
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;
}
xlntercept = locX + (ylntercept - locY) / tan ( angle );
for(;;) {
xTile = xlntercept
if ( xTile < 0 || xTile > 52 || yTile < 0 || yTile > 9 ) return 10000.0;
if ( worldMap [yTile][xTiie] != '')
return ( ylntercept - locY) / sin ( angle );
xlntercept += xStep; ylntercept += yStep; yTile += dyTile;
}
}
void drawView () {
float phi; float distance;
totalFrames++;
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;
float d1 = checkVWalls ( phi); float d2 = checkHWalls ( phi);
' distance = d1;
if ( d2 < distance ) distance = d2;

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