float x, y; // viewer loc
float angle;
int mod (float x, int y ) {
int res = (int) fmod ( x, y );
if (res < 0 ) res += y;
return res;
}
void drawView () {
char far * videoPtr = screenPtr + 100*320; totalFrames++;
Jmemset ( screenPtr, SKY_COLOR, 100*320 ); // draw the sky
for (int row = 0; row < 100; row++ ) {
float dist = H * DO / ((1 + row ) * DELTA );
int iO = mod ( x + dist * cos ( angle ), pic -> width );
int jO = mod ( y + dist * sin ( angle ), pic -> height);
float di = C * dist * sin ( angle );
float dj = -C * dist * cos ( angle );
float ii = iO;
float jj =j0;
int i, j;
videoPtr += 160;
for (int col = 159; col >= 0; col- ) {
i = mod (ii, pic -> width );
j = mod (jj, pic -> height);
* videoPtr- = pic -> data [ i + j * pic -> width ];
ii -= di; ii -= dj;
}
videoPtr += 160; ii = iO + di; jj = JO + dj;
for ( col = 160; col < 320; col++ ) {
i = mod (ii, pic -> width );
j = mod (jj, pic -> height);
* videoPtr++ = pic -> data [ i + j * pic -> width ];
ii += di;

Компьютерная графика. Полигональные модели

jj += dj;
}
}
}
void setVideoMode (int mode ) {
asm {
mov ax, mode int 10h
}
}
void setPalette ( RGB * palette ) {
for (int i = 0; i < 256; i++ ) II convert from 8-bit to { // 6-bit values
palette [i].red »= 2;
palette [ij.green »= 2;
palette [ij.blue »= 2;
}
asm { // really load palette via BIOS
push es mov ax, 1012h
mov bx, 0 // first color to set
mov cx, 256 // # of colors
les dx, palette // ES:DX == table of color values
int 10h
pop es
}
}
main () {
int done = 0;
int start = clock ();
angle =0; x = 29;
y =0;
setVideoMode (0x13 ); setPalette ( pic -> palette );
while (Idone ) {
drawView ();
if ( bioskey (1 )) {
float vx = cos ( angle )* 10; float vy = sin ( angle )* 10;
switch ( bioskey ( 0 )) {
case LEFT:

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

angle += 10 * M_PI /180; break;
case RIGHT:
angle -= 10* M_PI /180;
break;

case UP: x += vx; У ♦= vy;


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