aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/doc/html/example017.html
blob: a326ebc4ee812df096603c603b5571f7219f9b49 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>Irrlicht 3D Engine: Tutorial 17: Helloworld mobile</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td>
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Irrlicht 3D Engine
   
   </div>
   
  </td>
  
  
  
   
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
   
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="dynsections.js"></script>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('example017.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">Tutorial 17: Helloworld mobile </div>  </div>
</div>
<div class="contents">
<div class="textblock"><div class="image">
<img src="017shot.jpg" alt="017shot.jpg"/>
</div>
  This example show Hello World for Windows mobile. It compiles on other platform too. The only differences between the original examples are. You need a GUI, because otherwise you can't quit the application. You need a Filesystem, which is relative based to your executable. </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include &lt;<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>&gt;</span>

<span class="preprocessor">#if defined ( _IRR_WINDOWS_ )</span>
<span class="preprocessor"></span><span class="preprocessor">    #include &lt;windows.h&gt;</span>
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
<span class="keyword">using namespace </span>irr;
<span class="keyword">using namespace </span>core;
<span class="keyword">using namespace </span>scene;
<span class="keyword">using namespace </span>video;
<span class="keyword">using namespace </span>io;
<span class="keyword">using namespace </span>gui;

<span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
<span class="preprocessor"></span>
<span class="keyword">class </span>EventReceiver_basic : <span class="keyword">public</span> <a class="code" href="classirr_1_1_i_event_receiver.html" title="Interface of an object which can receive events.">IEventReceiver</a>
{
<span class="keyword">private</span>:
    <a class="code" href="classirr_1_1_irrlicht_device.html" title="The Irrlicht device. You can create it with createDevice() or createDeviceEx().">IrrlichtDevice</a> *Device;
<span class="keyword">public</span>:
    EventReceiver_basic ( <a class="code" href="classirr_1_1_irrlicht_device.html" title="The Irrlicht device. You can create it with createDevice() or createDeviceEx().">IrrlichtDevice</a> *device ): Device ( device ) {}

    <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> <a class="code" href="structirr_1_1_s_event.html" title="SEvents hold information about an event. See irr::IEventReceiver for details on event handling...">SEvent</a>&amp; event)
    {
        <span class="keywordflow">if</span> (event.<a class="code" href="structirr_1_1_s_event.html#a8b48c016d5c20a9b0967b1ce0fb3ef15">EventType</a> == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0cae85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a>)
        {
            <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();

            <span class="keywordflow">switch</span>(event.<a class="code" href="structirr_1_1_s_event.html#a8efed75c2ae2e39c0f5208bffbe5e009">GUIEvent</a>.EventType)
            {
                <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>:
                <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 2)
                {
                    Device-&gt;closeDevice();
                    <span class="keywordflow">return</span> <span class="keyword">true</span>;
                } <span class="keywordflow">break</span>;
            }
        }

        <span class="keywordflow">return</span> <span class="keyword">false</span>;
    }
};

