TGC Codebase Backup



3D rotation by Dimension

19th May 2004 17:40
Summary

Shows how to rotate around a object



Description

The 3D rotation program uses two angle to rotate around. This program creates a sphere using spheres and allows the user to rotate the camera.



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    global ObjectNum

dis = 100
for ax = 1 to 360 step 15
   for ay = 1 to 360 step 15
      CX = (sin(ax)*cos(ay))*(dis/2)
      CY = sin(ay)*(dis/2)
      CZ = (cos(ax)*cos(ay))*(dis/2)
      MakeSphere(5)
      position object ObjectNum, CX, CY, CZ
   next ay
next ax

do
   ControlCamera(200+MouseZ())
   sync
loop

function ControlCamera(dis)
   SW = screen width()
   SH = screen height()
   ax = (MouseX()-(SW/2))/2
   ay = (MouseY()-(SH/2))/2
   position camera (sin(ax)*cos(ay))*dis, sin(ay)*dis, (cos(ax)*cos(ay))*dis
   point camera 0, 0, 0
endfunction

function MakeBox(width, height, depth)
   ObjectNum = ObjectNum + 1
   make object box ObjectNum, width, height, depth
endfunction

function MakeSphere(size)
   ObjectNum = ObjectNum + 1
   make object sphere ObjectNum, size
endfunction