O'Reilly logo

3D Game Programming for Teens, Second Edition by Eric Grebler, Maneesh Sethi

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Switching Cameras Virtually

While switching cameras is one way of changing the viewpoint, another easier way to change the viewpoint is to simply move or reposition a camera when an event occurs. In the following example, we’ll change the position of the camera when certain keys are hit. Enter the following code to create a simple cylinder:

; Lighting and Cameras
; ––––––––––––––––——
Graphics3D 640,480
SetBuffer BackBuffer()
;Create camera
camera=CreateCamera()
; Creating a light
light=CreateLight()
; This is the code for creating the cylinder
cylinder=CreateCylinder()
PositionEntity cylinder,0,0,5
; This following code makes our program run
While Not KeyDown( 1 )
RenderWorld
Flip
Wend
End

If you run the program now, you should just see a cylinder ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required