Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program BumpMapper;
- Uses Crt,Dos,TJVga; { This file won't compile without TJVga, haha }
- Type ronne=Array[0..255,0..254]of byte; { The environmentmap array }
- rptr=^ronne; { Same, but pointer }
- Var environmentmap:rptr;
- i,j:integer;
- mx,my:integer; { Light position }
- xdir,ydir:integer;
- VirScr2:VirtPtr; { The second virtual screen, used for the bumpmap }
- Vaddr2:word;
- Procedure CreateEnvironmentMap; { Guess??? }
- Var I,J:Integer;
- nx,ny,nz:real;
- begin
- getmem(environmentmap,sizeof(environmentmap^)); { Biggos pointeros }
- for i := 0 to 255 do { Very slooooow }
- for j := 0 to 254 do begin
- nX:=(i-128)/128;
- nY:=(j-128)/128;
- nZ:=1-sqrt(nX*nX+nY*nY);
- if nz<0 then nZ:=0;
- environmentmap^[i,j]:=Round(nZ*128);
- end;
- end;
- Procedure Bumpmap(lightx,lighty:integer);
- var xtemp,ytemp,temp,i,j:integer;
- nx,ny:integer;
- begin
- for i := 0 to 319 do
- for j := 1 to 198 do begin {Skip the first and last line, cause they look bad}
- nx:=getpixel(i-1,j,vaddr2)-getpixel(i+1,j,vaddr2);
- ny:=getpixel(i,j-1,vaddr2)-getpixel(i,j+1,vaddr2);
- asm
- mov ax,i
- sub ax,lightx { xtemp:=i-lightx;}
- mov xtemp,ax
- mov ax,j
- sub ax,lighty { ytemp:=j-lighty;}
- mov ytemp,ax
- mov ax,nx
- sub ax,xtemp { dec(nx,xtemp);}
- mov nx,ax
- mov ax,ny
- sub ax,ytemp { dec(ny,ytemp);}
- mov ny,ax
- mov ax,nx
- add ax,128 { inc(nx,128); }
- mov nx,ax
- mov ax,ny
- add ax,128 { inc(ny,128;}
- mov ny,ax
- end;
- if (nx<0) or (nx>255) then nx:=0; { Check ranges }
- if (ny<0) or (ny>255) then ny:=0;
- putpixel(i,j,environmentmap^[nx,ny],vaddr); { Put the pixel }
- end;
- end;
- begin
- Writeln('[Creating Environment map]');
- CreateEnvironmentMap; { Bla,bla}
- Writeln('Done.');
- SetMCGA; { Init the graphics mode }
- mx:=160; { Start position of the light }
- my:=100;
- SetupVirtual; { Init virtual screens}
- getmem(virscr2,sizeof(virscr2^));
- vaddr2:=seg(virscr2^);
- cls(vaddr,0);
- LoadPCX('bumpmap.pcx',0,0,Vaddr2); { Load the PCX-file to use as bumpmap }
- for i := 0 to 63 do { Set the fire palette }
- pal(i,i,0,0);
- for i := 64 to 127 do
- pal(i,63,i-64,0);
- for i := 128 to 255 do
- pal(i,63,63,i div 4);
- xdir:=4;
- ydir:=-4;
- repeat
- BumpMap(mx,my);
- flip(vaddr,vga);
- inc(mx,xdir);
- inc(my,ydir);
- if mx<0 then xdir:=-xdir;
- if mx>319 then xdir:=-xdir;
- if my<0 then ydir:=-ydir;
- if my>199 then ydir:=-ydir;
- until keypressed;
- freemem(environmentmap,sizeof(environmentmap^));
- freemem(virscr2,sizeof(virscr2^));
- ShutDown; { Deallocate virtual screen }
- SetText; { Set text mode }
- Writeln('TJ -1998');
- end.
Add Comment
Please, Sign In to add comment