home *** CD-ROM | disk | FTP | other *** search
/ DarkBasic Professional / DarkBasicPro.iso / data1.cab / Lang_Files_(English) / Help / examples / light / light2-example.dba < prev   
Encoding:
Text File  |  2004-09-22  |  3.1 KB  |  141 lines

  1. rem Light Functionality
  2. sync on
  3.  
  4. rem Call subroutines
  5. gosub _createscene
  6. gosub _usingvectors
  7. gosub _lightshow
  8. gosub _deletescene
  9.  
  10. rem End of program
  11. end
  12.  
  13. _createscene:
  14.  
  15. rem Create Scene
  16. load image "ground.jpg",1
  17. make matrix 1,1000,1000,100,100
  18. prepare matrix texture 1,1,1,1
  19. position matrix 1,-500,0,-500
  20. position camera 0,100,0
  21.  
  22. rem Set Ambient light
  23. set ambient light 20
  24. color ambient light rgb(64,64,128)
  25.  
  26. rem Set Default Light As Sun
  27. set directional light 0,0,-1,0
  28. color light 0,192,192,192
  29.  
  30. rem Create Moving Light
  31. LightNumber=1 : z#=500
  32. make light LightNumber
  33. set point light LightNumber,0,100,0
  34. color light LightNumber,512,512,256
  35. set light range LightNumber,200
  36.  
  37. rem Create Lighthouse light
  38. make light 2
  39. set spot light 2,45,90
  40. color light 2,512,100,100
  41. position light 2,0,50,400
  42.  
  43. rem Follow Light
  44. make light 3
  45. set spot light 3,15,30
  46. color light 3,-512,-512,0
  47.  
  48. rem Set up Fog
  49. fog on
  50. fog distance 500
  51. fog color rgb(255,128,64)
  52. set normalization off
  53. color backdrop rgb(255,128,64)
  54.  
  55. rem Setup camera
  56. rotate camera 20,0,0
  57.  
  58. return
  59.  
  60. _deletescene:
  61.  
  62. if light exist(1)=1 then delete light 1
  63. if light exist(2)=1 then delete light 2
  64. if light exist(3)=1 then delete light 3
  65. set normalization on
  66. fog off
  67.  
  68. return
  69.  
  70. _usingvectors:
  71.  
  72. VectorNumber=1 : LightNumber=2
  73. result==make vector3(VectorNumber)
  74. set vector3 VectorNumber, 0, 50, 200
  75. position light LightNumber, VectorNumber
  76. set vector3 VectorNumber, 0, 45, 0
  77. rotate light LightNumber, VectorNumber
  78. set vector3 to light position VectorNumber, LightNumber
  79. set vector3 to light rotation VectorNumber, LightNumber
  80. a#=y vector3(VectorNumber)
  81. result=delete vector3(VectorNumber)
  82.  
  83. return
  84.  
  85. _lightshow:
  86.  
  87. while inkey$()<>"x"
  88.  
  89. set cursor 0,0 : print "LIGHT COMMANDS (X to Exit)"
  90. print "USE ARROW KEYS TO MOVE LIGHT"
  91. print "A+Z TO SWITCH SUN OFF/ON"
  92. print
  93. print "LIGHT DATA"
  94. print
  95. if rnd(5)=1 then LightNumber=rnd(3)
  96. print "number:";LightNumber
  97. print "exist:";light exist(LightNumber)
  98. print "type:";light type(LightNumber)
  99. print "range:";light range(LightNumber)
  100. print "visible:";light visible(LightNumber)
  101. print "position x:";light position x(LightNumber)
  102. print "position y:";light position y(LightNumber)
  103. print "position z:";light position z(LightNumber)
  104. print "direction x:";light direction x(LightNumber)
  105. print "direction y:";light direction y(LightNumber)
  106. print "direction z:";light direction z(LightNumber)
  107.  
  108. rem Mouselook Camera
  109. mx=mousemovex() : my=mousemovey()
  110. rotate camera camera angle x()+my,camera angle y()+mx,0
  111.  
  112. rem Control Sun
  113. if inkey$()="a" then hide light 0
  114. if inkey$()="z" then show light 0
  115.  
  116. rem Control Moving Light
  117. if leftkey()=1 then x#=x#-10
  118. if rightkey()=1 then x#=x#+10
  119. if upkey()=1 then z#=z#+10
  120. if downkey()=1 then z#=z#-10
  121.  
  122. LightNumber=1 : ObjectNumber=1
  123. set light to object orientation LightNumber,ObjectNumber
  124. set light to object position LightNumber,ObjectNumber
  125. position light 1,x#,100,z#
  126.  
  127. rem Control Lighthouse light
  128. a#=a#+1 : if a#>359 then a#=a#-360
  129. rotate light 2,0,a#,0
  130.  
  131. rem Control Beam Of Light
  132. position light 3,x#,150,z#
  133. point light 3,0,0,0
  134.  
  135. rem Update screen
  136. sync
  137.  
  138. endwhile
  139.  
  140. return
  141.