TGC Codebase Backup



Camera Views by Ram256

7th May 2008 18:20
Summary

A simple graphics program that creates a rotating cube and a translating circle with some camera views. The user has the normal view and create more five different views.



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `Create some variables
posx = 0
posz = 0
angle = 0
height = 150
radius = 300
screenw = screen width()
screenh = screen height()

`Initialize program
sync on
sync rate 100
hide mouse
color backdrop rgb(0,60,60)

`Create the floor
`(You can create the image textures by yourself)
make matrix 1, 1000, 1000, 10, 9
load image "floor.bmp", 2 
position matrix 1, -500, -100, -500
prepare matrix texture 1, 2, 1, 1
update matrix 1

`Create a textured cube
`(You can create the image textures by yourself)
make object cube 1, 100
load image "cube.bmp", 1
texture object 1, 1

`Create the moving sphere
make object sphere 2, 50
color object 2, rgb(245,0,200)

`Create and set up the cameras
make camera 1
set camera view 1, 10, 10, 110, 110
make camera 2
set camera view 2, screenw-110, 10, screenw-10, 110
make camera 3
set camera view 3, 140, 10, 240, 110
make camera 4
position camera 4, 0, 600, 0
point camera 4, 0, 0, 0
set camera view 4, screenw-240, 10, screenw-140, 110
make camera 5
position camera 5, 0, 0, 0
set camera view 5, screenw/2-50, 10, screenw/2+50, 110
position camera 0, 0, 100, -400
point camera 0, 0, 0, 0

`Start the loop
repeat
   `Rotate the cube and point camera 2 at it
   yrotate object 1, object angle y(1) + 1
   set camera to follow 2, 0, 0, 0, 0, 200, 30, 1.0, 0

   `Rotate a point around the scene
   posx = cos(angle) * radius
   posz = sin(angle) * radius
   angle = angle + 1

   `Move camera 1
   position camera 1, posx, height, posz
   point camera 1, 0, 0, 0

   `Move the sphere
   position object 2, -1*posx, COS(angle)*posz/2, -1*posz+200

   `Move camera 3
   X = object position x(2)
   Y = object position y(2)
   Z = object position z(2)
   set camera to follow 3, X, Y, Z, 0, 100, Y, 1.0, 0

   `Display frame rate and update the screen
   text screenw-70, screenh-20, "FPS " + str$(screen fps())
   sync
until escapekey()=1

`Clean up
show mouse
end