With this you can create a camera track which the camera will follow, for automated camera sequences. The track can then be saved as a file, and loaded into your game using the autoloader.
It's not rocket science, but someone might find it handy.
The editor:
`*********************************************
`******** Track-Cam Editor by Ric **********
`*********************************************
`*** display settings ***
if check display mode(1024,768,32)=1 then set display mode 1024,768,32
sync on
sync rate 0
hide mouse
color backdrop rgb(80,80,250)
autocam off
position camera 0,10,0
set text font "arial"
set text size 20
ink 0,0
`camera speed
CamSpeed#=0.2
dim wpxang#(2000000)
dim wpyang#(2000000)
dim wpzang#(2000000)
make object cube 2000000,1
hide object 2000000
make matrix 1000000,100,100,10,10
`************MAIN PROGRAM LOOP***************
do
text 0,screen height()-60,"Track-Cam Editor by Ric"
text 0,screen height()-30,"Hold 'h' for help"
if inkey$()="h" then gosub help
`if r is pressed then start recording
if inkey$()="r" then record=1
if record=1 then gosub record
`if l is pressed load data from file
if inkey$()="l" and record=0 then gosub load
`if p is pressed start playing
if inkey$()="p"
playback=1
n=1000000
`position camera object position x(n),object position y(n),object position z(n)
endif
if playback=1 then gosub playback
if inkey$()="d" then gosub delete
`if not in playback mode then allow free camera control
if playback=0 then 3D_Move_Cam(CamSpeed#)
sync
loop
record:
`record a waypoint every 10 time units
if recordtime#/20=int(recordtime#/20)
`mark waypoint location by placing a cube
make object cube 1000000+wp,1
position object 1000000+wp,camera position x(),camera position y(),camera position z()
`record angle of camera at that waypoint
wpxang#(1000000+wp)=camera angle x()
wpyang#(1000000+wp)=camera angle y()
wpzang#(1000000+wp)=camera angle z()
`increase waypoint number by one
inc wp
endif
`increase recording time
inc recordtime#
if inkey$()="s"
`overwrite waypoint file with new data
record=0
delete file "camera.dat"
open to write 1,"camera.dat"
write file 1,wp
for n=1000000 to 1000000+wp-1
write float 1,object position x(n)
write float 1,object position y(n)
write float 1,object position z(n)
write float 1,wpxang#(n)
write float 1,wpyang#(n)
write float 1,wpzang#(n)
next n
close file 1
text 0,0,"Saving data"
sync
wait 1000
endif
if record=1 then text 0,0,"Recording "+str$(recordtime#)
return
load:
`load waypoint data back from file
open to read 1,"camera.dat"
read file 1,wp
for n=1000000 to 1000000+wp-1
read float 1,wpx#
read float 1,wpy#
read float 1,wpz#
read float 1,wpxang#(n)
read float 1,wpyang#(n)
read float 1,wpzang#(n)
if object exist(n) then delete object n
make object cube n,1
position object n,wpx#,wpy#,wpz#
next n
close file 1
text 0,0,"Loading data"
sync
wait 1000
return
playback:
if object exist(n)=0
text 0,0,"No data saved"
sync
wait 1000
playback=0
return
endif
`store old camera angles
oldxang#=camera angle x()
oldyang#=camera angle y()
oldzang#=camera angle z()
`point camera at new waypoint
point camera object position x(n),object position y(n),object position z(n)
`move camera towards waypoint at correct speed
move camera CamSpeed#
`smoothly rotate camera from old angle to waypoint angle
rotate camera curveangle(wpxang#(n),oldxang#,20),curveangle(wpyang#(n),oldyang#,20),curveangle(wpzang#(n),oldzang#,20)
`rotate camera wpxang#(n),wpyang#(n),wpzang#(n)
position object 2000000,camera position x(),camera position y(),camera position z()
`check distance to waypoint
wpdist#=intersect object(2000000,object position x(n),object position y(n),object position z(n),camera position x(),camera position y(),camera position z())
if wpdist#=0 then wpdist#=10000
if camera position x()=object position x(n) and camera position y()=object position y(n) and camera position z()=object position z(n) then touching=1 else touching=0
`text 0,100,"waypoint: "+str$(n)
`text 0,120,"dist to waypoint: "+str$(wpdist#)
`check if distance is less than 5 units, and if so, move onto next waypoint. The 5 may need to be altered for different camera speeds.
if wpdist#<5 or touching=1 then inc n `increase waypoint number
`if camera reaches final waypoint, reset to first waypoint
if n>1000000+wp-1
n=1000000
playback=0
endif
text 0,0,"Playing"
sync
return
delete:
for n=1000000 to 1000000+wp-1
if object exist(n) then delete object n
next n
wp=0
return
help:
text 0,0,"Mouse and arrow keys: control camera"
text 0,20,"r: record camera"
text 0,40,"s: stop recording and save data"
text 0,60,"p: play back recording"
text 0,80,"l: load previously saved recording"
text 0,100,"d: delete data (does not delete saved data, just screen data)"
return
FUNCTION 3D_Move_Cam(CamSpeed#)
IF CamSpeed# = 0 THEN EXITFUNCTION
cam_x# = CAMERA ANGLE X() + MOUSEMOVEY() * .2
cam_y# = CAMERA ANGLE Y() + MOUSEMOVEX() * .2
cam_z# = CAMERA ANGLE Z() + MOUSEMOVEZ() * .2
IF upkey() = 1
polarity=1
MOVE CAMERA CamSpeed#
XROTATE CAMERA cam_x#
ENDIF
IF downkey() = 1
polarity=-1
MOVE CAMERA -CamSpeed#
XROTATE CAMERA cam_x#
ENDIF
IF leftkey() = 1
ROTATE CAMERA 0, cam_y#-90, 0
MOVE CAMERA CamSpeed#
ROTATE CAMERA cam_x#, cam_y#, 0
ENDIF
IF rightkey() = 1
ROTATE CAMERA 0, cam_y#+90, 0
MOVE CAMERA CamSpeed#
ROTATE CAMERA cam_x#, cam_y#, 0
ENDIF
ROTATE CAMERA cam_x#, cam_y#, cam_z#
ENDFUNCTION
`********have a nice day*************
The autoloader:
`**** Code for Pasting into Game ****
`Paste the following code right at the end of your game, then:
`Before the main program loop, type "gosub setup_track_cam"
`During the main program loop, type "gosub play_track_cam"
setup_track_cam:
CamSpeed#=0.2
make matrix 1000000,100,100,10,10
dim wpxang#(2000000)
dim wpyang#(2000000)
dim wpzang#(2000000)
make object cube 2000000,1
hide object 2000000
open to read 1,"camera.dat"
read file 1,wp `read number of waypoints stored in file
for n=1000000 to 1000000+wp-1 `repeat loop for number of waypoints stored
read float 1,wpx# `waypoint x position
read float 1,wpy# `waypoint y posiiton
read float 1,wpz# `waypoint z posiiton
read float 1,wpxang#(n) `waypoint x ang
read float 1,wpyang#(n) `waypoint y ang
read float 1,wpzang#(n) `waypoint z ang
make object cube n,1 `make invisible object and position it, so camera something to aim for.
hide object n
position object n,wpx#,wpy#,wpz#
next n
close file 1
return
play_track_cam:
`store old camera angles
oldxang#=camera angle x()
oldyang#=camera angle y()
oldzang#=camera angle z()
`point camera at new waypoint
point camera object position x(n),object position y(n),object position z(n)
`move camera towards waypoint at correct speed
move camera CamSpeed#
`smoothly rotate camera from old angle to waypoint angle
rotate camera curveangle(wpxang#(n),oldxang#,20),curveangle(wpyang#(n),oldyang#,20),curveangle(wpzang#(n),oldzang#,20)
`rotate camera wpxang#(n),wpyang#(n),wpzang#(n)
position object 2000000,camera position x(),camera position y(),camera position z()
`check distance to waypoint
wpdist#=intersect object(2000000,object position x(n),object position y(n),object position z(n),camera position x(),camera position y(),camera position z())
if wpdist#=0 then wpdist#=10000
if camera position x()=object position x(n) and camera position y()=object position y(n) and camera position z()=object position z(n) then touching=1 else touching=0
`text 0,100,"waypoint: "+str$(n)
`text 0,120,"dist to waypoint: "+str$(wpdist#)
`check if distance is less than 5 units, and if so, move onto next waypoint. The 5 may need to be altered for different camera speeds.
if wpdist#<5 or touching=1 then inc n `increase waypoint number
`if camera reaches final waypoint, reset to first waypoint
if n>1000000+wp-1
n=1000000
playback=0
endif
return
It's not 100% tested, so let me know if there are any problems.