TGC Codebase Backup



Sync Camera [camera number] (individual camera sync) by games coder

3rd Apr 2005 17:39
Summary

This function will let you simulate individal camera syncing in one simple function.



Description

This function will let you simulate individal camera syncing in one simple function. This is
accomplished by setting the range to a small number, as well as a small FOV. Thus, almost no rendering occurs. Great to sync cubemaps (one at a time).



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    rem setup the graphics and random number engine
sync on : sync rate 0 : cls 0 : sync : hide mouse : randomize timer()

rem create the camera type and the cameras array
type camera
 exists as boolean
 x1 as integer : y1 as integer
 x2 as integer : y2 as integer
endtype
dim cameras(999) as camera

rem create the screen buffer bitmap (VERY IMPORTANT)
create bitmap 1, screen width(), screen height()

rem set the default camera viewpoint:
rem the setCameraView function lets the functions know where the camera data should go
setCameraView(0, 0,0, screen width()/2,screen height())

rem create a second camera using make camera and the setCameraView function
rem whenever a camera is created, ALWAYS call setCameraView or the camera
rem is still rendered default (not good)
make camera 1
setCameraView(1, screen width()/2,0, screen width(),screen height())

rem create some spheres to look at
for i=1 to 200
 make object sphere i,rnd(5)+10
 color object i,rgb(rnd(255),rnd(255),rnd(255))
 position object i,rnd(25)-50,rnd(25)-50,rnd(25)-50
 point object i,rnd(25)-50,rnd(25)-50,rnd(25)-50 : move object i,15
next i

do
 rem print the FPS
 text 2,2,"FPS: "+str$(screen fps())

 rem simple mouse look for camera 0
 inc cax,mousemovey() : inc cay,mousemovex() : rotate camera 0,cax,cay,0
 if mouseclick()=1 then move camera 0,1 else if mouseclick()=2 then move camera 0,-1

 rem move the spheres for effect
 for i=1 to 200
  move object i,0.05
 next i

 rem the most important function is the syncCamera function
 rem this function syncs the screen for only a certain camera
 rem Make sure you DO NOT USE DBPRO SYNC AFTER THIS!!!
 syncCamera(0)

 rem as a test, we only sync the 2nd camera when shift is pushed
 if shiftkey() then syncCamera(1)
loop

rem the syncCamera function
function syncCamera(cam as integer)
 for c=0 to 999
  rem check if the camera exists(when setCameraView called) first
  if cameras(c).exists=1
   rem if this isnt the camera we want to sync
   if c<>cam
    rem set the range and fov so almost no rendering occurs
    set camera range c,2,1 : set camera fov c,0.001
   else
    rem set the range and fov to normal again
    set camera range c,1,3000 : set camera fov c,90
   endif
  endif
 next c
 rem set the current bitmap to 1 so we can send all sync's there
 set current bitmap 1
 rem the sync
 sync
 rem restore the current bitmap
 set current bitmap 0
 rem copy data for this camera from the buffer (where the rendering is) back to the screen
 copy bitmap 1, cameras(cam).x1,cameras(cam).y1,cameras(cam).x2,cameras(cam).y2, 0, cameras(cam).x1,cameras(cam).y1,cameras(cam).x2,cameras(cam).y2
endfunction

rem the setCameraView function
function setCameraView(cam, x1,y1, x2,y2)
 rem if this is called, the camera must exist
 cameras(cam).exists=1
 rem actually set the view
 set camera view cam,x1,y1,x2,y2
 rem record the setting
 cameras(cam).x1 = x1 : cameras(cam).y1 = y1
 cameras(cam).x2 = x2 : cameras(cam).y2 = y2
endfunction