#define UP 0x4800 #define DOWN 0x5000
#define LEFT 0x4b00 #define RIGHT 0x4d00
// labyrinth
char * worldMap [] = {
!**★*** ***************************** ****** ************
I
«* * *ll
I
II* ********* ************************** *ll
I
I* * *lf
)
It* ********* * ************************ *ll
I
I* * *ll
I
It* ********* ************************** *n
I
I* * *lt
I
II** ************************************************ **lt
};
float swing;
float locX;
float locY;
float angle;
long totalFrames = 01;
char far * screenPtr = (char far *) MK_FP ( OxAOOO, 0 );
float rayAngle [SCREEN_WIDTH]; // angles for rays from main
// viewing direction
int lastCell = -1;
int lastJI = 0;
int lastJ2 = 0;
////////////////////^
void drawSpan (float dist, char wallColor, int x, int cell)
{
char far * vptr = screenPtr + x;
13. Элементы виртуальной реальност
int h = dist >= 0.5 ? (int)(SCREEN_HEIGHT*0.5 / dist): SCREEN_HEIGHT; int j1 =(SCREEN_HEIGHT-h)/2; int j2 = j1 + h;
if ( x > 0 && cell != lastCell)// check for wall boundary
{
if (lastJI > j1 ) lastJ1=j1;
if (lastJ2 < j2 ) lasU2 = j2;
for (int j = 0; j < lastJI; j++, vptr += 320 )
* vptr = CEIUIMG^COLOR;
for (; j < lastJ2; j++, vptr += 320 )
* vptr = waltColor;
for ( ; j < SCREEN_HEIGHT; vptr += 320 )
* vptr = CEILING_COLOR;
}
else
{
for (int j = 0; j < SCREEN_HEIGHT; vptr += 320 )
* vptr = CEILING_COLOR;
* ( screenPtr + x + 320*j1 ) = waltColor;
* ( screenPtr + x + 320*j2 ) = wallColor;
}
lastCell = cell; lastJI =j1; lastJ2 =j2;
}
float checkVWalls (float angle, int& cell) {
int xTile = (int) locX; int yTile = (int) locY; float xlntercept; float ylntercept; float xStep; 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
{
Компьютерная графика. Полигональные модели