home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / examples / camera / camera2-example.dba < prev    next >
Encoding:
Text File  |  2004-09-22  |  3.8 KB  |  153 lines

  1. rem Camera Functionality
  2. autocam on
  3.  
  4. gosub _setupmatrix
  5. gosub _simplecamera
  6. gosub _freeflightcamera
  7. gosub _mouselookcamera
  8. gosub _modifycamera
  9. gosub _trackercamera
  10. gosub _followcamera
  11. gosub _usingvectors
  12. gosub _cameradata
  13.  
  14. rem End of program
  15. autocam off
  16. end
  17.  
  18. _setupmatrix:
  19.  make matrix 1,1000,1000,100,100
  20.  set matrix height 1,50,50,500
  21.  update matrix 1
  22. return
  23.  
  24. _simplecamera:
  25.  
  26. while mouseclick()<>1
  27.  set cursor 0,0 : print "SIMPLE CAMERA (EULER) (Left Mouse Button To Continue)"
  28.  print "USE ARROW KEYS TO MOVE / A+Z XRotate / S+X ZRotate"
  29.  print "SPACE/RETURN To Toggle Rotation Order"
  30.  if upkey()=1 then move camera 5.0
  31.  if downkey()=1 then move camera -5.0
  32.  if leftkey()=1 then y#=y#-1
  33.  if rightkey()=1 then y#=y#+1
  34.  if inkey$()="a" then x#=x#-1
  35.  if inkey$()="z" then x#=x#+1
  36.  if inkey$()="s" then z#=z#-1
  37.  if inkey$()="x" then z#=z#+1
  38.  if spacekey()=1 then set camera rotation zyx
  39.  if returnkey()=1 then set camera rotation xyz
  40.  xrotate camera x#
  41.  yrotate camera y#
  42.  zrotate camera z#
  43. endwhile
  44. while mouseclick()=1 : endwhile
  45.  
  46. return
  47.  
  48. _freeflightcamera:
  49.  
  50. while mouseclick()<>1
  51.  set cursor 0,0 : print "FREE FLIGHT CAMERA (Left Mouse Button To Continue)"
  52.  print "USE ARROW KEYS TO ROTATE / A+Z Roll Camera"
  53.  if upkey()=1 then pitch camera up 1
  54.  if downkey()=1 then pitch camera down 1
  55.  if leftkey()=1 then turn camera left 1
  56.  if rightkey()=1 then turn camera right 1
  57.  if inkey$()="a" then roll camera left 1
  58.  if inkey$()="z" then roll camera right 1
  59. endwhile
  60. while mouseclick()=1 : endwhile
  61.  
  62. return
  63.  
  64. _mouselookcamera:
  65.  
  66. backdrop off
  67. point camera 0,0,0
  68. while mouseclick()<>1
  69.  set cursor 0,0 : print "MOUSELOOK CAMERA (Left Mouse Button To Continue)"
  70.  x#=x#+mousemovey() : y#=y#+mousemovex() : z#=z#+mousemovez()
  71.  rotate camera x#,y#,z#
  72. endwhile
  73. while mouseclick()=1 : endwhile
  74. color backdrop rgb(128,0,0)
  75. backdrop on
  76.  
  77. return
  78.  
  79. _modifycamera:
  80.  
  81. rem 22 Degrees Field of View
  82. set camera fov 22
  83. set camera range 1,750
  84. set camera view 10,10,640-10,480-130
  85.  
  86. return
  87.  
  88. _trackercamera:
  89.  
  90. set camera rotation xyz
  91. position camera 0,100,-500
  92. while mouseclick()<>1
  93.  center text 320,30,"TRACKER CAMERA (Left Mouse Button To Continue)"
  94.  x#=cos(a#)*500 : z#=sin(a#)*500
  95.  a#=a#+1.0 : if a#>359 then a#=a#-360
  96.  position camera x#,100,z#
  97.  point camera 500,0,500
  98. endwhile
  99. while mouseclick()=1 : endwhile
  100.  
  101. return
  102.  
  103. _followcamera:
  104.  
  105. make object sphere 1,10
  106. set camera rotation xyz
  107. set camera range 1,3000
  108. while mouseclick()<>1
  109.  center text 320,30,"FOLLOW CAMERA (Left Mouse Button To Continue)"
  110.  a#=a#+1 : if a#>359 then a#=a#-360
  111.  x#=500+(cos(a#)*100) : z#=500+(sin(a#)*500)
  112.  distance#=200.0 : height#=100.0 : smooth#=25.0
  113.  dx#=x#-camera position x()
  114.  dz#=z#-camera position z()
  115.  angle#=atanfull(dx#,dz#)
  116.  set camera to follow x#,0,z#,angle#,distance#,height#,smooth#,0
  117.  set camera to object orientation 1
  118. endwhile
  119. while mouseclick()=1 : endwhile
  120.  
  121. return
  122.  
  123. _usingvectors:
  124.  
  125. VectorNumber=1 : CameraNumber=0
  126. result==make vector3(VectorNumber)
  127. set vector3 VectorNumber, 500, 10, 500
  128. position camera CameraNumber, VectorNumber
  129. set vector3 VectorNumber, 0, 45, 0
  130. rotate camera CameraNumber, VectorNumber
  131. set vector3 to camera position VectorNumber, CameraNumber
  132. set vector3 to camera rotation VectorNumber, CameraNumber
  133. x#=x vector3(VectorNumber)
  134. y#=y vector3(VectorNumber)
  135. result=delete vector3(VectorNumber)
  136.  
  137. return
  138.  
  139. _cameradata:
  140.  
  141. while inkey$()<>"x"
  142.  set cursor 0,0 : print : print "  CAMERA DATA (Press X to Exit)" : print
  143.  print "  angle x:";camera angle x()
  144.  print "  angle y:";camera angle y()
  145.  print "  angle z:";camera angle z()
  146.  print "  position x:";camera position x()
  147.  print "  position y:";camera position y()
  148.  print "  position z:";camera position z()
  149.  x#=x#+mousemovey() : y#=y#+mousemovex() : rotate camera x#,y#,0
  150. endwhile
  151.  
  152. return
  153.