<span class="keyword">class </span>CSampleSceneNode : <span class="keyword">public</span> ISceneNode
{
    aabbox3d&lt;f32&gt; Box;
    S3DVertex Vertices[4];
    SMaterial Material;
<span class="keyword">public</span>:

    CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span>)
        : ISceneNode(parent, mgr, id)
    {
        Material.Wireframe = <span class="keyword">false</span>;
        Material.Lighting = <span class="keyword">false</span>;

        Vertices[0] = S3DVertex(0,0,10, 1,1,0, SColor(255,0,255,255), 0, 1);
        Vertices[1] = S3DVertex(10,0,-10, 1,0,0, SColor(255,255,0,255), 1, 1);
        Vertices[2] = S3DVertex(0,20,0, 0,1,1, SColor(255,255,255,0), 1, 0);
        Vertices[3] = S3DVertex(-10,0,-10, 0,0,1, SColor(255,0,255,0), 0, 0);
        Box.reset(Vertices[0].Pos);
        <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=1; i&lt;4; ++i)
            Box.addInternalPoint(Vertices[i].Pos);
    }
    <span class="keyword">virtual</span> <span class="keywordtype">void</span> OnRegisterSceneNode()
    {
        <span class="keywordflow">if</span> (IsVisible)
            SceneManager-&gt;registerNodeForRendering(<span class="keyword">this</span>);

        ISceneNode::OnRegisterSceneNode();
    }

    <span class="keyword">virtual</span> <span class="keywordtype">void</span> render()
    {
        <a class="code" href="namespaceirr.html#ae9f8ec82692ad3b83c21f555bfa70bcc" title="16 bit unsigned variable.">u16</a> indices[] = {   0,2,3, 2,1,3, 1,0,3, 2,0,1  };
        IVideoDriver* driver = SceneManager-&gt;getVideoDriver();

        driver-&gt;setMaterial(Material);
        driver-&gt;setTransform(<a class="code" href="namespaceirr_1_1video.html#a15b57657a320243be03ae6f66fcff43da843cf42adb3fa9caf61c9e228cf14e85" title="World transformation.">ETS_WORLD</a>, AbsoluteTransformation);
        driver-&gt;drawIndexedTriangleList(&amp;Vertices[0], 4, &amp;indices[0], 4);
    }

    <span class="keyword">virtual</span> <span class="keyword">const</span> aabbox3d&lt;f32&gt;&amp; getBoundingBox()<span class="keyword"> const</span>
