aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html
diff options
context:
space:
mode:
Diffstat (limited to 'src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html')
-rw-r--r--src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html
new file mode 100644
index 0000000..f3d765f
--- /dev/null
+++ b/src/others/irrlicht-1.8.1/examples/12.TerrainRendering/tutorial.html
@@ -0,0 +1,122 @@
1<html>
2<head>
3<title>Irrlicht Engine Tutorial</title>
4<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5</head>
6
7<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
8<br>
9<table width="95%" border="0" cellspacing="0" cellpadding="2" align="center">
10 <tr>
11 <td bgcolor="#666699" width="10"><b><a href="http://irrlicht.sourceforge.net" target="_blank"><img src="../../media/irrlichtlogo.jpg" width="88" height="31" border="0"></a></b></td>
12 <td bgcolor="#666699" width="100%">
13<div align="center">
14 <div align="left"><b><font color="#FFFFFF">Tutorial 12. Terrain Rendering</font></b></div>
15 </div>
16 </td>
17 </tr>
18 <tr bgcolor="#eeeeff">
19 <td height="90" colspan="2">
20 <div align="left">
21 <p> This tutorial will briefly show how to use the terrain renderer of
22 Irrlicht. It will also show the terrain renderer triangle selector to
23 be able to do collision detection with terrain.</p>
24 <p>The program which is described here will look like this:</p>
25 <p align="center"><img src="../../media/012shot.jpg" width="258" height="202"></p>
26 <p align="left"><br>
27 Note that the terrain renderer in Irrlicht is based the terrain renderer
28 by Soconne and the GeoMipMapSceneNode developed by Spinz, lots of thanks
29 go to them.</p>
30 </div>
31 </td>
32 </tr>
33</table>
34<br>
35<table width="95%" border="0" cellspacing="0" cellpadding="2" align="center">
36 <tr>
37 <td bgcolor="#666699"> <b><font color="#FFFFFF">Lets start!</font></b></td>
38 </tr>
39 <tr>
40 <td height="90" bgcolor="#eeeeff" valign="top"> <div align="left">
41 <div align="left">
42 <p> In the beginning there is nothing special. We include the needed
43 header files and create an event listener to listen if the user presses
44 the 'W' key so we can switch to wireframe mode and if he presses 'D'
45 we toggle to material between solid and detail mapped.</p>
46 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
47 <tr>
48 <td> <pre>#include &lt;irrlicht.h&gt;<br>#include &lt;iostream&gt;<br>using namespace irr;<br><br>#pragma comment(lib, &quot;Irrlicht.lib&quot;)<br><br>class MyEventReceiver : public IEventReceiver<br>{<br>public:<br> MyEventReceiver(scene::ISceneNode* terrain)<br> {<br><font color="#006600"> // store pointer to terrain so we can change its drawing mode<br></font> Terrain = terrain;<br> }<br><br> bool OnEvent(const SEvent& event)<br> {<br> <font color="#006600"> // check if user presses the key 'W' or 'D'</font><br> if (event.EventType == irr::EET_KEY_INPUT_EVENT &amp;&amp; !event.KeyInput.PressedDown)<br> {<br> switch (event.KeyInput.Key)<br> {<br> case irr::KEY_KEY_W:<font color="#006600"> // switch wire frame mode</font><br> Terrain-&gt;setMaterialFlag(video::EMF_WIREFRAME, !Terrain-&gt;getMaterial(0).Wireframe);<br> return true;<br> case irr::KEY_KEY_D:<font color="#006600"> // toggle detail map</font><br> Terrain-&gt;setMaterialType(<br> Terrain-&gt;getMaterial(0).MaterialType == video::EMT_SOLID ? <br> video::EMT_DETAIL_MAP : video::EMT_SOLID);<br> return true;<br> }<br> }<br> return false;<br> }<br><br>private:<br> scene::ISceneNode* Terrain;<br>};<br><br></pre></td>
49 </tr>
50 </table>
51 <p>The start of the main function starts like in most other example.
52 We ask the user for the desired renderer and start it up. </p>
53 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
54 <tr>
55 <td> <pre>int main()<br>{<br><font color="#006600"> // let user select driver type<br></font><br> video::E_DRIVER_TYPE driverType = video::EDT_DIRECT3D9;<br><br> printf(&quot;Please select the driver you want for this example:\n&quot;\<br> &quot; (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.5\n&quot;\<br> &quot; (d) Software Renderer\n (e) Apfelbaum Software Renderer\n&quot;\<br> &quot; (f) NullDevice\n (otherKey) exit\n\n&quot;);<br><br> char i;<br> std::cin &gt;&gt; i;<br><br> switch(i)<br> {<br> case 'a': driverType = video::EDT_DIRECT3D9;break;<br> case 'b': driverType = video::EDT_DIRECT3D8;break;<br> case 'c': driverType = video::EDT_OPENGL; break;<br> case 'd': driverType = video::EDT_SOFTWARE; break;<br> case 'e': driverType = video::EDT_BURNINGSVIDEO;break;<br> case 'f': driverType = video::EDT_NULL; break;<br> default: return 1;<br> } <br><font color="#006600"><br> // create device<br></font> IrrlichtDevice* device = createDevice(driverType, core::dimension2d&lt;s32&gt;(640, 480));<br><br> if (device == 0)<br> return 1; <font color="#006600">// could not create selected driver.</font><br></pre></td>
56 </tr>
57 </table>
58 <p> First, we add standard stuff to the scene: A nice irrlicht engine
59 logo, a small help text, a user controlled camera, and we disable
60 the mouse cursor.</p>
61 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
62 <tr>
63 <td> <pre>video::IVideoDriver* driver = device-&gt;getVideoDriver();<br>scene::ISceneManager* smgr = device-&gt;getSceneManager();<br>gui::IGUIEnvironment* env = device-&gt;getGUIEnvironment();<br><br>driver-&gt;setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);<br><br><font color="#006600">// add irrlicht logo<br></font>env-&gt;addImage(driver-&gt;getTexture(&quot;../../media/irrlichtlogoalpha.tga&quot;),<br> core::position2d&lt;s32&gt;(10,10));<br>
64<font color="#006600">// add some help text<br></font>gui::IGUIStaticText* text = env-&gt;addStaticText(<br> L&quot;Press 'W' to change wireframe mode\nPress 'D' to toggle detail map&quot;,<br> core::rect&lt;s32&gt;(10,453,200,475), true, true, 0, -1, true);<br>
65<font color="#006600">// add camera<br></font>scene::ICameraSceneNode* camera = <br> smgr-&gt;addCameraSceneNodeFPS(0,100.0f,1200.0f);<br>camera-&gt;setPosition(core::vector3df(1900*2,255*2,3700*2));<br>camera-&gt;setTarget(core::vector3df(2397*2,343*2,2700*2));<br>camera-&gt;setFarValue(12000.0f);<br><br><font color="#006600">// disable mouse cursor<br></font>device-&gt;getCursorControl()-&gt;setVisible(false);</pre></td>
66 </tr>
67 </table>
68 <p> Here comes the terrain renderer scene node: We add it just like
69 any other scene node to the scene using ISceneManager::addTerrainSceneNode().
70 The only parameter we use is a file name to the heightmap we use.
71 A heightmap is simply a gray scale texture. The terrain renderer loads
72 it and creates the 3D terrain from it.<br>
73 To make the terrain look more big, we change the scale factor of it
74 to (40, 4.4, 40). Because we don't have any dynamic lights in the
75 scene, we switch off the lighting, and we set the file terrain-texture.jpg
76 as texture for the terrain and detailmap3.jpg as second texture, called
77 detail map. At last, we set the scale values for the texture: The
78 first texture will be repeated only one time over the whole terrain,
79 and the second one (detail map) 20 times. </p>
80 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
81 <tr>
82 <td> <pre><font color="#006600">// add terrain scene node<br></font>scene::ITerrainSceneNode* terrain = smgr-&gt;addTerrainSceneNode( <br> &quot;../../media/terrain-heightmap.bmp&quot;);<br><br>terrain-&gt;setScale(core::vector3df(40, 4.4f, 40));<br>terrain-&gt;setMaterialFlag(video::EMF_LIGHTING, false);<br><br>terrain-&gt;setMaterialTexture(0, driver-&gt;getTexture(&quot;../../media/terrain-texture.jpg&quot;));<br>terrain-&gt;setMaterialTexture(1, driver-&gt;getTexture(&quot;../../media/detailmap3.jpg&quot;));<br> <br>terrain-&gt;setMaterialType(video::EMT_DETAIL_MAP);<br>terrain-&gt;scaleTexture(1.0f, 20.0f);<font color="#006600"><br></font></pre></td>
83 </tr>
84 </table>
85 <p> To be able to do collision with the terrain, we create a triangle
86 selector. If you want to know what triangle selectors do, just take
87 a look into the collision tutorial. The terrain triangle selector
88 works together with the terrain. To demonstrate this, we create a
89 collision response animator and attach it to the camera, so that the
90 camera will not be able to fly through the terrain. </p>
91 </div>
92 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
93 <tr>
94 <td> <pre><font color="#006600">// create triangle selector for the terrain <br></font>scene::ITriangleSelector* selector =<br> smgr-&gt;createTerrainTriangleSelector(terrain, 0);<br>terrain-&gt;setTriangleSelector(selector);<br><br><font color="#006600">// create collision response animator and attach it to the camera<br></font>scene::ISceneNodeAnimator* anim = smgr-&gt;createCollisionResponseAnimator(<br> selector, camera, core::vector3df(60,100,60),<br> core::vector3df(0,0,0), <br> core::vector3df(0,50,0));<br>selector-&gt;drop();<br>camera-&gt;addAnimator(anim);<br>anim-&gt;drop();</pre></td>
95 </tr>
96 </table>
97 <p> To make the user be able to switch between normal and wireframe mode,
98 we create an instance of the event reciever from above and let Irrlicht
99 know about it. In addition, we add the skybox which we already used
100 in lots of Irrlicht examples.</p>
101 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
102 <tr>
103 <td><pre><font color="#006600">// create event receiver<br></font>MyEventReceiver receiver(terrain);<br>device-&gt;setEventReceiver(&amp;receiver);<br><br><font color="#006600">// create skybox<br></font>driver-&gt;setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);<br><br>smgr-&gt;addSkyBoxSceneNode(<br> driver-&gt;getTexture(&quot;../../media/irrlicht2_up.jpg&quot;),<br> driver-&gt;getTexture(&quot;../../media/irrlicht2_dn.jpg&quot;),<br> driver-&gt;getTexture(&quot;../../media/irrlicht2_lf.jpg&quot;),<br> driver-&gt;getTexture(&quot;../../media/irrlicht2_rt.jpg&quot;),<br> driver-&gt;getTexture(&quot;../../media/irrlicht2_ft.jpg&quot;),<br> driver-&gt;getTexture(&quot;../../media/irrlicht2_bk.jpg&quot;));<br>
104driver-&gt;setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);<br></pre></td>
105 </tr>
106 </table>
107 <p> That's it, draw everything. Now you know how to use terrain in Irrlicht.</p>
108 <table width="95%" border="0" cellspacing="2" cellpadding="0" bgcolor="#CCCCCC" align="center">
109 <tr>
110 <td><pre> int lastFPS = -1;<br><br> while(device-&gt;run())<br> if (device-&gt;isWindowActive())<br> {<br> driver-&gt;beginScene(true, true, 0 );<br><br> smgr-&gt;drawAll();<br> env-&gt;drawAll();<br><br> driver-&gt;endScene();
111<br><font color="#006600"> // display frames per second in window title
112</font> int fps = driver-&gt;getFPS();<br><br> if (lastFPS != fps)<br> {<br> core::stringw str = L&quot;Terrain Renderer - Irrlicht Engine [&quot;;<br> str += driver-&gt;getName();<br> str += &quot;] FPS:&quot;;<br> str += fps;<br> device-&gt;setWindowCaption(str.c_str());<br> lastFPS = fps;<br> }<br> }<br><br> device-&gt;drop();<br> <br> return 0;<br>}</pre></td>
113 </tr>
114 </table>
115 <p>&nbsp; </p>
116 </div>
117 </td>
118 </tr>
119</table>
120<p>&nbsp;</p>
121 </body>
122</html>