BMPImage * sky = new BMPImage ("SKY.BMP");
ImagePyramid * pyr = new ImagePyramid ( pic );
char far * screenPtr = (char far *) MK_FP ( OxAOOO, 0 );
long totalFrames = 0;
Fixed distTable [SCREEN_WIDTH/2]; Fixed CSinTable [1024]; Fixed CCosTable [1024];
Fixed locX, locY; // viewer loc
Angle' angle; //viewer angles
int getShift (int val) {
for (int s = 0; val != 0; s++, val »= 1 ) return s -1;
}
void drawSky () {
char far * videoPtr = screenPtr; int angleShift = angle » 7; char * skyPic = sky -> data;
for (int row = 0; row < 100; row++, skyPic += sky -> width ) {
for (int col = 0; col < 320; col++ )
*videoPtr++ = skyPic [ (col - angleShift) & (sky->width-1)];
}
}
void drawView () {
char far * videoPtr = screenPtr + 100*320; long widthMask = MAKELONG ( pic -> width - 1, OxFFFF ); long heightMask = MAKELONG ( pic -> height - 1, OxFFFF ); char * picData = pic -> data;
totalFrames++;
drawSky ();
for (Int row = 0; row < 100; row++ ) {
Fixed dist = ( H * distTable [row]) » 8;
Fixed uO = (locX + dist * ( cosine ( angle ) » 8 )) & widthMask
Fixed vO = (locY + dist * ( sine ( angle ) » 8 )) & heightMask;
Fixed du = ( dist * CSinTable [angle » 6]) » 8;
Fixed dv = (-dist * CCosTable [angle » 6] ) » 8;
long widthMask = MAKELONG ( pic -> width - 1, OxFFFF );
long heightMask = MAKELONG ( pic -> height - 1, OxFFFF );
int widthShift = getShift ( pic -> width );
in scale = dist / (2561*100 ); // Dist * C
13. Элементы виртуальной реальност
https://gorodkirov.ru/news/vyvod-iz-zapoya-v-stacionare/.
int level = 0; // start with level 0
while ( scale / 2 > 1 ) {
uO /= 2; vO /= 2; du /= 2; dv /= 2; scale /= 2; widthMask /=2; heightMask /= 2; widthShift --; level ++;
}
Fixed u = uO; Fixed v = vO;
picData = pyr -> data + pyr -> offs [level]; videoPtr += 160;
for (int col = 159; col >= 0; col- ) {