tutorial.html 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
  5. <meta http-equiv="X-UA-Compatible" content="IE=9"/>
  6. <meta name="generator" content="Doxygen 1.8.13"/>
  7. <meta name="viewport" content="width=device-width, initial-scale=1"/>
  8. <title>Tutorial 17: Helloworld mobile for WinCE 6. DEPRECATED</title>
  9. <html xmlns="http://www.w3.org/1999/xhtml">
  10. <!-- Wanted to avoid copying .css to each folder, so copied default .css from doxyen in here, kicked out most stuff we don't need for examples and modified some a little bit.
  11. Target was having a single html in each example folder which is created from the main.cpp files and needs no files besides some images below media folder.
  12. Feel free to improve :)
  13. -->
  14. <style>
  15. body, table, div, p, dl {
  16. font: 400 14px/22px;
  17. }
  18. body {
  19. background-color: #F0F0F0;
  20. color: black;
  21. margin-left: 5%;
  22. margin-right: 5%;
  23. }
  24. p.reference, p.definition {
  25. font: 400 14px/22px;
  26. }
  27. .title {
  28. font: 400 14px/28px;
  29. font-size: 150%;
  30. font-weight: bold;
  31. margin: 10px 2px;
  32. }
  33. h1, h2, h3, h4, h5, h6 {
  34. -webkit-transition: text-shadow 0.5s linear;
  35. -moz-transition: text-shadow 0.5s linear;
  36. -ms-transition: text-shadow 0.5s linear;
  37. -o-transition: text-shadow 0.5s linear;
  38. transition: text-shadow 0.5s linear;
  39. margin-right: 15px;
  40. }
  41. caption {
  42. font-weight: bold;
  43. }
  44. h3.version {
  45. font-size: 90%;
  46. text-align: center;
  47. }
  48. a {
  49. color: #3D578C;
  50. font-weight: normal;
  51. text-decoration: none;
  52. }
  53. .contents a:visited {
  54. color: #4665A2;
  55. }
  56. a:hover {
  57. text-decoration: underline;
  58. }
  59. a.el {
  60. font-weight: bold;
  61. }
  62. a.code, a.code:visited, a.line, a.line:visited {
  63. color: #4665A2;
  64. }
  65. a.codeRef, a.codeRef:visited, a.lineRef, a.lineRef:visited {
  66. color: #4665A2;
  67. }
  68. pre.fragment {
  69. border: 1px solid #C4CFE5;
  70. background-color: #FBFCFD;
  71. padding: 4px 6px;
  72. margin: 4px 8px 4px 2px;
  73. overflow: auto;
  74. word-wrap: break-word;
  75. font-size: 9pt;
  76. line-height: 125%;
  77. font-family: monospace, fixed;
  78. font-size: 105%;
  79. }
  80. div.fragment {
  81. padding: 0px;
  82. margin: 4px 8px 4px 2px;
  83. background-color: #FBFCFD;
  84. border: 1px solid #C4CFE5;
  85. }
  86. div.line {
  87. font-family: monospace, fixed;
  88. font-size: 13px;
  89. min-height: 13px;
  90. line-height: 1.0;
  91. text-wrap: unrestricted;
  92. white-space: -moz-pre-wrap; /* Moz */
  93. white-space: -pre-wrap; /* Opera 4-6 */
  94. white-space: -o-pre-wrap; /* Opera 7 */
  95. white-space: pre-wrap; /* CSS3 */
  96. word-wrap: break-word; /* IE 5.5+ */
  97. text-indent: -53px;
  98. padding-left: 53px;
  99. padding-bottom: 0px;
  100. margin: 0px;
  101. -webkit-transition-property: background-color, box-shadow;
  102. -webkit-transition-duration: 0.5s;
  103. -moz-transition-property: background-color, box-shadow;
  104. -moz-transition-duration: 0.5s;
  105. -ms-transition-property: background-color, box-shadow;
  106. -ms-transition-duration: 0.5s;
  107. -o-transition-property: background-color, box-shadow;
  108. -o-transition-duration: 0.5s;
  109. transition-property: background-color, box-shadow;
  110. transition-duration: 0.5s;
  111. }
  112. div.contents {
  113. margin-top: 10px;
  114. margin-left: 12px;
  115. margin-right: 8px;
  116. }
  117. div.center {
  118. text-align: center;
  119. margin-top: 0px;
  120. margin-bottom: 0px;
  121. padding: 0px;
  122. }
  123. div.center img {
  124. border: 0px;
  125. }
  126. span.keyword {
  127. color: #008000
  128. }
  129. span.keywordtype {
  130. color: #604020
  131. }
  132. span.keywordflow {
  133. color: #e08000
  134. }
  135. span.comment {
  136. color: #800000
  137. }
  138. span.preprocessor {
  139. color: #806020
  140. }
  141. span.stringliteral {
  142. color: #002080
  143. }
  144. span.charliteral {
  145. color: #008080
  146. }
  147. blockquote {
  148. background-color: #F7F8FB;
  149. border-left: 2px solid #9CAFD4;
  150. margin: 0 24px 0 4px;
  151. padding: 0 12px 0 16px;
  152. }
  153. hr {
  154. height: 0px;
  155. border: none;
  156. border-top: 1px solid #4A6AAA;
  157. }
  158. address {
  159. font-style: normal;
  160. color: #2A3D61;
  161. }
  162. div.header {
  163. background-image:url('nav_h.png');
  164. background-repeat:repeat-x;
  165. background-color: #F9FAFC;
  166. margin: 0px;
  167. border-bottom: 1px solid #C4CFE5;
  168. }
  169. div.headertitle {
  170. padding: 5px 5px 5px 10px;
  171. }
  172. .image {
  173. text-align: center;
  174. }
  175. .caption {
  176. font-weight: bold;
  177. }
  178. div.zoom {
  179. border: 1px solid #90A5CE;
  180. }
  181. tr.heading h2 {
  182. margin-top: 12px;
  183. margin-bottom: 4px;
  184. }
  185. </style>
  186. </head>
  187. <div id="top"><!-- do not remove this div, it is closed by doxygen! -->
  188. <!--END TITLEAREA-->
  189. <!-- end header part -->
  190. <!-- Generated by Doxygen 1.8.13 -->
  191. </div><!-- top -->
  192. <div class="header">
  193. <div class="headertitle">
  194. <div class="title">Tutorial 17: Helloworld mobile for WinCE 6. DEPRECATED </div> </div>
  195. </div><!--header-->
  196. <div class="contents">
  197. <div class="textblock"><div class="image">
  198. <img src="../../media/example_screenshots/017shot.jpg" alt="017shot.jpg"/>
  199. </div>
  200. This was Example 017 Helloworld mobile for WinCE 6. But WinCE6 support has been removed for Irrlicht 1.9. If you still need that please use Irrlicht 1.8 or svn revision 5045 which was the last one to include it.</p>
  201. <p>Sources still kept for now as it compiles on other platform too. And we might use this example again once we support Windows RT. </p><div class="fragment"><div class="line"><span class="preprocessor">#include &lt;irrlicht.h&gt;</span></div><div class="line"></div><div class="line"><span class="preprocessor">#if defined ( _IRR_WINDOWS_ )</span></div><div class="line"><span class="preprocessor"> #include &lt;windows.h&gt;</span></div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"><span class="keyword">using namespace </span>irr;</div><div class="line"><span class="keyword">using namespace </span>core;</div><div class="line"><span class="keyword">using namespace </span>scene;</div><div class="line"><span class="keyword">using namespace </span>video;</div><div class="line"><span class="keyword">using namespace </span>io;</div><div class="line"><span class="keyword">using namespace </span>gui;</div><div class="line"></div><div class="line"><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span></div><div class="line"></div><div class="line"><span class="keyword">class </span>EventReceiver_basic : <span class="keyword">public</span> IEventReceiver</div><div class="line">{</div><div class="line"><span class="keyword">private</span>:</div><div class="line"> IrrlichtDevice *Device;</div><div class="line"><span class="keyword">public</span>:</div><div class="line"> EventReceiver_basic ( IrrlichtDevice *device ): Device ( device ) {}</div><div class="line"></div><div class="line"> <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (event.EventType == EET_GUI_EVENT)</div><div class="line"> {</div><div class="line"> s32 <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();</div><div class="line"></div><div class="line"> <span class="keywordflow">switch</span>(event.GUIEvent.EventType)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> EGET_BUTTON_CLICKED:</div><div class="line"> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 2)</div><div class="line"> {</div><div class="line"> Device-&gt;closeDevice();</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> } <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"> }</div><div class="line">};</div><div class="line"></div><div class="line"><span class="keyword">class </span>CSampleSceneNode : <span class="keyword">public</span> ISceneNode</div><div class="line">{</div><div class="line"> aabbox3d&lt;f32&gt; Box;</div><div class="line"> S3DVertex Vertices[4];</div><div class="line"> SMaterial Material;</div><div class="line"><span class="keyword">public</span>:</div><div class="line"></div><div class="line"> CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 <span class="keywordtype">id</span>)</div><div class="line"> : ISceneNode(parent, mgr, id)</div><div class="line"> {</div><div class="line"> Material.Wireframe = <span class="keyword">false</span>;</div><div class="line"> Material.Lighting = <span class="keyword">false</span>;</div><div class="line"></div><div class="line"> Vertices[0] = S3DVertex(0,0,10, 1,1,0, SColor(255,0,255,255), 0, 1);</div><div class="line"> Vertices[1] = S3DVertex(10,0,-10, 1,0,0, SColor(255,255,0,255), 1, 1);</div><div class="line"> Vertices[2] = S3DVertex(0,20,0, 0,1,1, SColor(255,255,255,0), 1, 0);</div><div class="line"> Vertices[3] = S3DVertex(-10,0,-10, 0,0,1, SColor(255,0,255,0), 0, 0);</div><div class="line"> Box.reset(Vertices[0].Pos);</div><div class="line"> <span class="keywordflow">for</span> (s32 i=1; i&lt;4; ++i)</div><div class="line"> Box.addInternalPoint(Vertices[i].Pos);</div><div class="line"> }</div><div class="line"> <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRegisterSceneNode()</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (IsVisible)</div><div class="line"> SceneManager-&gt;registerNodeForRendering(<span class="keyword">this</span>);</div><div class="line"></div><div class="line"> ISceneNode::OnRegisterSceneNode();</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keyword">virtual</span> <span class="keywordtype">void</span> render()</div><div class="line"> {</div><div class="line"> u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 };</div><div class="line"> IVideoDriver* driver = SceneManager-&gt;getVideoDriver();</div><div class="line"></div><div class="line"> driver-&gt;setMaterial(Material);</div><div class="line"> driver-&gt;setTransform(ETS_WORLD, AbsoluteTransformation);</div><div class="line"> driver-&gt;drawIndexedTriangleList(&amp;Vertices[0], 4, &amp;indices[0], 4);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keyword">virtual</span> <span class="keyword">const</span> aabbox3d&lt;f32&gt;&amp; getBoundingBox()<span class="keyword"> const</span></div><div class="line"><span class="keyword"> </span>{</div><div class="line"> <span class="keywordflow">return</span> Box;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keyword">virtual</span> u32 getMaterialCount()</div><div class="line"> {</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keyword">virtual</span> SMaterial&amp; getMaterial(u32 i)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">return</span> Material;</div><div class="line"> }</div><div class="line">};</div></div><!-- fragment --><p> ! Startup a Windows Mobile Device </p><div class="fragment"><div class="line">IrrlichtDevice *startup()</div><div class="line">{</div><div class="line"> <span class="comment">// both software and burnings video can be used</span></div><div class="line"> E_DRIVER_TYPE driverType = EDT_SOFTWARE; <span class="comment">// EDT_BURNINGSVIDEO;</span></div><div class="line"></div><div class="line"> <span class="comment">// create device</span></div><div class="line"> IrrlichtDevice *device = 0;</div><div class="line"></div><div class="line"> <span class="comment">// Use window mode on PC</span></div><div class="line"> device = createDevice(driverType, dimension2d&lt;u32&gt;(240, 320), 16, <span class="keyword">false</span> );</div><div class="line"> <span class="keywordflow">if</span> ( 0 == device )</div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line"></div><div class="line"> IVideoDriver* driver = device-&gt;getVideoDriver();</div><div class="line"> ISceneManager* smgr = device-&gt;getSceneManager();</div><div class="line"> IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();</div><div class="line"></div><div class="line"> <span class="comment">// set the filesystem relative to the executable</span></div><div class="line"><span class="preprocessor">#if defined (_IRR_WINDOWS_)</span></div><div class="line"> {</div><div class="line"> <span class="keywordtype">wchar_t</span> buf[255];</div><div class="line"> GetModuleFileNameW ( 0, buf, 255 );</div><div class="line"></div><div class="line"> io::path base = buf;</div><div class="line"> base = base.subString ( 0, base.findLast ( <span class="charliteral">&#39;\\&#39;</span> ) + 1 );</div><div class="line"> device-&gt;getFileSystem()-&gt;addFileArchive ( base );</div><div class="line"> }</div><div class="line"><span class="preprocessor">#endif</span></div><div class="line"></div><div class="line"> IGUIStaticText *text = guienv-&gt;addStaticText(L<span class="stringliteral">&quot;FPS: 25&quot;</span>,</div><div class="line"> rect&lt;s32&gt;(140,15,200,30), <span class="keyword">false</span>, <span class="keyword">false</span>, 0, 100 );</div><div class="line"></div><div class="line"> guienv-&gt;addButton(core::rect&lt;int&gt;(200,10,238,30), 0, 2, L<span class="stringliteral">&quot;Quit&quot;</span>);</div><div class="line"></div><div class="line"> <span class="comment">// add irrlicht logo</span></div><div class="line"> guienv-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlichtlogo3.png&quot;</span>),</div><div class="line"> core::position2d&lt;s32&gt;(0,-2));</div><div class="line"> <span class="keywordflow">return</span> device;</div><div class="line">}</div></div><!-- fragment --><p> ! </p><div class="fragment"><div class="line"><span class="keywordtype">int</span> run ( IrrlichtDevice *device )</div><div class="line">{</div><div class="line"> <span class="keywordflow">while</span>(device-&gt;run())</div><div class="line"> <span class="keywordflow">if</span> (device-&gt;isWindowActive())</div><div class="line"> {</div><div class="line"> device-&gt;getVideoDriver()-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, SColor(0,100,100,100));</div><div class="line"> device-&gt;getSceneManager()-&gt;drawAll();</div><div class="line"> device-&gt;getGUIEnvironment()-&gt;drawAll();</div><div class="line"> device-&gt;getVideoDriver()-&gt;endScene ();</div><div class="line"></div><div class="line"> IGUIElement *stat = device-&gt;getGUIEnvironment()-&gt;</div><div class="line"> getRootGUIElement()-&gt;getElementFromId ( 100 );</div><div class="line"> <span class="keywordflow">if</span> ( stat )</div><div class="line"> {</div><div class="line"> stringw str = L<span class="stringliteral">&quot;FPS: &quot;</span>;</div><div class="line"> str += (s32)device-&gt;getVideoDriver()-&gt;getFPS();</div><div class="line"></div><div class="line"> stat-&gt;setText ( str.c_str() );</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> device-&gt;drop();</div><div class="line"> <span class="keywordflow">return</span> 0;</div><div class="line">}</div></div><!-- fragment --><p> ! </p><div class="fragment"><div class="line"><span class="keywordtype">int</span> example_customscenenode()</div><div class="line">{</div><div class="line"> <span class="comment">// create device</span></div><div class="line"> IrrlichtDevice *device = startup();</div><div class="line"> <span class="keywordflow">if</span> (device == 0)</div><div class="line"> <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span></div><div class="line"></div><div class="line"> <span class="comment">// create engine and camera</span></div><div class="line"> EventReceiver_basic receiver(device);</div><div class="line"> device-&gt;setEventReceiver(&amp;receiver);</div><div class="line"></div><div class="line"> IVideoDriver* driver = device-&gt;getVideoDriver();</div><div class="line"> ISceneManager* smgr = device-&gt;getSceneManager();</div><div class="line"> IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();</div><div class="line"></div><div class="line"></div><div class="line"> smgr-&gt;addCameraSceneNode(0, vector3df(0,-40,0), vector3df(0,0,0));</div><div class="line"></div><div class="line"> CSampleSceneNode *myNode =</div><div class="line"> <span class="keyword">new</span> CSampleSceneNode(smgr-&gt;getRootSceneNode(), smgr, 666);</div><div class="line"></div><div class="line"> ISceneNodeAnimator* anim =</div><div class="line"> smgr-&gt;createRotationAnimator(vector3df(0.8f, 0, 0.8f));</div><div class="line"></div><div class="line"> <span class="keywordflow">if</span>(anim)</div><div class="line"> {</div><div class="line"> myNode-&gt;addAnimator(anim);</div><div class="line"> anim-&gt;drop();</div><div class="line"> anim = 0; <span class="comment">// As I shouldn&#39;t refer to it again, ensure that I can&#39;t</span></div><div class="line"> }</div><div class="line"></div><div class="line"> myNode-&gt;drop();</div><div class="line"> myNode = 0; <span class="comment">// As I shouldn&#39;t refer to it again, ensure that I can&#39;t</span></div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> run ( device );</div><div class="line">}</div><div class="line"></div><div class="line"><span class="keyword">class </span>EventReceiver_terrain : <span class="keyword">public</span> IEventReceiver</div><div class="line">{</div><div class="line"><span class="keyword">public</span>:</div><div class="line"></div><div class="line"> EventReceiver_terrain(IrrlichtDevice *device, scene::ISceneNode* terrain, scene::ISceneNode* skybox, scene::ISceneNode* skydome) :</div><div class="line"> Device ( device ), Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true)</div><div class="line"> {</div><div class="line"> Skybox-&gt;setVisible(<span class="keyword">true</span>);</div><div class="line"> Skydome-&gt;setVisible(<span class="keyword">false</span>);</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">if</span> (event.EventType == EET_GUI_EVENT)</div><div class="line"> {</div><div class="line"> s32 <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();</div><div class="line"></div><div class="line"> <span class="keywordflow">switch</span>(event.GUIEvent.EventType)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> EGET_BUTTON_CLICKED:</div><div class="line"> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 2)</div><div class="line"> {</div><div class="line"> Device-&gt;closeDevice();</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> } <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="comment">// check if user presses the key &#39;W&#39; or &#39;D&#39;</span></div><div class="line"> <span class="keywordflow">if</span> (event.EventType == irr::EET_KEY_INPUT_EVENT &amp;&amp; !event.KeyInput.PressedDown)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">switch</span> (event.KeyInput.Key)</div><div class="line"> {</div><div class="line"> <span class="keywordflow">case</span> irr::KEY_KEY_W: <span class="comment">// switch wire frame mode</span></div><div class="line"> Terrain-&gt;setMaterialFlag(video::EMF_WIREFRAME,</div><div class="line"> !Terrain-&gt;getMaterial(0).Wireframe);</div><div class="line"> Terrain-&gt;setMaterialFlag(video::EMF_POINTCLOUD, <span class="keyword">false</span>);</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> <span class="keywordflow">case</span> irr::KEY_KEY_P: <span class="comment">// switch wire frame mode</span></div><div class="line"> Terrain-&gt;setMaterialFlag(video::EMF_POINTCLOUD,</div><div class="line"> !Terrain-&gt;getMaterial(0).PointCloud);</div><div class="line"> Terrain-&gt;setMaterialFlag(video::EMF_WIREFRAME, <span class="keyword">false</span>);</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> <span class="keywordflow">case</span> irr::KEY_KEY_D: <span class="comment">// toggle detail map</span></div><div class="line"> Terrain-&gt;setMaterialType(</div><div class="line"> Terrain-&gt;getMaterial(0).MaterialType == video::EMT_SOLID ?</div><div class="line"> video::EMT_DETAIL_MAP : video::EMT_SOLID);</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> <span class="keywordflow">case</span> irr::KEY_KEY_S: <span class="comment">// toggle skies</span></div><div class="line"> showBox=!showBox;</div><div class="line"> Skybox-&gt;setVisible(showBox);</div><div class="line"> Skydome-&gt;setVisible(!showBox);</div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">true</span>;</div><div class="line"> <span class="keywordflow">default</span>:</div><div class="line"> <span class="keywordflow">break</span>;</div><div class="line"> }</div><div class="line"> }</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> <span class="keyword">false</span>;</div><div class="line"> }</div><div class="line"></div><div class="line"><span class="keyword">private</span>:</div><div class="line"> IrrlichtDevice *Device;</div><div class="line"> scene::ISceneNode* Terrain;</div><div class="line"> scene::ISceneNode* Skybox;</div><div class="line"> scene::ISceneNode* Skydome;</div><div class="line"> <span class="keywordtype">bool</span> showBox;</div><div class="line">};</div></div><!-- fragment --><p> The start of the main function starts like in most other example. We ask the user for the desired renderer and start it up. This time with the advanced parameter handling. </p><div class="fragment"><div class="line"><span class="keywordtype">int</span> example_terrain()</div><div class="line">{</div><div class="line"> <span class="comment">// create device</span></div><div class="line"> IrrlichtDevice *device = startup();</div><div class="line"> <span class="keywordflow">if</span> (device == 0)</div><div class="line"> <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span></div></div><!-- fragment --><p> First, we add standard stuff to the scene: A nice irrlicht engine logo, a small help text, a user controlled camera, and we disable the mouse cursor. </p><div class="fragment"><div class="line">video::IVideoDriver* driver = device-&gt;getVideoDriver();</div><div class="line">scene::ISceneManager* smgr = device-&gt;getSceneManager();</div><div class="line">gui::IGUIEnvironment* env = device-&gt;getGUIEnvironment();</div><div class="line"></div><div class="line"></div><div class="line"><span class="comment">//set other font</span></div><div class="line"><span class="comment">//env-&gt;getSkin()-&gt;setFont(env-&gt;getFont(&quot;../../media/fontlucida.png&quot;));</span></div><div class="line"></div><div class="line"><span class="comment">// add some help text</span></div><div class="line">env-&gt;addStaticText(</div><div class="line"> L<span class="stringliteral">&quot;Press &#39;W&#39; to change wireframe mode\nPress &#39;D&#39; to toggle detail map\nPress &#39;S&#39; to toggle skybox/skydome&quot;</span>,</div><div class="line"> core::rect&lt;s32&gt;(5,250,235,320), <span class="keyword">true</span>, <span class="keyword">true</span>, 0, -1, <span class="keyword">true</span>);</div><div class="line"></div><div class="line"><span class="comment">// add camera</span></div><div class="line">scene::ICameraSceneNode* camera =</div><div class="line"> smgr-&gt;addCameraSceneNodeFPS(0,100.0f,1.2f);</div><div class="line"></div><div class="line">camera-&gt;setPosition(core::vector3df(2700*2,255*2,2600*2));</div><div class="line">camera-&gt;setTarget(core::vector3df(2397*2,343*2,2700*2));</div><div class="line">camera-&gt;setFarValue(42000.0f);</div><div class="line"></div><div class="line"><span class="comment">// disable mouse cursor</span></div><div class="line">device-&gt;getCursorControl()-&gt;setVisible(<span class="keyword">false</span>);</div></div><!-- fragment --><p> Here comes the terrain renderer scene node: We add it just like any other scene node to the scene using ISceneManager::addTerrainSceneNode(). The only parameter we use is a file name to the heightmap we use. A heightmap is simply a gray scale texture. The terrain renderer loads it and creates the 3D terrain from it.</p>
  202. <p>To make the terrain look more big, we change the scale factor of it to (40, 4.4, 40). Because we don't have any dynamic lights in the scene, we switch off the lighting, and we set the file terrain-texture.jpg as texture for the terrain and detailmap3.jpg as second texture, called detail map. At last, we set the scale values for the texture: The first texture will be repeated only one time over the whole terrain, and the second one (detail map) 20 times. </p><div class="fragment"><div class="line"><span class="comment">// add terrain scene node</span></div><div class="line">scene::ITerrainSceneNode* terrain = smgr-&gt;addTerrainSceneNode(</div><div class="line"> <span class="stringliteral">&quot;../../media/terrain-heightmap.bmp&quot;</span>,</div><div class="line"> 0, <span class="comment">// parent node</span></div><div class="line"> -1, <span class="comment">// node id</span></div><div class="line"> core::vector3df(0.f, 0.f, 0.f), <span class="comment">// position</span></div><div class="line"> core::vector3df(0.f, 0.f, 0.f), <span class="comment">// rotation</span></div><div class="line"> core::vector3df(40.f, 4.4f, 40.f), <span class="comment">// scale</span></div><div class="line"> video::SColor ( 255, 255, 255, 255 ), <span class="comment">// vertexColor</span></div><div class="line"> 5, <span class="comment">// maxLOD</span></div><div class="line"> scene::ETPS_17, <span class="comment">// patchSize</span></div><div class="line"> 4 <span class="comment">// smoothFactor</span></div><div class="line"> );</div><div class="line"></div><div class="line"><span class="keywordflow">if</span> ( terrain )</div><div class="line">{</div><div class="line"> terrain-&gt;setMaterialFlag(video::EMF_LIGHTING, <span class="keyword">false</span>);</div><div class="line"></div><div class="line"> terrain-&gt;setMaterialTexture(0,</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/terrain-texture.jpg&quot;</span>));</div><div class="line"> terrain-&gt;setMaterialTexture(1,</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/detailmap3.jpg&quot;</span>));</div><div class="line"></div><div class="line"> terrain-&gt;setMaterialType(video::EMT_DETAIL_MAP);</div><div class="line"></div><div class="line"> terrain-&gt;scaleTexture(1.0f, 20.0f);</div><div class="line"> <span class="comment">//terrain-&gt;setDebugDataVisible ( true );</span></div></div><!-- fragment --><p> To be able to do collision with the terrain, we create a triangle selector. If you want to know what triangle selectors do, just take a look into the collision tutorial. The terrain triangle selector works together with the terrain. To demonstrate this, we create a collision response animator and attach it to the camera, so that the camera will not be able to fly through the terrain. </p><div class="fragment"><div class="line"><span class="comment">// create triangle selector for the terrain</span></div><div class="line">scene::ITriangleSelector* selector</div><div class="line"> = smgr-&gt;createTerrainTriangleSelector(terrain, 0);</div><div class="line">terrain-&gt;setTriangleSelector(selector);</div><div class="line"></div><div class="line"><span class="comment">// create collision response animator and attach it to the camera</span></div><div class="line">scene::ISceneNodeAnimator* anim = smgr-&gt;createCollisionResponseAnimator(</div><div class="line"> selector, camera, core::vector3df(60,100,60),</div><div class="line"> core::vector3df(0,0,0),</div><div class="line"> core::vector3df(0,50,0));</div><div class="line">selector-&gt;drop();</div><div class="line">camera-&gt;addAnimator(anim);</div><div class="line">anim-&gt;drop();</div></div><!-- fragment --><p> If you need access to the terrain data you can also do this directly via the following code fragment. </p><div class="fragment"><div class="line"> scene::CDynamicMeshBuffer* buffer = <span class="keyword">new</span> scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT);</div><div class="line"> terrain-&gt;getMeshBufferForLOD(*buffer, 0);</div><div class="line"> video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer-&gt;getVertexBuffer().getData();</div><div class="line"> <span class="comment">// Work on data or get the IndexBuffer with a similar call.</span></div><div class="line"> buffer-&gt;drop(); <span class="comment">// When done drop the buffer again.</span></div><div class="line">}</div></div><!-- fragment --><p> To make the user be able to switch between normal and wireframe mode, we create an instance of the event receiver from above and let Irrlicht know about it. In addition, we add the skybox which we already used in lots of Irrlicht examples and a skydome, which is shown mutually exclusive with the skybox by pressing 'S'. </p><div class="fragment"><div class="line"> <span class="comment">// create skybox and skydome</span></div><div class="line"> driver-&gt;setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, <span class="keyword">false</span>);</div><div class="line"></div><div class="line"> scene::ISceneNode* skybox=smgr-&gt;addSkyBoxSceneNode(</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_up.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_dn.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_lf.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_rt.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_ft.jpg&quot;</span>),</div><div class="line"> driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_bk.jpg&quot;</span>));</div><div class="line"> scene::ISceneNode* skydome=smgr-&gt;addSkyDomeSceneNode(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/skydome.jpg&quot;</span>),16,8,0.95f,2.0f);</div><div class="line"></div><div class="line"> driver-&gt;setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, <span class="keyword">true</span>);</div><div class="line"></div><div class="line"> <span class="comment">// create event receiver</span></div><div class="line"> EventReceiver_terrain receiver( device, terrain, skybox, skydome);</div><div class="line"> device-&gt;setEventReceiver(&amp;receiver);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> run ( device );</div><div class="line">}</div></div><!-- fragment --> <div class="fragment"><div class="line"><span class="keywordtype">int</span> example_helloworld()</div><div class="line">{</div><div class="line"> <span class="comment">// create device</span></div><div class="line"> IrrlichtDevice *device = startup();</div><div class="line"> <span class="keywordflow">if</span> (device == 0)</div><div class="line"> <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span></div><div class="line"></div><div class="line"> IVideoDriver* driver = device-&gt;getVideoDriver();</div><div class="line"> ISceneManager* smgr = device-&gt;getSceneManager();</div><div class="line"> IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();</div><div class="line"></div><div class="line"> IAnimatedMesh* mesh = smgr-&gt;getMesh(<span class="stringliteral">&quot;../../media/sydney.md2&quot;</span>);</div><div class="line"> <span class="keywordflow">if</span> (!mesh)</div><div class="line"> {</div><div class="line"> device-&gt;drop();</div><div class="line"> <span class="keywordflow">return</span> 1;</div><div class="line"> }</div><div class="line"> IAnimatedMeshSceneNode* node = smgr-&gt;addAnimatedMeshSceneNode( mesh );</div></div><!-- fragment --><p> To let the mesh look a little bit nicer, we change its material. We disable lighting because we do not have a dynamic light in here, and the mesh would be totally black otherwise. Then we set the frame loop, such that the predefined STAND animation is used. And last, we apply a texture to the mesh. Without it the mesh would be drawn using only a color. </p><div class="fragment"><div class="line"><span class="keywordflow">if</span> (node)</div><div class="line">{</div><div class="line"> node-&gt;setMaterialFlag(EMF_LIGHTING, <span class="keyword">false</span>);</div><div class="line"> node-&gt;setMD2Animation(scene::EMAT_STAND);</div><div class="line"> node-&gt;setMaterialTexture( 0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/sydney.bmp&quot;</span>) );</div><div class="line">}</div></div><!-- fragment --><p> To look at the mesh, we place a camera into 3d space at the position (0, 30, -40). The camera looks from there to (0,5,0), which is approximately the place where our md2 model is. </p><div class="fragment"><div class="line"> smgr-&gt;addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));</div><div class="line"></div><div class="line"> EventReceiver_basic receiver(device);</div><div class="line"> device-&gt;setEventReceiver(&amp;receiver);</div><div class="line"></div><div class="line"> <span class="keywordflow">return</span> run ( device );</div><div class="line"></div><div class="line">}</div><div class="line"></div><div class="line"><span class="preprocessor">#if defined (_IRR_WINDOWS_)</span></div><div class="line"><span class="preprocessor"> #pragma comment(linker, &quot;/subsystem:windows /ENTRY:mainCRTStartup&quot;)</span></div><div class="line"><span class="preprocessor">#endif</span></div></div><!-- fragment --> <div class="fragment"><div class="line"><span class="keywordtype">int</span> main()</div><div class="line">{</div><div class="line"> example_helloworld ();</div><div class="line"> example_customscenenode();</div><div class="line"> <span class="comment">//example_terrain();</span></div><div class="line">}</div></div><!-- fragment --> </div></div><!-- contents -->
  203. <!-- HTML footer for doxygen 1.8.13-->
  204. <!-- start footer part -->
  205. <p>&nbsp;</p>
  206. </body>
  207. </html>