`//--------------------------------------------
`// globals
`//--------------------------------------------
type VECTOR3_t
x as float
y as float
z as float
endtype
type ORBCAM_t
rad as float
rot as VECTOR3_t
pos as VECTOR3_t
endtype
type OBJECT_t
pos as VECTOR3_t
rot as VECTOR3_t
endtype
global OrbCam as ORBCAM_t
global Object as VECTOR3_t
global Mouse as VECTOR3_t
`// set initial variables
OrbCam.rad=300 :`// change to suit object size
OrbCam.rot.y=180 :`// makes sure rotation is correct
`// run once just to get initial rotation and depth
mouse.x = mousemovex()*0.3 :`// init mousex
mouse.y = mousemovey()*0.3 :`// init mousey
gosub _Orb_Cam
do
`// mouse movement
mouse.z = mouse.z+mousemovez()/8
mouse.x = mousemovex()*0.3
mouse.y = mousemovey()*0.3
`// orbit cam
if mouseclick()=1 then gosub _Orb_Cam
`// zoom cam
if mouseclick()=3
mouse.z = mouse.z + (mousemovex()*0.3)
endif
`// update camera
rotate camera wrapvalue((OrbCam.rot.y * -1)+180),wrapvalue((OrbCam.rot.x * -1) + 90),0
position camera Object.pos.x + OrbCam.pos.x, Object.pos.y + OrbCam.pos.y, Object.pos.z + OrbCam.pos.z
move camera mouse.z
fastsync :`// update 3d
loop
_Orb_Cam:
`// calc rotation
OrbCam.rot.x = wrapvalue(OrbCam.x+(mouse.x)) :`// XZ Axis
OrbCam.rot.y = wrapvalue(OrbCam.y+(mouse.y)) :`// Y Axis
`// update camera orbit position
OrbCam.pos.x = sin( OrbCam.rot.y ) * OrbCam.rad
OrbCam.pos.y = ( cos( OrbCam.rot.x ) * OrbCam.rad ) * cos( OrbCam.rot.y )
OrbCam.pos.z = ( sin( OrbCam.rot.x ) * OrbCam.rad ) * cos( OrbCam.rot.y )
return
the camera seemed a little awekard that should help