float swing;
Fixed locX;
Fixed locY;
Angle angle;
13. Элементы виртуальной реальност
Fixed xlntV; // interception point for
Fixed , ylntV; // vertical walls
Fixed xlntH; // interception point for
Fixed ylntH; // horizontal walls
long totalFrames = 01;
char far * screenPtr = (char far *) MK_FP ( OxAOOO, 0 ); BMPImage* pic = new BMPImage ("WALL.BMP");
Angle rayAngle [SCREEN JA/IDTH]; // angles for rays from main
//viewing direction
////////////////////////// Functions ////////////////////////////////////
void drawSpan (Fixed dist, int textOffs, int x ) {
char far * vptr = screenPtr + x; int h = dist >= (ONE / 2) ?
fixed2lnt ((int2Fixed (SGREEN_HElGHT/2) « 8) / (dist » 8)):
SCREENJHEIGHT; int j1 = ( SCREENJHEIGHT - h ) / 2;
int j2 = j1 + h;
char * img = pic -> data + textOffs; Fixed y - 01;
Fixed dy = (2 * 128 * dist) / SCREENJHEIGHT;
// draw ceiling for (register int j = 0; j < j1; vptr += 320 )
* vptr = CElLING_COLOR;
if (j2 > SCREENJHEIGHT )
j2 = SCREENJHEIGHT;
// skip invisible part of wall for(j = j1;j<0; j++,y+=dy)
*
// draw wall
// Note: a«7==a* 128 // where pic -> width ==128 for (; j < j2; vptr += 320, y += dy )
* vptr = img [fixed2lnt(y)«7];
// draw floor for (; j < SCREENJHEIGHT; vptr += 320 )
* vptr = FLOOR_COLOR;
}
Fixed checkVWalls (Angle angle ) {
int xTile = fixed2lnt (locX ); // cell indices int yTile = fixed2lnt (JocY ); Fixed xlntercept; // intercept point
Fixed ylntercept;
Fixed xStep; // intercept steps
Fixed yStep; int dxTile;
if ( fixAbs ( coTang ( angle )) < 2 ) return MAX_FIXED;
Компьютерная графика. Полигональные модели
if ( angle >= ANGLE_270 || angle <= ANGLE_90 ) {
xTile ++;
xStep = ONE; yStep = tang (angle); xlntercept = int2Fixed (xTile); dxTile =1;
}
else
{
xTile --;
xStep = -ONE; yStep = -tang (angle); xlntercept = int2Fixed (xTile + 1); dxTile =-1;