;Rotate, Zoom and Drag Camera with Mouse, on 18/11/05, by mukGraphics3D 640,480,16,2SetBuffer BackBuffer()Global camx#,camy#,camz#=-10,pivx#,pivz#,camspd#=0.02 ;cameraGlobal msex,msey,lastx,lasty,movex,movey ;mouseGlobal pivot,camera,light ;entitypivot=CreatePivot() ;pivotcamera=CreateCamera(pivot) ;camera with pivot parentlight=CreateLight() ;lightRotateEntity light,90,0,0cube=CreateCube() ;cube;Main LoopWhile Not KeyDown(1) UpdateCamera()RenderWorld Text 0,0,"Press LShift to Zoom" Text 0,16,"Press LCtrl to Drag" Text 0,48,"X dg:"+camx Text 0,64,"Y dg:"+camy Text 0,80,"Zoom:"+camz Text 0,96,"X mts:"+pivx Text 0,112,"Z mts:"+pivzFlipWendEnd;FunctionsFunction UpdateCamera()lastx=msex : lasty=msey ;get mouse movementsmsex=MouseX() : msey=MouseY()movex=msex-lastx : movey=msey-lastyIf MouseDown(1) If KeyDown(29) ;LCtrl key, camera drag yrot#=camy : xaxis#=camspd : zaxis#=camspd ;init xz axis If yrot>90 And yrot<270 Then zaxis=-zaxis ;-zaxis if 90-270dg If yrot>180 Then yrot=360-yrot : xaxis=-xaxis ;-xaxis if 180-360dg If yrot>90 Then yrot=180-yrot ;reduce y rotation to 90dg yfr#=yrot*0.011 : ifr#=1-yfr ;set y as fraction of 1 and get inverse mxpx#=movex*ifr*zaxis : mxpz#=movex*yfr*xaxis ;set mouse xy movements mypx#=movey*yfr*xaxis : mypz#=movey*ifr*zaxis ;by y fraction and axis pivx=pivx-mxpx-mypx : pivz=pivz-mxpz+mypz ;add to pivot positions ElseIf KeyDown(42) ;LShift key, camera zoom camz=camz-movey*camspd ;-mousey sets camera z position If camz>-3 Then camz=-3 ;limit z to 3-30mt If camz<-30 Then camz=-30 Else ;Neither keys, camera rotation camx=camx+movey*10*camspd ;mousey sets camera x rotation If camx>90 Then camx=90 ;limit x to 0-90dg If camx<0 Then camx=0 camy=camy-movex*10*camspd ;-mousex sets camera y rotation If camy>359 Then camy=0 ;wrap y to 0-359dg If camy<0 Then camy=359 EndIfEndIfRotateEntity pivot,camx,camy,0 ;rotate cameraPositionEntity camera,0,0,camz ;zoom cameraPositionEntity pivot,pivx,0,pivz ;drag cameraEnd Function