<span class="keyword">    </span>{
        <span class="keywordflow">return</span> Box;
    }

    <span class="keyword">virtual</span> <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> getMaterialCount()
    {
        <span class="keywordflow">return</span> 1;
    }

    <span class="keyword">virtual</span> SMaterial&amp; getMaterial(<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i)
    {
        <span class="keywordflow">return</span> Material;
    }   
};
</pre></div><p> ! Startup a Windows Mobile Device </p>
<div class="fragment"><pre class="fragment">IrrlichtDevice *startup()
{
    <span class="comment">// both software and burnings video can be used</span>
    <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">E_DRIVER_TYPE</a> driverType = <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0a1598cd235a1a6bd052e2011b559e8995" title="The Irrlicht Engine Software renderer.">EDT_SOFTWARE</a>; <span class="comment">// EDT_BURNINGSVIDEO;</span>

    <span class="comment">// create device</span>
    IrrlichtDevice *device = 0;

<span class="preprocessor">#if defined (_IRR_USE_WINDOWS_CE_DEVICE_)</span>
<span class="preprocessor"></span>    <span class="comment">// set to standard mobile fullscreen 240x320</span>
    device = <a class="code" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice</a>(driverType, dimension2d&lt;u32&gt;(240, 320), 16, <span class="keyword">true</span> );
<span class="preprocessor">#else</span>
<span class="preprocessor"></span>    <span class="comment">// on PC. use window mode</span>
    device = <a class="code" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice</a>(driverType, dimension2d&lt;u32&gt;(240, 320), 16, <span class="keyword">false</span> );
<span class="preprocessor">#endif      </span>
<span class="preprocessor"></span>    <span class="keywordflow">if</span> ( 0 == device )
        <span class="keywordflow">return</span> 0;

    IVideoDriver* driver = device-&gt;getVideoDriver();
    ISceneManager* smgr = device-&gt;getSceneManager();
    IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();

    <span class="comment">// set the filesystem relative to the executable</span>
<span class="preprocessor">#if defined (_IRR_WINDOWS_)</span>
<span class="preprocessor"></span>    {
        <span class="keywordtype">wchar_t</span> buf[255];
        GetModuleFileNameW ( 0, buf, 255 );

        <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a> base = buf;
        base = base.subString ( 0, base.findLast ( <span class="charliteral">&#39;\\&#39;</span> ) + 1 );
        device-&gt;getFileSystem()-&gt;addFileArchive ( base );
    }
<span class="preprocessor">#endif</span>
<span class="preprocessor"></span>
    IGUIStaticText *text = guienv-&gt;addStaticText(L<span class="stringliteral">&quot;FPS: 25&quot;</span>,
        rect&lt;s32&gt;(140,15,200,30), <span class="keyword">false</span>, <span class="keyword">false</span>, 0, 100 );

    guienv-&gt;addButton(core::rect&lt;int&gt;(200,10,238,30), 0, 2, L<span class="stringliteral">&quot;Quit&quot;</span>);

    <span class="comment">// add irrlicht logo</span>
    guienv-&gt;addImage(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlichtlogo3.png&quot;</span>),
                    core::position2d&lt;s32&gt;(0,-2));
    <span class="keywordflow">return</span> device;
}
</pre></div><p> ! </p>
<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> run ( IrrlichtDevice *device )
{
    <span class="keywordflow">while</span>(device-&gt;run())
    <span class="keywordflow">if</span> (device-&gt;isWindowActive())
    {
        device-&gt;getVideoDriver()-&gt;beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, SColor(0,100,100,100));
        device-&gt;getSceneManager()-&gt;drawAll();
        device-&gt;getGUIEnvironment()-&gt;drawAll();
        device-&gt;getVideoDriver()-&gt;endScene ();

        IGUIElement *stat = device-&gt;getGUIEnvironment()-&gt;
            getRootGUIElement()-&gt;getElementFromId ( 100 );
        <span class="keywordflow">if</span> ( stat )
        {
            <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">stringw</a> str = L<span class="stringliteral">&quot;FPS: &quot;</span>;
            str += (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)device-&gt;getVideoDriver()-&gt;getFPS();

            stat-&gt;setText ( str.c_str() );
        }
    }

    device-&gt;drop();
    <span class="keywordflow">return</span> 0;
}
</pre></div><p> ! </p>
<div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> example_customscenenode()
{
    <span class="comment">// create device</span>
    IrrlichtDevice *device = startup();
    <span class="keywordflow">if</span> (device == 0)
        <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>

    <span class="comment">// create engine and camera</span>
    EventReceiver_basic receiver(device);
    device-&gt;setEventReceiver(&amp;receiver);
    
    IVideoDriver* driver = device-&gt;getVideoDriver();
    ISceneManager* smgr = device-&gt;getSceneManager();
    IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();


    smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,-40,0), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,0,0));

    CSampleSceneNode *myNode = 
        <span class="keyword">new</span> CSampleSceneNode(smgr-&gt;getRootSceneNode(), smgr, 666);

    ISceneNodeAnimator* anim = 
        smgr-&gt;createRotationAnimator(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0.8f, 0, 0.8f));

    <span class="keywordflow">if</span>(anim)
    {
        myNode-&gt;addAnimator(anim);
        anim-&gt;drop();
        anim = 0; <span class="comment">// As I shouldn&#39;t refer to it again, ensure that I can&#39;t</span>
    }

    myNode-&gt;drop();
    myNode = 0; <span class="comment">// As I shouldn&#39;t refer to it again, ensure that I can&#39;t</span>

    <span class="keywordflow">return</span> run ( device );
}

