Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. ; ----------------------------------------------------------------------------
  2. ; Irrlicht Wrapper for Imperative Languages - Freebasic Examples
  3. ; Frank Dodd (2006)
  4. ; Converted/modified for the au3Irr2 project by linus
  5. ; ----------------------------------------------------------------------------
  6. ; Example 92: Moving Entities by Collision
  7. ; This example loads a map and a character model into the scene and then
  8. ; uses a collision function to let the character walk up the stairs in the map
  9. ; ----------------------------------------------------------------------------
  10.  
  11. ; ////////////////////////////////////////////////////////////////////////////
  12. ; Includes for extension libraries
  13. #include "..\au3Irrlicht2.au3"
  14. #include <Misc.au3>
  15. opt("MustDeclareVars", True)
  16. HotKeySet("{ESC}", "_exit")
  17.  
  18. Func _exit()
  19. _IrrStop()
  20. Exit
  21. EndFunc ; _exit
  22.  
  23.  
  24. ; ////////////////////////////////////////////////////////////////////////////
  25. ; global variables
  26.  
  27. ; irrlicht objects
  28. DIM $MD2Mesh ; irr_mesh
  29. DIM $MeshTexture ; irr_texture
  30. DIM $SceneNode ; irr_node
  31. DIM $BSPMesh ; irr_mesh
  32. DIM $BSPNode ; irr_node
  33. DIM $OurCamera ; irr_camera
  34. DIM $Light ; irr_node
  35.  
  36. DIM $selector ; irr_selector
  37. DIM $ellipsoidPosition[3] ; $IRR_VECTOR
  38. DIM $ellipsoidRadius[3] ; $IRR_VECTOR
  39. DIM $velocity[3] ; $IRR_VECTOR
  40. DIM $gravity[3] ; $IRR_VECTOR
  41. DIM $outPosition[3] ; $IRR_VECTOR
  42. DIM $outHitPosition[3] ; $IRR_VECTOR
  43. DIM $outFalling ; Integer
  44.  
  45. ; ////////////////////////////////////////////////////////////////////////////
  46.  
  47.  
  48. ; -----------------------------------------------------------------------------
  49. ; start the irrlicht interface
  50. _IrrStart( $IRR_EDT_OPENGL, 800, 600, $IRR_BITS_PER_PIXEL_32, _
  51. $IRR_WINDOWED, $IRR_NO_SHADOWS, $IRR_IGNORE_EVENTS, $IRR_VERTICAL_SYNC_ON )
  52.  
  53. ; set the window caption
  54. _IrrSetWindowCaption( "Example 92: Moving Entities by Collision" )
  55.  
  56. ; Load the character mode
  57. $MD2Mesh = _IrrGetMesh( "../media/zumlin.md2" )
  58. $MeshTexture = _IrrGetTexture( "../media/zumlin.pcx" )
  59. $SceneNode = _IrrAddMeshToScene( $MD2Mesh )
  60. _IrrSetNodeMaterialTexture( $SceneNode, $MeshTexture, 0 )
  61. _IrrSetNodeMaterialFlag( $SceneNode, $IRR_EMF_LIGHTING, $IRR_OFF )
  62. _IrrPlayNodeMD2Animation( $SceneNode, $IRR_EMAT_RUN )
  63. _IrrSetNodeScale( $SceneNode, 5, 5, 5 )
  64. _IrrSetNodeRotation( $SceneNode, 0, 270, 0 )
  65.  
  66. ; load the bsp environment
  67. _IrrAddZipFile( "../media/TestMap01.pk3", $IRR_IGNORE_CASE, $IRR_IGNORE_PATHS )
  68. $BSPMesh = _IrrGetMesh( "TestMap01.bsp" )
  69. $BSPNode = _IrrAddMeshToSceneAsOcttree( $BSPMesh )
  70.  
  71. ; move the map into position around the model
  72. _IrrSetNodePosition( $BSPNode, -0,-0,-0)
  73.  
  74. ; create a collision object from the map
  75. $selector = _IrrGetCollisionGroupFromComplexMesh( $BSPMesh, $BSPNode )
  76.  
  77. ; This is the velocity the character moves each frame, the upward velocity seams
  78. ; to help the character climb stairs but it should never be greater than gravity
  79. $velocity[0] = 0.0
  80. $velocity[1] = 0.50
  81. $velocity[2] = 0.0
  82.  
  83. ; the direction of gravity pulling the character to the ground, if you apply too
  84. ; little gravity you may find your character doesn't move
  85. $gravity[0] = 0.0
  86. $gravity[1] = -5
  87. $gravity[2] = 0.0
  88.  
  89. ; the position of the character in the scene (just at the top of the stairs)
  90. $ellipsoidPosition[0] = 0
  91. $ellipsoidPosition[1] = 300
  92. $ellipsoidPosition[2] = 0
  93.  
  94. ; the size of the collision volume. this is important in moving up steps. too
  95. ; large and you will get stuck in a doorway, too small and you won't climb stairs
  96. $ellipsoidRadius[0] = 60.0
  97. $ellipsoidRadius[1] = 150.0
  98. $ellipsoidRadius[2] = 60.0
  99.  
  100. ; add a camera into the scene
  101. $OurCamera = _IrrAddFPSCamera()
  102. _IrrSetNodePosition($OurCamera, 0, 300, 0)
  103. ; -----------------------------------------------------------------------------
  104. ; while the irrlicht environment is still running
  105. Dim $timer = TimerInit()
  106. WHILE _IrrRunning()
  107. ; is it time for another frame
  108. if TimerDiff($timer) > 16.7 then
  109. Select
  110. Case _IsPressed(57)
  111. $velocity[0] = +3
  112. Case _IsPressed(53)
  113. $velocity[0] = -3
  114. Case Else
  115. $velocity[0] = 0
  116. EndSelect
  117. Select
  118. Case _IsPressed(41)
  119. $velocity[2] = +3
  120. Case _IsPressed(44)
  121. $velocity[2] = -3
  122. Case Else
  123. $velocity[2] = 0
  124. EndSelect
  125. ; calculate the time the next frame starts
  126. $timer = TimerInit()
  127.  
  128. ; begin the scene, erasing the canvas with sky-blue before rendering
  129. _IrrBeginScene( 240, 255, 255 )
  130.  
  131. ; Collides a moving ellipsoid with a 3d world with gravity and returns the
  132. ; resulting new position of the ellipsoid.
  133. _IrrGetCollisionResultPosition ( _
  134. $selector, _
  135. $ellipsoidPosition, _
  136. $ellipsoidRadius, _
  137. $velocity, _
  138. $gravity, _
  139. 0.0005, _
  140. $ellipsoidPosition, _
  141. $outHitPosition, _
  142. $outFalling )
  143.  
  144. ; move the character to the position that is the result of the test
  145. _IrrSetNodePosition( $SceneNode, _
  146. $ellipsoidPosition[0], _
  147. $ellipsoidPosition[1] + $gravity[1] - 30.0, _
  148. $ellipsoidPosition[2] )
  149.  
  150. ; make the camera follow the character
  151. ; _IrrSetNodePosition( $OurCamera, _
  152. ; $ellipsoidPosition[0] + 50.0 + ($ellipsoidPosition[2] - 500 ) / 10.0, _
  153. ; $ellipsoidPosition[1] + $gravity[1] + 40.0, _
  154. ; $ellipsoidPosition[2] + 40.0 )
  155.  
  156. ; point the camera at the character
  157. ; _IrrSetCameraTarget( $OurCamera, _
  158. ; $ellipsoidPosition[0], _
  159. ; $ellipsoidPosition[1] + $gravity[1], _
  160. ; $ellipsoidPosition[2] )
  161.  
  162. ; draw the scene
  163. _IrrDrawScene()
  164.  
  165. ; end drawing the scene and render it
  166. _IrrEndScene()
  167. endif
  168. WEND
  169.  
  170. ; -----------------------------------------------------------------------------
  171. ; Stop the irrlicht engine and release resources
  172. _IrrStop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement