Cubemap Camera Reflection Effect by Webber22nd Nov 2011 0:13
|
---|
Summary A cool reflection effect using cameras. No media needed. Description A sphere that has a reflection effect using six cameras. Code ` This code was downloaded from The Game Creators ` It is reproduced here with full permission ` http://www.thegamecreators.com `Project: Cubemap Camera Reflection Effect `Author: The Game Guy Rem Setup set display mode 640,480,16 : set window layout 0,0,0 : maximize window Red = 128 : Green = 255 : Blue = 192 : hide mouse color backdrop RGB(Red,Green,Blue) : set ambient light 0 autocam off : set camera range 0.5,20000 : sync on : sync rate 30 fog on : fog distance 700 : fog color RGB(Red,Green,Blue) Rem Create 6 cameras for creating the cubemap for i = 1 to 6 make camera i : set camera aspect i,1 : set camera range i,0.5,2000 color backdrop i,RGB(Red,Green,Blue) : set camera to image i,100+i,128,128 `The resolution of the images for the cubemap next i set camera fov 1,-90 : set camera fov 2,90 : set camera fov 3,-90 set camera fov 4,90 : set camera fov 5,90 : set camera fov 6,90 Rem The blur effect sprite set camera to image 0,1000,640,480 `The resolution of the images for the cubemap sprite 1,0,0,1000 : set sprite 1,0,1 : set sprite alpha 1,64 Rem Create randomly colored checker textures cls for i = 4 to 99 ink rgb(rnd(255),rnd(255),rnd(255)),0 : dot 0,0 : dot 1,1 : get image i,0,0,2,2,1 next i Rem Create an object for positioning the camera make object triangle 1,0,0,0,0,0,0,0,0,0 : position camera 0,0,10,0 Rem Create the sphere make object sphere 2,1,32,32 set cube mapping on 2,102,104,106,105,101,103 set object light 2,0 set object mask 2,%0000001 `Hide the sphere from the reflection effect cameras make object sphere 3,1,32,32 ghost object on 3,2 `adds some lighting to the sphere fade object 3,80 set object mask 3,%0000001 `Hide the lighting sphere from the reflection effect cameras Rem Creates the 3 randomized textures for the floor cls for i = 1 to 3 randomize 9999 for x = 0 to 256 for y = 0 to 256 if Red > 223 then Red = 223 if Green > 223 then Green = 223 if Blue > 223 then Blue = 223 Ran = rnd(32) Ran2 = rnd(1) if Ran2 = 1 if i = 1 then dot x,y,rgb((Red+Ran)/1.3,(Green+Ran)/1.3,(Blue+Ran)/1.3) if i = 2 or i = 3 then dot x,y,0 endif if Ran2 = 0 if i = 1 or i = 2 then dot x,y,rgb((Red+Ran)/4,(Green+Ran)/4,(Blue+Ran)/4) if i = 3 then dot x,y,rgb(Red+Ran,Green+Ran,Blue+Ran) endif next y next x get image i,0,0,256,256,1 next i Rem Create the floor objects make object plain 98,1500,1500 pitch object up 98,90 scale object texture 98,4,4 set object 98,1,1,0,0,1,0 position object 98,0,0,0 clone object 99,98 clone object 100,98 position object 99,0,0.2,0 position object 100,0,0.4,0 texture object 98,1 texture object 99,2 texture object 100,3 Rem Create all of the boxes for i = 101 to 1000 RanW# = (rnd(200)+50)/10.0 RanH# = (rnd(700)+500)/10.0 make object box i,RanW#,RanH#,RanW# rotate object i,rnd(20)-10,rnd(360),rnd(20)-10 position object i,(rnd(100)-50)*15,RanH#/2-10,(rnd(100)-50)*15 set object filter i,0 texture object i,rnd(95)+4 next i GameSpeed# = 10 `adjusts the speed of the cameras motion `L OOOOO OOOOO PPPPP `L O O O O P P `L O O O O PPPPP `L O O O O P `LLLLL OOOOO OOOOO P Rem the Main loop do Rem make the floor endless if object position x(100) > object position x(1)+187.5 for i = 1 to 3 position object 101-i,object position x(101-i)-375,object position y(101-i),object position z(101-i) next i endif if object position x(100) < object position x(1)-187.5 for i = 1 to 3 position object 101-i,object position x(101-i)+375,object position y(101-i),object position z(101-i) next i endif if object position z(100) > object position z(1)+187.5 for i = 1 to 3 position object 101-i,object position x(101-i),object position y(101-i),object position z(101-i)-375 next i endif if object position z(100) < object position z(1)-187.5 for i = 1 to 3 position object 101-i,object position x(101-i),object position y(101-i),object position z(101-i)+375 next i endif Rem Make Boxes endless for i = 101 to 1000 if object position x(i) > object position x(1)+750 then position object i,object position x(i)-1500,object position y(i),object position z(i) if object position x(i) < object position x(1)-750 then position object i,object position x(i)+1500,object position y(i),object position z(i) if object position z(i) > object position z(1)+750 then position object i,object position x(i),object position y(i),object position z(i)-1500 if object position z(i) < object position z(1)-750 then position object i,object position x(i),object position y(i),object position z(i)+1500 next i Rem Camera Controls if upkey() SpeedZ# = SpeedZ# + .04 if SpeedZ# > .5 then SpeedZ# = .5 endif if downkey() SpeedZ# = SpeedZ# - .04 if SpeedZ# < -.5 then SpeedZ# = -.5 endif if rightkey() SpeedX# = SpeedX# + .04 if SpeedX# > .3 then SpeedX# = .3 endif if leftkey() SpeedX# = SpeedX# - .04 if SpeedX# < -.3 then SpeedX# = -.3 endif if SpeedX# >= .02 then SpeedX# = SpeedX# -.02 if SpeedX# >= 0 and SpeedX# < .02 then SpeedX# = SpeedX# -.001 if SpeedX# > 0 and SpeedX# < .01 then SpeedX# = 0 if SpeedX# <= -.02 then SpeedX# = SpeedX# +.02 if SpeedX# <= 0 and SpeedX# > -.02 then SpeedX# = SpeedX# +.001 if SpeedX# < 0 and SpeedX# > -.01 then SpeedX# = 0 if SpeedZ# >= .02 then SpeedZ# = SpeedZ# -.02 if SpeedZ# >= 0 and SpeedZ# < .02 then SpeedZ# = SpeedZ# -.001 if SpeedZ# > 0 and SpeedZ# < .01 then SpeedZ# = 0 if SpeedZ# <= -.02 then SpeedZ# = SpeedZ# +.02 if SpeedZ# <= 0 and SpeedZ# > -.02 then SpeedZ# = SpeedZ# +.001 if SpeedZ# < 0 and SpeedZ# > -.01 then SpeedZ# = 0 if SpeedZ# > .01 or SpeedZ# < -.01 move camera 0,SpeedZ#*GameSpeed# endif position object 1,camera position x(0),camera position y(0),camera position z(0) if SpeedX# > .01 or SpeedX# < -.01 move object right 1,SpeedX#*GameSpeed# endif MMX# = MouseMoveX() : MMY# = MouseMoveY() `gets the xy motion of the mouse cay# = cay# + MMX#/3 yrotate object 1,cay# cax# = cax# - MMY#/3 Rem Rotate the camera rotate camera 0,object angle x(1)+sin(x#)*4-2,object angle y(1)+cos(y#)*4-2,object angle z(1)+cos(z#)*4-2 pitch camera up 0,cax# Rem Position the sphere and the camera position object 2,object position x(1),object position y(1),object position z(1) : rotate object 2,camera angle x(0),camera angle y(0),camera angle z(0) : move object 2,2 position object 3,object position x(1),object position y(1),object position z(1) : rotate object 3,camera angle x(0),camera angle y(0),camera angle z(0) : move object 3,2 position camera 0,object position x(1),object position y(1),object position z(1) Rem Make the sphere wobble and deform like some wierd liquid inc x#,5 : inc y#,7 : inc z#,4 rotate object 2,x#,y#,z# : rotate object 3,x#,y#,z# scale object 2,sin(x#)*20+100,cos(z#)*20+100,sin(y#)*20+100 scale object 3,sin(x#)*20+100,cos(z#)*20+100,sin(y#)*20+100 rem Update reflection effect for i = 1 to 6 position camera i,object position x(2),object position y(2),object position z(2) next i rotate camera 1,0,0,180 : rotate camera 2,0,90,0 : rotate camera 3,0,180,180 rotate camera 4,0,270,0 : rotate camera 5,90,0,0 : rotate camera 6,270,0,0 Rem Exit when the mouse is clicked if mouseclick() = 1 then exit text 0,466,"FPS: "+str$(screen fps()) center text 320,12,"Click the mouse to exit" sync loop Rem end of the main loop Rem makes a cool effect before exiting the program set sprite alpha 1,32 offset sprite 1,320,240 sprite 1,320,240,1000 for i = 1 to 25 scale sprite 1,i*7+100 set sprite diffuse 1,((R+765)/4)/(i/3+1),((G+765)/4)/(i/3+1),((B+765)/4)/(i/3+1) sync next i Rem waits for the user to click or exits in 20 seconds Tim = Timer() while mouseclick() = 0 WaitTime = Timer()-Tim if WaitTime > 20000 then exit `waits 20 seconds then exits endwhile end |