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

Rotating Objects on Their Own

In the previous section, you learned how you could rotate an object via keyboard commands. What if you wanted to just have an object rotate on its own? To do this, you just have to slightly modify the code you used in the last section. Here is the code for a program that contains a single cube that rotates on its own:

;demo06-03.bb - Rotating a cube on its own ; –––––––– Graphics3D 640,480 SetBuffer BackBuffer() ;Key constants Const ESC_KEY = 1 ; Create camera camera=CreateCamera() ; Create a light light=CreateLight() ;Create cube cube = CreateCube() PositionEntity cube,0,0,5 ; This following code rotates our cube: While Not KeyDown(ESC_KEY) pitch# = pitch# - 1 ;Rotate RotateEntity cube,pitch#,yaw#,roll# RenderWorld ...

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