home *** CD-ROM | disk | FTP | other *** search
/ 3D Game Programming for Teens (2nd Edition) / 3DGPFT2E.iso / Source / Chapter06 / demo06-02.bb < prev    next >
Text File  |  2009-01-20  |  1KB  |  59 lines

  1. ;demo06-02.bb - Moving and rotating a sphere  
  2. ; ------------------
  3. Graphics3D 640,480 
  4. SetBuffer BackBuffer()
  5.  
  6. ;Key constants
  7. Const A_KEY = 30
  8. Const Z_KEY = 44
  9. Const LEFT_KEY = 203
  10. Const RIGHT_KEY = 205
  11. Const UP_KEY = 200
  12. Const DOWN_KEY = 208
  13. Const ESC_KEY = 1
  14. Const N_KEY = 49
  15. Const M_KEY = 50
  16. Const COMMA = 51
  17. Const PERIOD = 52
  18. Const X_KEY = 45
  19. Const C_KEY = 46
  20.  
  21. ; Create camera 
  22. camera=CreateCamera()
  23. ; Create a light 
  24. light=CreateLight()
  25.  
  26. ;Create sphere
  27. sphere=CreateSphere(16) 
  28. PositionEntity sphere,0,0,5
  29.  
  30. ;Load the texture 
  31. tex=LoadTexture( "brick.jpg" ) 
  32. ScaleTexture tex, .5,.5 
  33. EntityTexture sphere,tex
  34.  
  35. ; This following code moves our sphere: 
  36. While Not KeyDown(ESC_KEY)
  37.     
  38.     If KeyDown(A_KEY) TranslateEntity sphere,0,-.3,0 
  39.     If KeyDown(Z_KEY) TranslateEntity sphere,0,.3,0 
  40.     If KeyDown(LEFT_KEY) TranslateEntity sphere, -0.3,0,0 
  41.     If KeyDown(RIGHT_KEY) TranslateEntity sphere, 0.3,0,0 
  42.     If KeyDown(UP_KEY) TranslateEntity sphere,0,0,0.3 
  43.     If KeyDown(DOWN_KEY) TranslateEntity sphere,0,0,-0.3
  44.     ; Change rotation values depending on the key pressed 
  45.     If KeyDown(N_KEY)= True Then pitch#=pitch#-1 
  46.     If KeyDown(M_KEY)=True Then pitch#=pitch#+1 
  47.     If KeyDown(COMMA)=True Then yaw#=yaw#-1 
  48.     If KeyDown(PERIOD)=True Then yaw#=yaw#+1 
  49.     If KeyDown(X_KEY)=True Then roll#=roll#-1 
  50.     If KeyDown(C_KEY)=True Then roll#=roll#+1
  51.  
  52.     ;Rotate
  53.     RotateEntity sphere,pitch#,yaw#,roll#
  54.  
  55.     
  56.     RenderWorld 
  57.     Flip
  58. Wend
  59. End