REM Project: outerblur REM Created: 9/7/2005 10:09:58 PM REM REM ***** Main Source File ***** REM Make_blend_gradient() autocam off color backdrop 0 hide light 0 make light 1 position light 1,50,50,100 set light range 1,100 hide mouse set camera range 0.1,10000 randomize timer() sync on create bitmap 1,screen width(),screen height() set camera range 0.01,2000 terraform() make object plain 100,screen width(),screen height() texture object 100,2000 position object 100,0,0,screen height() yrotate object 100,180 lock object on 100 do move_camera(0.02,2) move_water() text 0,0,"FPS: "+str$(screen fps()) my_sync() loop function make_Blend_gradient() backdrop off create bitmap 2000,screen width(),screen height() set current bitmap 2000 lock pixels for i=0 to screen width()-1 for j=0 to screen height()-1 Distance#=sqrt(((screen width()/2.0-i)^2+(screen height()/2.0-j)^2))/(screen width()/2.0) intensity#=255-255*cos(distance#*90) if distance#>=1 then intensity#=255 set_locked_pixel(i,j,rgb(intensity#,intensity#,intensity#)) next j next i unlock pixels get image 2000,0,0,screen width()-1, screen height()-1,0 set current bitmap 0 backdrop on endfunction function my_sync() `copy bitmap 2000,0 sync endfunction function save_bitmap_for_editing(number) if memblock exist(100+number) then delete memblock 100+number make memblock from bitmap 100+number,number endfunction function get_memblock_pixel(memblock,x,y) width=memblock dword(memblock,0) height=memblock dword(memblock,4) depth=memblock dword(memblock,8) if x>0 and y>0 and x<width and y<height pointer=y*width*depth/8+x*depth/8+12 value=memblock dword(memblock,pointer) endif endfunction value function get_locked_pixel(x,y) start=get pixels pointer() repeat_number=get pixels pitch() bits_per_pixel=bitmap depth(num)/8 pointer=start+y*repeat_number+x*bits_per_pixel result=*pointer endfunction result function set_locked_pixel(x,y,color_value) start=get pixels pointer() repeat_number=get pixels pitch() bits_per_pixel=bitmap depth(num)/8 pointer=start+y*repeat_number+x*bits_per_pixel *pointer=color_value endfunction function terraform sync text 0,0,"Generating terrain ....." sync create bitmap 1,screen width(),screen height() set current bitmap 1 global matrixsize matrixsize=100 fog on fog color rgb(180,180,250) fog distance matrixsize*0.6 global object_seed object_seed=1000000 global image_seed image_seed=1000000 global grassimage create_grass() global skyimage create_sky() global waterimage global water global water2 create_water_image() create_water() `set size of terrain rows=60 columns=60 `create terrain make matrix 1,matrixsize,matrixsize,columns,rows `set mountain peaks number_of_peaks=rnd(35)+10 max_height=15 dim peakx(number_of_peaks) dim peakz(number_of_peaks) dim height(number_of_peaks) for peak=1 to number_of_peaks `set x,z coordinates for peak peakx(peak)=rnd(columns-10)+5 peakz(peak)=rnd(rows-10)+5 `set height of peak height(peak)=rnd(max_height)+10 `create peak set matrix height 1,peakx(peak),peakz(peak),height(peak) next peak num=rows*columns dim obnum(rows+1,columns+1) dim v#(rows,columns) `give each tile an x,z coordinate for use later for x=1 to rows for z=1 to columns obnum(x,z)=ob ob=ob+1 next z next x `texture matrix prepare matrix texture 1,grassimage,rows,columns tile=1 for x=rows-1 to 0 step -1 for z=0 to columns-1 set matrix tile 1,z,x,tile inc tile next z next x `adjust height of points between peaks elasticity#=0.3 damping#=0 for time=1 to 100 for peak=1 to number_of_peaks set matrix height 1,peakx(peak),peakz(peak),height(peak) next peak for x=1+1 to rows-1 for z=1+1 to columns-1 if x<rows distxp1#=get matrix height(1,x+1,z)-get matrix height (1,x,z) endif if x>1 distxm1#=get matrix height(1,x-1,z)-get matrix height (1,x,z) endif if z<columns distzp1#=get matrix height(1,x,z+1)-get matrix height (1,x,z) endif if z>1 distzm1#=get matrix height(1,x,z-1)-get matrix height (1,x,z) endif vectorsum#=distxp1#+distxm1#+distzp1#+distzm1# a#=vectorsum#*elasticity# v#(obnum(x,z))=v#(obnum(x,z))+a# set matrix height 1,x,z,get matrix height(1,x,z)+v#(obnum(x,z)) v#(obnum(x,z))=v#(obnum(x,z))*damping# next z next x update matrix 1 next time create_skysphere() position camera 65,get ground height(1,65,65)+2,65 point camera 75,get ground height(1,75,75),75 set current bitmap 0 ink rgb(255,255,255),0 endfunction function check_free_object_number `this handy function means that you never have to worry about `remembering object numbers. You just give them names you can remember, `and this function will find the next available number to assosciate `with that name. Just call the function by, for example, writing: ` `ball=check_free_object_number `make object sphere ball,1 object=object_seed repeat inc object until object exist(object)=0 endfunction object function check_free_image_number() `this functionworks in the same way as the check_free_object function, `except it works for images. image=image_seed repeat inc image until image exist(image)=0 endfunction image function create_grass `make a shaded box box 0,0,100,100,rgb(100,150,100),rgb(50,200,20),rgb(80,0,10),rgb(150,200,0) `and speckle it with random dots for x=0 to 100 for y=0 to 100 if rnd(5)=0 r=rnd(150) g=rnd(250) b=rnd(100) ink rgb(r,g,b),0 dot x,y endif next x next y grassimage=check_free_image_number() get image grassimage,0,0,100,100 endfunction function create_skysphere `get image for sphere by taking snapshot of terrain image=check_free_image_number() set camera fov 90 position camera matrixsize/2.0,3,-matrixsize*0.3 sync get image image,0,0,screen width(),screen height() set camera fov 60 `sphere 1 (mountains near) - just a sphere textured with the captured image object=check_free_object_number() make object sphere object,matrixsize*2 set object cull object,0 texture object object,image set object texture object,2,1 scale object texture object,3,1 set object fog object,0 set object light object,0 set object transparency object,4 position object object,matrixsize/2,0,matrixsize/2 `sphere 2 (mountains far) - and another one further out. The inner sphere must be `transparent, though, to see this one. object=check_free_object_number() make object sphere object,matrixsize*2.5 yrotate object object,30 set object cull object,0 texture object object,image set object texture object,2,1 scale object texture object,3,1 set object fog object,0 `set object light object,0 set object transparency object,4 ghost object on object,4 set object emissive object,rgb(180,150,250) fade object object,70 position object object,matrixsize/2,0,matrixsize/2 `sphere 3 (sky) - a third, outer sphere for the sky object=check_free_object_number() make object sphere object,matrixsize*4 set object cull object,0 texture object object,skyimage scale object texture object,1,1.8 set object light object,0 set object fog object,0 endfunction function create_sky() `creates a dark to light bluish gradient cls for n=0 to 250 ink rgb(n,n,250),0 line 0,n,250,n next n skyimage=check_free_image_number() get image skyimage,0,0,250,250 endfunction function create_water_image `creates a shaded box box 0,0,100,100,rgb(150,150,200),rgb(50,200,200),rgb(80,0,200),rgb(150,100,200) `and speckles with white bits for x=0 to 100 for y=0 to 100 if rnd(5)=0 r=(250) g=(250) b=(250) ink rgb(r,g,b),0 dot x,y endif next x next y waterimage=check_free_image_number() get image waterimage,0,0,100,100 endfunction function create_water `just a plane textured with the water image water=check_free_object_number() make object plain water,matrixsize*4,matrixsize*4 texture object water,waterimage set object texture water,2,1 scale object texture water,4,4 xrotate object water,90 set object fog water,0 set object emissive water,rgb(220,220,200) ghost object on water set alpha mapping on water,20 water2=check_free_object_number() make object plain water2,matrixsize*4,matrixsize*4 texture object water2,waterimage xrotate object water2,90 position object water2,0,1,0 set object texture water2,2,1 scale object texture water2,4,4 set object light water2,0 set object fog water2,0 endfunction function move_water `moves the texture along a bit scroll object texture water,0.001,0 scroll object texture water2,-0.001,0 `and moves the water up and down according to a sine wave position object water,0,0.5*sin(theta#)+3,0 inc theta#,1 endfunction function move_camera(movespeed#,turnspeed#) control camera using arrowkeys 0,movespeed#,turnspeed# position camera camera position x(),get ground height(1,camera position x(),camera position z())+0.2,camera position z() endfunction