<span class="keyword">class </span>EventReceiver_terrain : <span class="keyword">public</span> IEventReceiver
{
<span class="keyword">public</span>:

    EventReceiver_terrain(IrrlichtDevice *device, scene::ISceneNode* terrain, scene::ISceneNode* skybox, scene::ISceneNode* skydome) :
        Device ( device ), Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true)
    {
        Skybox-&gt;setVisible(<span class="keyword">true</span>);
        Skydome-&gt;setVisible(<span class="keyword">false</span>);
    }

    <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent&amp; event)
    {
        <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0cae85bb44dd09a29c879d64a05047fc1d2" title="An event of the graphical user interface.">EET_GUI_EVENT</a>)
        {
            <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = <span class="keyword">event</span>.GUIEvent.Caller-&gt;getID();

            <span class="keywordflow">switch</span>(event.GUIEvent.EventType)
            {
                <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>:
                <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == 2)
                {
                    Device-&gt;closeDevice();
                    <span class="keywordflow">return</span> <span class="keyword">true</span>;
                } <span class="keywordflow">break</span>;
            }
        }

        <span class="comment">// check if user presses the key &#39;W&#39; or &#39;D&#39;</span>
        <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> &amp;&amp; !event.KeyInput.PressedDown)
        {
            <span class="keywordflow">switch</span> (event.KeyInput.Key)
            {
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ae559e3169016a3180c45c2828f391af2">irr::KEY_KEY_W</a>: <span class="comment">// switch wire frame mode</span>
                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3abc620823efed8d6bdbd46c8a0180893a" title="Draw as wireframe or filled triangles? Default: false.">video::EMF_WIREFRAME</a>,
                        !Terrain-&gt;getMaterial(0).Wireframe);
                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3726bbddc57e6b37b05481b640eefb07" title="Draw as point cloud or filled triangles? Default: false.">video::EMF_POINTCLOUD</a>, <span class="keyword">false</span>);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a52e3c10f6d5c2bc0bd446273879f9519">irr::KEY_KEY_P</a>: <span class="comment">// switch wire frame mode</span>
                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3726bbddc57e6b37b05481b640eefb07" title="Draw as point cloud or filled triangles? Default: false.">video::EMF_POINTCLOUD</a>,
                        !Terrain-&gt;getMaterial(0).PointCloud);
                Terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3abc620823efed8d6bdbd46c8a0180893a" title="Draw as wireframe or filled triangles? Default: false.">video::EMF_WIREFRAME</a>, <span class="keyword">false</span>);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ad20e7e220103e611752b90edeb6cbc9d">irr::KEY_KEY_D</a>: <span class="comment">// toggle detail map</span>
                Terrain-&gt;setMaterialType(
                    Terrain-&gt;getMaterial(0).MaterialType == <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a> ?
                    <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a065af4f8daeb15f81bfe0417a3f231b1" title="Detail mapped material.">video::EMT_DETAIL_MAP</a> : <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ae52bafc112fc6c52f6b49cea42fa246e">irr::KEY_KEY_S</a>: <span class="comment">// toggle skies</span>
                showBox=!showBox;
                Skybox-&gt;setVisible(showBox);
                Skydome-&gt;setVisible(!showBox);
                <span class="keywordflow">return</span> <span class="keyword">true</span>;
            <span class="keywordflow">default</span>:
                <span class="keywordflow">break</span>;
            }
        }

        <span class="keywordflow">return</span> <span class="keyword">false</span>;
    }

<span class="keyword">private</span>:
    IrrlichtDevice *Device;
    scene::ISceneNode* Terrain;
    scene::ISceneNode* Skybox;
    scene::ISceneNode* Skydome;
    <span class="keywordtype">bool</span> showBox;
};
</pre></div><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"><pre class="fragment"><span class="keywordtype">int</span> example_terrain()
{
    <span class="comment">// create device</span>
    IrrlichtDevice *device = startup();
    <span class="keywordflow">if</span> (device == 0)
        <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
</pre></div><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"><pre class="fragment">    video::IVideoDriver* driver = device-&gt;getVideoDriver();
    scene::ISceneManager* smgr = device-&gt;getSceneManager();
    gui::IGUIEnvironment* env = device-&gt;getGUIEnvironment();


    <span class="comment">//set other font</span>
    <span class="comment">//env-&gt;getSkin()-&gt;setFont(env-&gt;getFont(&quot;../../media/fontlucida.png&quot;));</span>

    <span class="comment">// add some help text</span>
    env-&gt;<a class="code" href="classirr_1_1gui_1_1_i_g_u_i_environment.html#adb56652b23932a391b08f710a9546ef3" title="Adds a static text.">addStaticText</a>(
        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>,
        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>);

    <span class="comment">// add camera</span>
    scene::ICameraSceneNode* camera =
        smgr-&gt;addCameraSceneNodeFPS(0,100.0f,1.2f);

    camera-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(2700*2,255*2,2600*2));
    camera-&gt;setTarget(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(2397*2,343*2,2700*2));
    camera-&gt;setFarValue(42000.0f);

    <span class="comment">// disable mouse cursor</span>
    device-&gt;getCursorControl()-&gt;setVisible(<span class="keyword">false</span>);
