EntityZ.htm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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>EntityZ# ( 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 Z-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. See EntityX() for an overview of Local and Global coordinates.
  25. </td>
  26. </tr>
  27. </table>
  28. <h1><a href=../3d_examples/EntityZ.bb>Example</a></h1>
  29. <table>
  30. <tr>
  31. <td>
  32. ; EntityX / EntityY / EntityZ example. <br />
  33. <br />
  34. ; Escape quits, other keys move or pause the display. <br />
  35. <br />
  36. Const width = 640, height = 480 <br />
  37. Const KEY_ESC = 1, KEY_LEFT = 203, KEY_RIGHT = 205 <br />
  38. <br />
  39. Graphics3D 640, 480 <br />
  40. AmbientLight 50, 50, 50 <br />
  41. <br />
  42. Global isMoving = False ; used to pause/resume movement <br />
  43. Global count ; how many updates have been done <br />
  44. <br />
  45. <br />
  46. ; Set up a camera, light and three entities... <br />
  47. <br />
  48. cam = CreateCamera() <br />
  49. PositionEntity cam, 0, 2, -50 <br />
  50. CameraZoom cam, 4 <br />
  51. <br />
  52. lt = CreateLight() : TurnEntity lt, 30, 40, 0 <br />
  53. <br />
  54. <br />
  55. Global oSphere, pCone, cSphere <br />
  56. <br />
  57. oSphere = CreateSphere() <br />
  58. EntityColor oSphere, 250, 50, 0 ; Orange = Origin, parent of cone <br />
  59. <br />
  60. pCone = CreateCone( 8, True, oSphere) ; will be a parent of small sphere <br />
  61. ScaleEntity pCone, .8, 2.0, .8 <br />
  62. PositionEntity pCone, 8, 0, 0 <br />
  63. EntityColor pCone, 255, 255, 0 <br />
  64. <br />
  65. cSphere = CreateSphere( 8, pCone ) ; child of the cone <br />
  66. EntityColor cSphere, 150, 150, 0 <br />
  67. ScaleEntity cSphere, .4/.8, .4/2.0, .4/.8 ; try commenting out this line <br />
  68. PositionEntity cSphere, 0, 2, 0 ; above parent <br />
  69. <br />
  70. ; ... and we are ready run. <br />
  71. <br />
  72. While Not KeyDown( KEY_ESC ) <br />
  73. <br />
  74. UpdateEverything <br />
  75. RenderWorld <br />
  76. ShowInfo <br />
  77. <br />
  78. Flip <br />
  79. <br />
  80. Wend <br />
  81. <br />
  82. End <br />
  83. <br />
  84. <br />
  85. <br />
  86. Function UpdateEverything( ) <br />
  87. <br />
  88. ; Nothing moves relative to its parent, so local coordinates are constant. <br />
  89. ; Try uncommenting the PositionEntity command to change this. <br />
  90. <br />
  91. <br />
  92. If GetKey() Then isMoving = Not isMoving <br />
  93. <br />
  94. If isMoving <br />
  95. TurnEntity oSphere, 0, .5, 0 <br />
  96. TurnEntity pCone, .2, 0, 0 <br />
  97. <br />
  98. count = count + 1 <br />
  99. a# = count Mod 360 <br />
  100. ; PositionEntity cSphere, 0, 2 + Sin( a ), 0 ; experiment with this <br />
  101. <br />
  102. End If <br />
  103. <br />
  104. End Function <br />
  105. <br />
  106. Function ShowInfo( ) ; global and local coordinates for all entities <br />
  107. Local x$, y$, z$ <br />
  108. <br />
  109. Color 255, 255, 255 <br />
  110. Text 185, 20, "Global" <br />
  111. Text 495, 20, "Local" <br />
  112. <br />
  113. Color 250, 50, 0 <br />
  114. Text 20, 50, "oSphere: " + XYZ( oSphere, True ) <br />
  115. Text 400, 50, XYZ( oSphere, False ) <br />
  116. <br />
  117. Color 255, 255, 0 <br />
  118. Text 20, 75, " pCone: " + XYZ( pCone, True ) <br />
  119. Text 400, 75, XYZ( pCone, False ) <br />
  120. <br />
  121. Color 150, 150, 0 <br />
  122. Text 20, 100, "cSphere: " + XYZ( cSphere, True ) <br />
  123. Text 400, 100, XYZ( cSphere, False ) <br />
  124. <br />
  125. End Function <br />
  126. <br />
  127. ; ****************************************************************** <br />
  128. <br />
  129. ; These two functions just format the text display. <br />
  130. ; Without them there are too many numbers crowding the screen. <br />
  131. <br />
  132. Function Round#( x#, m# ) ; returns x rounded to multiple of m <br />
  133. If m < 0.0 Then m = -m <br />
  134. s# = Sgn( x ) <br />
  135. If x < 0.0 Then x = -x <br />
  136. diff# = x Mod m <br />
  137. If diff < .5 * m <br />
  138. Return ( x - diff ) * s <br />
  139. Else <br />
  140. Return ( m + x - diff ) * s <br />
  141. End If <br />
  142. End Function <br />
  143. <br />
  144. <br />
  145. Function XYZ$( entity, globalFlag ) <br />
  146. <br />
  147. ex# = Round( EntityX( entity, globalFlag ), .001 ) <br />
  148. ey# = Round( EntityY( entity, globalFlag ), .001 ) <br />
  149. ez# = Round( EntityZ( entity, globalFlag ), .001 ) <br />
  150. <br />
  151. Return RSet( ex, 8 ) + RSet( ey, 8 ) + RSet( ez, 8 ) <br />
  152. <br />
  153. End Function
  154. </td>
  155. </tr>
  156. </table>
  157. <br>
  158. <a target=_top href=../index.htm>Index</a><br>
  159. <br>
  160. Click <a href=http://www.blitzbasic.co.nz/b3ddocs/command.php?name=EntityZ&ref=comments target=_blank>here</a> to view the latest version of this page online</body>
  161. </html>