page2.html 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <font face="verdana">
  2. <table border="1" width="100%" bordercolor="#FFFFFF">
  3. <tr>
  4. <td width="61%" bgcolor="#6097C9"><font face="verdana">
  5. <h1 align="left"><font color="#FFFFFF">&nbsp;Movement &amp;<br>
  6. &nbsp;Rotation</font></h1>
  7. <p align="left"><b>&nbsp;Aim</b>: Move an object around 3d space<br>
  8. &nbsp;<b>Skill level</b>: Beginner<br>
  9. &nbsp;<b>Files Needed</b>: movement.bb / rocket.3ds</font>
  10. <p>&nbsp;</td>
  11. <td width="5%">&nbsp;</td>
  12. <td width="34%">
  13. <p align="center"><font face="verdana">
  14. <img src="2c.jpg" alt="Movement" width="167" height="127" align="right">
  15. </font>
  16. </p>
  17. </td>
  18. </tr>
  19. </table>
  20. <p>
  21. Lets start to get things moving, in this tutorial we will be loading an object which I made up in 3D Studio. Granted its not wonderful and looks more like a candle than a state-of-the-art rocket, but it will do us.</p>
  22. <p>
  23. Let's take a look through the full source, feel free to run it and have a play !.</p>
  24. <p>NOTE: You will need to have the object ROCKET.3DS in the same directory as the sourcecode for Blitz to find it</p>
  25. <p>
  26. You can move the rocket forwards with the <b>UP</b> cursor, and rotate it with the <b>LEFT</b> and <b>RIGHT</b> cursor keys.</p>
  27. <table border="1" width="86%" bordercolor="#FFFFFF">
  28. <tr>
  29. <td width="14%">&nbsp;</td>
  30. <td width="72%" bordercolor="#000000" bgcolor="#C0C0C0">&nbsp;<br>
  31. &nbsp; <font face="arial">Graphics3D 800,600<br>
  32. <br>
  33. &nbsp; SetBuffer BackBuffer()<br>
  34. <br>
  35. &nbsp; camera=CreateCamera()<br>
  36. &nbsp; CameraViewport camera,0,0,800,600<br>
  37. <br>
  38. &nbsp; light=CreateLight()<br>
  39. <br>
  40. &nbsp; rocket=LoadMesh( &quot;rocket.3ds&quot; )<br>
  41. &nbsp; PositionEntity rocket,0,0,7<br>
  42. <br>
  43. &nbsp; While Not KeyHit(1)<br>
  44. <br>
  45. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If KeyDown(200) Then<br>
  46. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MoveEntity
  47. rocket,0,0.05,0<br>
  48. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndIf<br>
  49. <br>
  50. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If KeyDown(203) Then<br>
  51. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TurnEntity
  52. rocket,0,0,1.0<br>
  53. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndIf<br>
  54. <br>
  55. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If KeyDown(205) Then<br>
  56. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TurnEntity
  57. rocket,0,0,-1.0<br>
  58. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EndIf<br>
  59. <br>
  60. &nbsp; UpdateWorld<br>
  61. &nbsp; RenderWorld<br>
  62. <br>
  63. &nbsp; Text 320,500,&quot;Movement &amp; Rotation&quot;<br>
  64. <br>
  65. &nbsp; Flip<br>
  66. <br>
  67. &nbsp; Wend<br>
  68. &nbsp; End<br><br>
  69. </font></td>
  70. <td width="14%">&nbsp;</td>
  71. </tr>
  72. </table>
  73. <p>
  74. I won't explain every line of code, just the new commands which we have yet to use. First up is:</p>
  75. </font>
  76. <table border="0" width="100%" bgcolor="#6097C9">
  77. <tr>
  78. <td width="100%">
  79. <b><font face="Arial">rocket=LoadMesh(&quot;rocket.3ds&quot;)</font></b></td>
  80. </tr>
  81. </table>
  82. <font face="verdana">
  83. <p>
  84. As you can probably guess, this line of code will load a 3d model called ROCKET.3DS into a handle variable called 'rocket'.</p>
  85. <p>
  86. What's a handle variable ?, its exactly the same type of label we use in normal blitz for initializing sprites. (It holds the address in memory of where the data is stored), in this case the variable rocket points to the location of where the model is stored.</p>
  87. </font>
  88. <table border="0" width="100%" bgcolor="#6097C9">
  89. <tr>
  90. <td width="100%">
  91. <b><font face="Arial">If KeyDown(200) Then<br>
  92. MoveEntity rocket,0,0.05,0<br>
  93. EndIf</font></b></td>
  94. </tr>
  95. </table>
  96. <font face="verdana">
  97. <p>
  98. These 3 lines tell us that if you are pressing the UP cursor move the object 'ROCKET' in the Y axis 0.05 units upwards.</p>
  99. <p>
  100. Let's take a more indepth look at this, remember my rocket is pointing up - so to start with I want my rocket to travel upwards - hence why I am increasing the Y coordinate. (remember in 3D a positive Y means up - not down like in normal coordinate systems, such as plotting sprites in standard Blitz)</p>
  101. <p>
  102. If my rocket was a car, that was designed to be facing towards the right - then I would want my car to travel to the right of the screen, (it goes forwards) - so I would be increasing the X coordinate. It's very important to get this right at the beginning of your program, or your shape could start moving in the wrong direction to what you want it to.</p>
  103. </font>
  104. <table border="0" width="100%" bgcolor="#6097C9">
  105. <tr>
  106. <td width="100%">
  107. <p>
  108. <b><font face="Arial">If KeyDown(203) Then<br>
  109. TurnEntity rocket,0,0,1.0<br>
  110. EndIf</font></b></p>
  111. <p>
  112. <b><font face="Arial">If KeyDown(205) Then<br>
  113. TurnEntity rocket,0,0,-1.0<br>
  114. EndIf</font></b></p>
  115. </td>
  116. </tr>
  117. </table>
  118. <font face="verdana">
  119. <p>
  120. It should be quite obvious to you that these lines control the rotation of our rocket. If you press the LEFT cursor - turn the rocket 1.0 unit clockwise, whereas pressing the RIGHT cursor results in turning -1.0 units anti clockwise.</p>
  121. <p>
  122. So how comes the shape still moves forward even though we are no longer pointing up ? .. well.. you've got to thank Mr Sibly for giving us the very easy TurnEntity command !. You see as we turn the object, the axis move with it. If we rotate the shape 90 degrees, the Y axis is now pointing where the X axis should be. Don't worry why or how.. just be thankful you don't have to work out any nasty calculations to do it.</p>
  123. <p>
  124. Just incase you where wondering, you can rotate the shape without the axis moving by using the RotateEntity command. This would be used mainly for placement of objects in your world - for example, if I designed the rocket on its side. I would firstly rotate it till its standing upright with the Rotate command - then I could use the turn command to move it.</p>
  125. <p>
  126. And that's about it really.. The only way of getting to know this command, (which will probably be your most widely used command) - is to experiment. Try getting the rocket to rotate in other directions !!</p>
  127. <p>
  128. remember here's the format you use:</p>
  129. <table border="0" width="100%" bgcolor="#FFFF00">
  130. <tr>
  131. <td width="100%">
  132. <font face="verdana">
  133. <i>TurnEntity [what object it is],<br>
  134. X [amount to rotate about the X axis],<br>
  135. Y [amount to rotate about the Y axis],<br>
  136. Z [amount to rotate about the Z axis]</i>
  137. </font>
  138. </td>
  139. </tr>
  140. </table>
  141. <p>NOTE: Blitz3D also contains a command for scaling an object, (see the doc's for info on SCALEENTITY) - if for instance we designed it too small we could increase it on-the-fly, or shrink it if its too large. If you choose to use a multitude of different 3d Packages to design your objects with, then you will need to use this command quite a lot. 3D Studio for instance, likes to scale your object much larger than other packages.</p>
  142. <center><font color="#808080">Tutorial 3 - <a href="page3.html">Camera Movement</a></font></center></font>