</pre></div><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>
<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"><pre class="fragment">    <span class="comment">// add terrain scene node</span>
    scene::ITerrainSceneNode* terrain = smgr-&gt;addTerrainSceneNode(
        <span class="stringliteral">&quot;../../media/terrain-heightmap.bmp&quot;</span>,
        0,                  <span class="comment">// parent node</span>
        -1,                 <span class="comment">// node id</span>
        <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.f, 0.f, 0.f),     <span class="comment">// position</span>
        <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.f, 0.f, 0.f),     <span class="comment">// rotation</span>
        <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(40.f, 4.4f, 40.f),  <span class="comment">// scale</span>
        video::SColor ( 255, 255, 255, 255 ),   <span class="comment">// vertexColor</span>
        5,                  <span class="comment">// maxLOD</span>
        <a class="code" href="namespaceirr_1_1scene.html#a6de1eb2d024f82b5b1af499d61523044abe94d6195f435b8e08a38269e63af72e" title="patch size of 17, at most, use 5 levels of detail with this patch size.">scene::ETPS_17</a>,             <span class="comment">// patchSize</span>
        4                   <span class="comment">// smoothFactor</span>
        );

    <span class="keywordflow">if</span> ( terrain )
    {
        terrain-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, <span class="keyword">false</span>);

        terrain-&gt;setMaterialTexture(0,
                driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/terrain-texture.jpg&quot;</span>));
        terrain-&gt;setMaterialTexture(1,
                driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/detailmap3.jpg&quot;</span>));
        
        terrain-&gt;setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a065af4f8daeb15f81bfe0417a3f231b1" title="Detail mapped material.">video::EMT_DETAIL_MAP</a>);

        terrain-&gt;scaleTexture(1.0f, 20.0f);
        <span class="comment">//terrain-&gt;setDebugDataVisible ( true );</span>
</pre></div><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"><pre class="fragment">        <span class="comment">// create triangle selector for the terrain </span>
        scene::ITriangleSelector* selector
            = smgr-&gt;createTerrainTriangleSelector(terrain, 0);
        terrain-&gt;setTriangleSelector(selector);

        <span class="comment">// create collision response animator and attach it to the camera</span>
        scene::ISceneNodeAnimator* anim = smgr-&gt;createCollisionResponseAnimator(
            selector, camera, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(60,100,60),
            <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0),
            <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,50,0));
        selector-&gt;drop();
        camera-&gt;addAnimator(anim);
        anim-&gt;drop();
</pre></div><p> If you need access to the terrain data you can also do this directly via the following code fragment. </p>
<div class="fragment"><pre class="fragment">        scene::CDynamicMeshBuffer* buffer = <span class="keyword">new</span> scene::CDynamicMeshBuffer(<a class="code" href="namespaceirr_1_1video.html#a0e3b59e025e0d0db0ed2ee0ce904deaca7b5127a706ee33eb4385d702da007016" title="Vertex with two texture coordinates, video::S3DVertex2TCoords.">video::EVT_2TCOORDS</a>, <a class="code" href="namespaceirr_1_1video.html#af152a1edea2579f0517e0049525acb55a1c79610ea1191e124887efa16626f299">video::EIT_16BIT</a>);
        terrain-&gt;getMeshBufferForLOD(*buffer, 0);
        video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer-&gt;getVertexBuffer().getData();
        <span class="comment">// Work on data or get the IndexBuffer with a similar call.</span>
        buffer-&gt;drop(); <span class="comment">// When done drop the buffer again.</span>
    }
