}
// find interception point ylntercept = locY + ((xlntercept - locX) « 15) / (coTang (angle) » 1);
for(;;) {
yTile = fixed2lnt (ylntercept); if ( xTile < 0 || xTile > 52 || yTile < 0 || yTile > 9 ) return MAX_FIXED;
if ( worldMap [yTile][xTile] != '') {
ylntV = ylntercept; // store interception point for xlntV = xlntercept; // computing texture offset
return ((xlntercept - locX) » 8) * (invCosine ( angle ) » 8);
}
xlntercept += xStep; ylntercept += yStep; xTile += dxTile;
}
}
Fixed checkHWalis (Angle angle ) {
int xTile = fixed2lnt (locX );
int yTile = fixed2lnt (locY );
Fixed xlntercept;
Fixed ylntercept;
Fixed xStep;
Fixed yStep;
int dyTile;
if (fixAbs (tang ( angle )) < 2 ) return MAX_FIXED;
if ( angle <= ANGLEJ80 )
{
yTile ++;
xStep = coTang (angle);
13. Элементы виртуальной реальност
yStep = ONE; ylntercept = int2Fixed (yTile); dyTile =1;
}
else
{
yTile --;
yStep = -ONE; xStep = -coTang ( angle ); ylntercept = int2Fixed (yTile + 1); dyTile =-1;
}
xlntercept = locX + ((ylntercept - locY) «15)/ (tang (angle)» 1);
for(;;) {
xTile = fixed2lnt (xlntercept);
if ( xTile < 0 || xTile > 52 || yTile < 0 || yTile > 9 )
return MAX_FIXED; if (woridMap [yTile][xTile] != '')
{
xlntH = xlntercept; // store interception point ylntH = ylntercept; // for computing texture offset
return ((ylntercept - locY) » 8) * (invSine ( angle ) » 8);
}
xlntercept += xStep; ylntercept += yStep; yTile += dyTile;
}
}
void drawView () {
Angle phi; Fixed distance;
totalFrames++;
for (int col = 0; col < 320; coi++ ) {
phi = angle + rayAngle [col];
Fixed d1 = checkVWalls ( phi); Fixed d2 = checkHWalls ( phi); int texture Offset;
distance = d1;
if ( d2 < distance ) {
distance = d2;
textureOffset = fixed2lnt (frac ( xlntH ) « 7 );
if ( ylntH < locY )
textureOffset = 127 - textureOffset;
}
Компьютерная графика. Полигональные модели
else
{
textureOffset = fixed2lnt (frac ( ylntV ) « 7 );
if ( xlntV < locX )