// Vytvoril (C)Cyril Höschl // Copyright 1997, Vsechna prava vyhrazena // Zadna cast tohoto zdrojoveho kodu nesmi byt zkopirovana, modifikovana // nebo kdekoliv publikovana bez pisemneho svoleni Autora! // // Tento zdrojovy kod slouzi ciste a jen k ucelu prohlizeni algoritmu zde pouzitych, // ktere vytvoril Cyril Hoschl a ktere nesmi byt nikde pouzity bez jeho pisemneho svoleni! #include #include #include #include #include #include #define PI 3.14159265358979 #define POZOROVATEL 20 #define ROZHLED 150 #define DOHLED 50 #define POLEX 128 #define POLEY 128 #define NAKLON 0.01 int nacti_paletu(char *soubor) { FILE *stream; char paleta[768]; stream = fopen(soubor, "rb"); fread(paleta, 768, 1, stream); fclose(stream); unsigned int seg, off; struct REGPACK reg; reg.r_ax = 0x1012; reg.r_bx = 0; reg.r_cx = 256; reg.r_es = FP_SEG(paleta); reg.r_dx = FP_OFF(paleta); intr(0x10, ®); return 0; } void put(char *co, char *kam, int x, int y) { asm { push ds lds si,co les di,kam mov dx,y mov bx,x } znovu: asm { mov cx,bx rep movsb add di,320 sub di,bx dec dx jnz znovu pop ds } } int ConvPal(int brv) { int barva; if (brv > 63) barva = 63; else if (brv < 0) barva = 0; else barva = brv; return barva; } int Norm(int uhel) { if (uhel > 359) return(uhel-360); if (uhel < 0) return(uhel+360); return(uhel); } void OtocOsy(float *x, float *y, int uhel) { *x += sin(uhel / 180.0 * PI); *y += cos(uhel / 180.0 * PI); } int main(void) { FILE *stream; int x, y, u=135, v=0;//, Plus = 0, Vyska = 0; unsigned char *pole; char *kam; char *TabulkaX, *TabulkaY; // int i, uhel, delka; int i, uhel, delka, Zbuffer = 0, vyska = 0, barva; float StredX = 50, StredY = 90, o = 1; // char MazaciPole[64*ROZHLED]; pole = (char*) malloc(POLEX*POLEY); stream = fopen("voxel.grf", "rb"); fread(pole, POLEX*POLEY, 1, stream); fclose(stream); asm { mov ax, 0x13 int 0x10 } //Zde je nutne pred init pal. nanest na port 0x3c8 hodnotu 0, aby //se skala barev nacetla na 0-64 a ne treba na 0-55 outp(0x3c8, 0); //Modra for (i = 0; i < 64; i++) { outp(0x3c9, 0); outp(0x3c9, 0); outp(0x3c9, i/4); } //Zelena for (i = 0; i < 64; i++) { outp(0x3c9, 0); outp(0x3c9, i/4); outp(0x3c9, 16-i/4); } //Bila for (i = 0; i < 64; i++) { outp(0x3c9, i); outp(0x3c9, 16+i/1.333); outp(0x3c9, i); } // for (i = 0; i < 64*ROZHLED; i++) MazaciPole[i] = 0; // nacti_paletu("voxel.pal"); kam = (char*) MK_FP(0xA000, 0); put(pole, kam, POLEX, POLEY); TabulkaX = (char*) malloc(360*DOHLED); TabulkaY = (char*) malloc(360*DOHLED); kam = (char*) MK_FP(0xA000, 0); for (delka = POZOROVATEL; delka < POZOROVATEL+DOHLED; delka++) for (uhel = 0; uhel < 360; uhel++) { x = sin(uhel / 180.0 * PI) * delka; y = cos(uhel / 180.0 * PI) * delka; TabulkaX[uhel + (delka-POZOROVATEL) * 360] = x; TabulkaY[uhel + (delka-POZOROVATEL) * 360] = y; } do { switch(getch()) { case 'w': StredX += sin((u+ROZHLED/2) / 180.0 * PI); StredY += cos((u+ROZHLED/2) / 180.0 * PI); break; case 's': StredX -= sin((u+ROZHLED/2) / 180.0 * PI); StredY -= cos((u+ROZHLED/2) / 180.0 * PI); break; case 'z': StredX -= sin((u-90+ROZHLED/2) / 180.0 * PI); StredY -= cos((u-90+ROZHLED/2) / 180.0 * PI); break; case 'x': StredX += sin((u-90+ROZHLED/2) / 180.0 * PI); StredY += cos((u-90+ROZHLED/2) / 180.0 * PI); break; case 'a': u++; break; case 'd': u--; break; case 'r': o+=NAKLON; break; case 'f': o-=NAKLON; break; // case 't': v++; break; // case 'g': v--; break; case 27: return 0; } kam = (char *) MK_FP(0xA000, 0); put(pole, kam, POLEX, POLEY); if (u < 0) u = 359; if (u > 359) u = 0; if (StredX < 0) StredX = POLEX - 1; if (StredX >= POLEX) StredX = 0; if (StredY < 0) StredY = POLEY - 1; if (StredY >= POLEY) StredY = 0; for (uhel = u; uhel < u+ROZHLED; uhel ++) { v = pole[(TabulkaX[Norm(uhel)]+(int)StredX) + (TabulkaY[Norm(uhel)]+(int)StredY) * POLEY]; Zbuffer = 0; for (delka = 0; delka < DOHLED; delka++) { x = TabulkaX[Norm(uhel) + delka * 360]; y = TabulkaY[Norm(uhel) + delka * 360]; if (x > POLEX-StredX-1) x -= POLEX; if (x < 0-StredX) x += POLEX; if (y > POLEY-StredY-1) y -= POLEY; if (y < 0-StredY) y += POLEY; barva = pole[(x+(int)StredX) + (y+(int)StredY) * POLEX]-v; if (uhel == u || uhel == u+ROZHLED-1 || delka == 49 || delka == 0) { kam = (char*) MK_FP(0xA000, ((x+(int)StredX) + (y+(int)StredY) * 320)); *kam = 255; } vyska = (POZOROVATEL*barva)/((delka+POZOROVATEL)*o); if (vyska > Zbuffer) { for (i = 200 - vyska; i < 200-Zbuffer; i++) { kam = (char *) MK_FP(0xA000, (300-uhel+u) + i*320); *kam = barva+v; } Zbuffer = vyska; } } for (i = 50; i < 200-Zbuffer; i++) { kam = (char *) MK_FP(0xA000, (300-uhel+u) + i*320); *kam = 50-i/4; } // getch(); } } while (3==3); getch(); free(pole); free(TabulkaX); free(TabulkaY); return 0; }