</pre></div><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"><pre class="fragment">    <span class="comment">// create skybox and skydome</span>
    driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa288b302e9d4faaba80c7796c7bc1682c">video::ETCF_CREATE_MIP_MAPS</a>, <span class="keyword">false</span>);

    scene::ISceneNode* skybox=smgr-&gt;addSkyBoxSceneNode(
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_up.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_dn.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_lf.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_rt.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_ft.jpg&quot;</span>),
        driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/irrlicht2_bk.jpg&quot;</span>));
    scene::ISceneNode* skydome=smgr-&gt;addSkyDomeSceneNode(driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/skydome.jpg&quot;</span>),16,8,0.95f,2.0f);

    driver-&gt;setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa288b302e9d4faaba80c7796c7bc1682c">video::ETCF_CREATE_MIP_MAPS</a>, <span class="keyword">true</span>);

    <span class="comment">// create event receiver</span>
    EventReceiver_terrain receiver( device, terrain, skybox, skydome);
    device-&gt;setEventReceiver(&amp;receiver);

    <span class="keywordflow">return</span> run ( device );
}
</pre></div><div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> example_helloworld()
{
    <span class="comment">// create device</span>
    IrrlichtDevice *device = startup();
    <span class="keywordflow">if</span> (device == 0)
        <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>

    IVideoDriver* driver = device-&gt;getVideoDriver();
    ISceneManager* smgr = device-&gt;getSceneManager();
    IGUIEnvironment* guienv = device-&gt;getGUIEnvironment();

    IAnimatedMesh* mesh = smgr-&gt;getMesh(<span class="stringliteral">&quot;../../media/sydney.md2&quot;</span>);
    <span class="keywordflow">if</span> (!mesh)
    {
        device-&gt;drop();
        <span class="keywordflow">return</span> 1;
    }
    IAnimatedMeshSceneNode* node = smgr-&gt;addAnimatedMeshSceneNode( mesh );
</pre></div><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"><pre class="fragment">    <span class="keywordflow">if</span> (node)
    {
        node-&gt;setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">EMF_LIGHTING</a>, <span class="keyword">false</span>);
        node-&gt;setMD2Animation(<a class="code" href="namespaceirr_1_1scene.html#a08d4a84966e1d2886d0d57e4acbb4f19a35893ae58423c41dace23ad13e262e2c">scene::EMAT_STAND</a>);
        node-&gt;setMaterialTexture( 0, driver-&gt;getTexture(<span class="stringliteral">&quot;../../media/sydney.bmp&quot;</span>) );
    }
</pre></div><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"><pre class="fragment">    smgr-&gt;addCameraSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,30,-40), <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">vector3df</a>(0,5,0));

    EventReceiver_basic receiver(device);
    device-&gt;setEventReceiver(&amp;receiver);

    <span class="keywordflow">return</span> run ( device );

}

<span class="preprocessor">#if defined (_IRR_USE_WINDOWS_CE_DEVICE_)</span>
<span class="preprocessor"></span><span class="preprocessor">    #pragma comment(linker, &quot;/subsystem:WINDOWSCE /ENTRY:main&quot;) </span>
<span class="preprocessor"></span><span class="preprocessor">#elif defined (_IRR_WINDOWS_)</span>
<span class="preprocessor"></span><span class="preprocessor">    #pragma comment(linker, &quot;/subsystem:windows /ENTRY:mainCRTStartup&quot;)</span>
<span class="preprocessor">#endif</span>
</pre></div><div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main()
{
    example_helloworld ();
    example_customscenenode();
    <span class="comment">//example_terrain();</span>
}
</pre></div> </div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">
<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht 
Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Sun Nov 17 2013 20:18:41 for Irrlicht 3D Engine by
<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>