EntityX.htm 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <html>
  2. <head>
  3. <title>Blitz3D Docs</title>
  4. <link rel=stylesheet href=../css/commands.css type=text/css>
  5. </head>
  6. <body>
  7. <h1>EntityX# ( entity[,global] )</h1>
  8. <h1>Parameters</h1>
  9. <table>
  10. <tr>
  11. <td>
  12. entity = handle of Loaded or Created Entity <br />
  13. global = True for Global coordinates, False for Local. Optional, defaults to False.
  14. </td>
  15. </tr>
  16. </table>
  17. <h1>Description</h1>
  18. <table>
  19. <tr>
  20. <td>
  21. The X-coordinate of the entity. <br />
  22. If the global flag is set to False then the parent's local coordinate system is used. <br />
  23. <br />
  24. NOTE: If the entity has no parent then local and global coordinates are the same. <br />
  25. In this case you can think of the 3d world as the parent. <br />
  26. <br />
  27. Global coordinates refer to the 3d world. Blitz 3D uses a left-handed system: <br />
  28. <br />
  29. X+ is to the right <br />
  30. Y+ is up <br />
  31. Z+ is forward ( into the screen ) <br />
  32. <br />
  33. Every entity also has its own Local coordinate system. <br />
  34. <br />
  35. The global system never changes. <br />
  36. But the local system is carried along as an entity moves and turns. <br />
  37. <br />
  38. This same concept is used in the entity movement commands: <br />
  39. <br />
  40. MoveEntity entity, 0,0,1 <br />
  41. <br />
  42. No matter what the orientation this moves one unit forward.
  43. </td>
  44. </tr>
  45. </table>
  46. <h1><a href=../3d_examples/EntityX.bb>Example</a></h1>
  47. <table>
  48. <tr>
  49. <td>
  50. ; EntityX / EntityY / EntityZ example. <br />
  51. <br />
  52. ; Escape quits, other keys move or pause the display. <br />
  53. <br />
  54. Const width = 640, height = 480 <br />
  55. Const KEY_ESC = 1, KEY_LEFT = 203, KEY_RIGHT = 205 <br />
  56. <br />
  57. Graphics3D 640, 480 <br />
  58. AmbientLight 50, 50, 50 <br />
  59. <br />
  60. Global isMoving = False ; used to pause/resume movement <br />
  61. Global count ; how many updates have been done <br />
  62. <br />
  63. <br />
  64. ; Set up a camera, light and three entities... <br />
  65. <br />
  66. cam = CreateCamera() <br />
  67. PositionEntity cam, 0, 2, -50 <br />
  68. CameraZoom cam, 4 <br />
  69. <br />
  70. lt = CreateLight() : TurnEntity lt, 30, 40, 0 <br />
  71. <br />
  72. <br />
  73. Global oSphere, pCone, cSphere <br />
  74. <br />
  75. oSphere = CreateSphere() <br />
  76. EntityColor oSphere, 250, 50, 0 ; Orange = Origin, parent of cone <br />
  77. <br />
  78. pCone = CreateCone( 8, True, oSphere) ; will be a parent of small sphere <br />
  79. ScaleEntity pCone, .8, 2.0, .8 <br />
  80. PositionEntity pCone, 8, 0, 0 <br />
  81. EntityColor pCone, 255, 255, 0 <br />
  82. <br />
  83. cSphere = CreateSphere( 8, pCone ) ; child of the cone <br />
  84. EntityColor cSphere, 150, 150, 0 <br />
  85. ScaleEntity cSphere, .4/.8, .4/2.0, .4/.8 ; try commenting out this line <br />
  86. PositionEntity cSphere, 0, 2, 0 ; above parent <br />
  87. <br />
  88. ; ... and we are ready run. <br />
  89. <br />
  90. While Not KeyDown( KEY_ESC ) <br />
  91. <br />
  92. UpdateEverything <br />
  93. RenderWorld <br />
  94. ShowInfo <br />
  95. <br />
  96. Flip <br />
  97. <br />
  98. Wend <br />
  99. <br />
  100. End <br />
  101. <br />
  102. <br />
  103. <br />
  104. Function UpdateEverything( ) <br />
  105. <br />
  106. ; Nothing moves relative to its parent, so local coordinates are constant. <br />
  107. ; Try uncommenting the PositionEntity command to change this. <br />
  108. <br />
  109. <br />
  110. If GetKey() Then isMoving = Not isMoving <br />
  111. <br />
  112. If isMoving <br />
  113. TurnEntity oSphere, 0, .5, 0 <br />
  114. TurnEntity pCone, .2, 0, 0 <br />
  115. <br />
  116. count = count + 1 <br />
  117. a# = count Mod 360 <br />
  118. ; PositionEntity cSphere, 0, 2 + Sin( a ), 0 ; experiment with this <br />
  119. <br />
  120. End If <br />
  121. <br />
  122. End Function <br />
  123. <br />
  124. Function ShowInfo( ) ; global and local coordinates for all entities <br />
  125. Local x$, y$, z$ <br />
  126. <br />
  127. Color 255, 255, 255 <br />
  128. Text 185, 20, "Global" <br />
  129. Text 495, 20, "Local" <br />
  130. <br />
  131. Color 250, 50, 0 <br />
  132. Text 20, 50, "oSphere: " + XYZ( oSphere, True ) <br />
  133. Text 400, 50, XYZ( oSphere, False ) <br />
  134. <br />
  135. Color 255, 255, 0 <br />
  136. Text 20, 75, " pCone: " + XYZ( pCone, True ) <br />
  137. Text 400, 75, XYZ( pCone, False ) <br />
  138. <br />
  139. Color 150, 150, 0 <br />
  140. Text 20, 100, "cSphere: " + XYZ( cSphere, True ) <br />
  141. Text 400, 100, XYZ( cSphere, False ) <br />
  142. <br />
  143. End Function <br />
  144. <br />
  145. ; ****************************************************************** <br />
  146. <br />
  147. ; These two functions just format the text display. <br />
  148. ; Without them there are too many numbers crowding the screen. <br />
  149. <br />
  150. Function Round#( x#, m# ) ; returns x rounded to multiple of m <br />
  151. If m < 0.0 Then m = -m <br />
  152. s# = Sgn( x ) <br />
  153. If x < 0.0 Then x = -x <br />
  154. diff# = x Mod m <br />
  155. If diff < .5 * m <br />
  156. Return ( x - diff ) * s <br />
  157. Else <br />
  158. Return ( m + x - diff ) * s <br />
  159. End If <br />
  160. End Function <br />
  161. <br />
  162. <br />
  163. Function XYZ$( entity, globalFlag ) <br />
  164. <br />
  165. ex# = Round( EntityX( entity, globalFlag ), .001 ) <br />
  166. ey# = Round( EntityY( entity, globalFlag ), .001 ) <br />
  167. ez# = Round( EntityZ( entity, globalFlag ), .001 ) <br />
  168. <br />
  169. Return RSet( ex, 8 ) + RSet( ey, 8 ) + RSet( ez, 8 ) <br />
  170. <br />
  171. End Function
  172. </td>
  173. </tr>
  174. </table>
  175. <br>
  176. <a target=_top href=../index.htm>Index</a><br>
  177. <br>
  178. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=EntityX&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  179. </html>