diff options
Diffstat (limited to 'libraries/irrlicht-1.8/doc/html/example012.html')
-rw-r--r-- | libraries/irrlicht-1.8/doc/html/example012.html | 339 |
1 files changed, 0 insertions, 339 deletions
diff --git a/libraries/irrlicht-1.8/doc/html/example012.html b/libraries/irrlicht-1.8/doc/html/example012.html deleted file mode 100644 index d0de908..0000000 --- a/libraries/irrlicht-1.8/doc/html/example012.html +++ /dev/null | |||
@@ -1,339 +0,0 @@ | |||
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | ||
2 | <html xmlns="http://www.w3.org/1999/xhtml"> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/> | ||
5 | <title>Irrlicht 3D Engine: Tutorial 12: Terrain Rendering</title> | ||
6 | |||
7 | <link href="tabs.css" rel="stylesheet" type="text/css"/> | ||
8 | <link href="doxygen.css" rel="stylesheet" type="text/css" /> | ||
9 | <link href="navtree.css" rel="stylesheet" type="text/css"/> | ||
10 | <script type="text/javascript" src="jquery.js"></script> | ||
11 | <script type="text/javascript" src="resize.js"></script> | ||
12 | <script type="text/javascript" src="navtree.js"></script> | ||
13 | <script type="text/javascript"> | ||
14 | $(document).ready(initResizable); | ||
15 | </script> | ||
16 | <link href="search/search.css" rel="stylesheet" type="text/css"/> | ||
17 | <script type="text/javascript" src="search/search.js"></script> | ||
18 | <script type="text/javascript"> | ||
19 | $(document).ready(function() { searchBox.OnSelectItem(0); }); | ||
20 | </script> | ||
21 | |||
22 | </head> | ||
23 | <body> | ||
24 | <div id="top"><!-- do not remove this div! --> | ||
25 | |||
26 | |||
27 | <div id="titlearea"> | ||
28 | <table cellspacing="0" cellpadding="0"> | ||
29 | <tbody> | ||
30 | <tr style="height: 56px;"> | ||
31 | |||
32 | <td id="projectlogo"><img alt="Logo" src="irrlichtlogo.png"/></td> | ||
33 | |||
34 | |||
35 | <td style="padding-left: 0.5em;"> | ||
36 | <div id="projectname">Irrlicht 3D Engine | ||
37 | |||
38 | </div> | ||
39 | |||
40 | </td> | ||
41 | |||
42 | |||
43 | |||
44 | |||
45 | <td> <div id="MSearchBox" class="MSearchBoxInactive"> | ||
46 | <span class="left"> | ||
47 | <img id="MSearchSelect" src="search/mag_sel.png" | ||
48 | onmouseover="return searchBox.OnSearchSelectShow()" | ||
49 | onmouseout="return searchBox.OnSearchSelectHide()" | ||
50 | alt=""/> | ||
51 | <input type="text" id="MSearchField" value="Search" accesskey="S" | ||
52 | onfocus="searchBox.OnSearchFieldFocus(true)" | ||
53 | onblur="searchBox.OnSearchFieldFocus(false)" | ||
54 | onkeyup="searchBox.OnSearchFieldChange(event)"/> | ||
55 | </span><span class="right"> | ||
56 | <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a> | ||
57 | </span> | ||
58 | </div> | ||
59 | </td> | ||
60 | |||
61 | |||
62 | </tr> | ||
63 | </tbody> | ||
64 | </table> | ||
65 | </div> | ||
66 | |||
67 | <!-- Generated by Doxygen 1.7.5.1 --> | ||
68 | <script type="text/javascript"> | ||
69 | var searchBox = new SearchBox("searchBox", "search",false,'Search'); | ||
70 | </script> | ||
71 | <script type="text/javascript" src="dynsections.js"></script> | ||
72 | </div> | ||
73 | <div id="side-nav" class="ui-resizable side-nav-resizable"> | ||
74 | <div id="nav-tree"> | ||
75 | <div id="nav-tree-contents"> | ||
76 | </div> | ||
77 | </div> | ||
78 | <div id="splitbar" style="-moz-user-select:none;" | ||
79 | class="ui-resizable-handle"> | ||
80 | </div> | ||
81 | </div> | ||
82 | <script type="text/javascript"> | ||
83 | initNavTree('example012.html',''); | ||
84 | </script> | ||
85 | <div id="doc-content"> | ||
86 | <div class="header"> | ||
87 | <div class="headertitle"> | ||
88 | <div class="title">Tutorial 12: Terrain Rendering </div> </div> | ||
89 | </div> | ||
90 | <div class="contents"> | ||
91 | <div class="textblock"><div class="image"> | ||
92 | <img src="012shot.jpg" alt="012shot.jpg"/> | ||
93 | </div> | ||
94 | <p>This tutorial will briefly show how to use the terrain renderer of Irrlicht. It will also show the terrain renderer triangle selector to be able to do collision detection with terrain.</p> | ||
95 | <p>Note that the Terrain Renderer in Irrlicht is based on Spintz' GeoMipMapSceneNode, lots of thanks go to him. DeusXL provided a new elegant simple solution for building larger area on small heightmaps -> terrain smoothing.</p> | ||
96 | <p>In the beginning there is nothing special. We include the needed header files and create an event listener to listen if the user presses a key: The 'W' key switches to wireframe mode, the 'P' key to pointcloud mode, and the 'D' key toggles between solid and detail mapped material. </p> | ||
97 | <div class="fragment"><pre class="fragment"><span class="preprocessor">#include <<a class="code" href="irrlicht_8h.html" title="Main header file of the irrlicht, the only file needed to include.">irrlicht.h</a>></span> | ||
98 | <span class="preprocessor">#include "<a class="code" href="driver_choice_8h.html">driverChoice.h</a>"</span> | ||
99 | |||
100 | <span class="keyword">using namespace </span>irr; | ||
101 | |||
102 | <span class="preprocessor">#ifdef _MSC_VER</span> | ||
103 | <span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, "Irrlicht.lib")</span> | ||
104 | <span class="preprocessor"></span><span class="preprocessor">#endif</span> | ||
105 | <span class="preprocessor"></span> | ||
106 | |||
107 | <span class="keyword">class </span>MyEventReceiver : <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> | ||
108 | { | ||
109 | <span class="keyword">public</span>: | ||
110 | |||
111 | MyEventReceiver(<a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* terrain, <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* skybox, <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* skydome) : | ||
112 | Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true), showDebug(false) | ||
113 | { | ||
114 | Skybox->setVisible(showBox); | ||
115 | Skydome->setVisible(!showBox); | ||
116 | } | ||
117 | |||
118 | <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>& event) | ||
119 | { | ||
120 | <span class="comment">// check if user presses the key 'W' or 'D'</span> | ||
121 | <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#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">irr::EET_KEY_INPUT_EVENT</a> && !event.<a class="code" href="structirr_1_1_s_event.html#abe216d2ccbae64f509cca162072c9d7e">KeyInput</a>.PressedDown) | ||
122 | { | ||
123 | <span class="keywordflow">switch</span> (event.<a class="code" href="structirr_1_1_s_event.html#abe216d2ccbae64f509cca162072c9d7e">KeyInput</a>.Key) | ||
124 | { | ||
125 | <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> | ||
126 | Terrain->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3abc620823efed8d6bdbd46c8a0180893a" title="Draw as wireframe or filled triangles? Default: false.">video::EMF_WIREFRAME</a>, | ||
127 | !Terrain->getMaterial(0).Wireframe); | ||
128 | Terrain->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>); | ||
129 | <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
130 | <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> | ||
131 | Terrain->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3726bbddc57e6b37b05481b640eefb07" title="Draw as point cloud or filled triangles? Default: false.">video::EMF_POINTCLOUD</a>, | ||
132 | !Terrain->getMaterial(0).PointCloud); | ||
133 | Terrain->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>); | ||
134 | <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
135 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ad20e7e220103e611752b90edeb6cbc9d">irr::KEY_KEY_D</a>: <span class="comment">// toggle detail map</span> | ||
136 | Terrain->setMaterialType( | ||
137 | Terrain->getMaterial(0).MaterialType == <a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a> ? | ||
138 | <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>); | ||
139 | <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
140 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ae52bafc112fc6c52f6b49cea42fa246e">irr::KEY_KEY_S</a>: <span class="comment">// toggle skies</span> | ||
141 | showBox=!showBox; | ||
142 | Skybox->setVisible(showBox); | ||
143 | Skydome->setVisible(!showBox); | ||
144 | <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
145 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ad004cdd263159baf3e4724336aad66d5">irr::KEY_KEY_X</a>: <span class="comment">// toggle debug information</span> | ||
146 | showDebug=!showDebug; | ||
147 | Terrain->setDebugDataVisible(showDebug?<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea80f38e42f1b8cf169e83f44092367bfe" title="EDS_BBOX | EDS_BBOX_BUFFERS.">scene::EDS_BBOX_ALL</a>:<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea25111b15f03bee9a99498737286916dc" title="No Debug Data ( Default )">scene::EDS_OFF</a>); | ||
148 | <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
149 | <span class="keywordflow">default</span>: | ||
150 | <span class="keywordflow">break</span>; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | <span class="keywordflow">return</span> <span class="keyword">false</span>; | ||
155 | } | ||
156 | |||
157 | <span class="keyword">private</span>: | ||
158 | <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* Terrain; | ||
159 | <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* Skybox; | ||
160 | <a class="code" href="classirr_1_1scene_1_1_i_scene_node.html" title="Scene node interface.">scene::ISceneNode</a>* Skydome; | ||
161 | <span class="keywordtype">bool</span> showBox; | ||
162 | <span class="keywordtype">bool</span> showDebug; | ||
163 | }; | ||
164 | </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> | ||
165 | <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main() | ||
166 | { | ||
167 | <span class="comment">// ask user for driver</span> | ||
168 | <a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0" title="An enum for all types of drivers the Irrlicht Engine supports.">video::E_DRIVER_TYPE</a> driverType=driverChoiceConsole(); | ||
169 | <span class="keywordflow">if</span> (driverType==<a class="code" href="namespaceirr_1_1video.html#ae35a6de6d436c76107ad157fe42356d0ae685cada50f8c100403134d932d0414c" title="No driver, just for counting the elements.">video::EDT_COUNT</a>) | ||
170 | <span class="keywordflow">return</span> 1; | ||
171 | |||
172 | <span class="comment">// create device with full flexibility over creation parameters</span> | ||
173 | <span class="comment">// you can add more parameters if desired, check irr::SIrrlichtCreationParameters</span> | ||
174 | <a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html" title="Structure for holding Irrlicht Device creation parameters.">irr::SIrrlichtCreationParameters</a> params; | ||
175 | params.<a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html#a1ea2f50c3b3a8eed6602a1a86e1cdf82" title="Type of video driver used to render graphics.">DriverType</a>=driverType; | ||
176 | params.<a class="code" href="structirr_1_1_s_irrlicht_creation_parameters.html#a1b596e201a6ebd63ca2841d46be10433" title="Size of the window or the video mode in fullscreen mode. Default: 800x600.">WindowSize</a>=core::dimension2d<u32>(640, 480); | ||
177 | IrrlichtDevice* device = <a class="code" href="namespaceirr.html#ac83a30d674204dcb94d70f849e9b4a62" title="Creates an Irrlicht device with the option to specify advanced parameters.">createDeviceEx</a>(params); | ||
178 | |||
179 | <span class="keywordflow">if</span> (device == 0) | ||
180 | <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span> | ||
181 | </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> | ||
182 | <div class="fragment"><pre class="fragment"> video::IVideoDriver* driver = device->getVideoDriver(); | ||
183 | scene::ISceneManager* smgr = device->getSceneManager(); | ||
184 | gui::IGUIEnvironment* env = device->getGUIEnvironment(); | ||
185 | |||
186 | driver->setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa20881e307a778c4a4fbb5327a60a93bb">video::ETCF_ALWAYS_32_BIT</a>, <span class="keyword">true</span>); | ||
187 | |||
188 | <span class="comment">// add irrlicht logo</span> | ||
189 | env->addImage(driver->getTexture(<span class="stringliteral">"../../media/irrlichtlogo2.png"</span>), | ||
190 | core::position2d<s32>(10,10)); | ||
191 | |||
192 | <span class="comment">//set other font</span> | ||
193 | env->getSkin()->setFont(env->getFont(<span class="stringliteral">"../../media/fontlucida.png"</span>)); | ||
194 | |||
195 | <span class="comment">// add some help text</span> | ||
196 | env->addStaticText( | ||
197 | L<span class="stringliteral">"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome"</span>, | ||
198 | core::rect<s32>(10,421,250,475), <span class="keyword">true</span>, <span class="keyword">true</span>, 0, -1, <span class="keyword">true</span>); | ||
199 | |||
200 | <span class="comment">// add camera</span> | ||
201 | scene::ICameraSceneNode* camera = | ||
202 | smgr->addCameraSceneNodeFPS(0,100.0f,1.2f); | ||
203 | |||
204 | camera->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)); | ||
205 | camera->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)); | ||
206 | camera->setFarValue(42000.0f); | ||
207 | |||
208 | <span class="comment">// disable mouse cursor</span> | ||
209 | device->getCursorControl()->setVisible(<span class="keyword">false</span>); | ||
210 | </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> | ||
211 | <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> | ||
212 | <div class="fragment"><pre class="fragment"> <span class="comment">// add terrain scene node</span> | ||
213 | scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( | ||
214 | <span class="stringliteral">"../../media/terrain-heightmap.bmp"</span>, | ||
215 | 0, <span class="comment">// parent node</span> | ||
216 | -1, <span class="comment">// node id</span> | ||
217 | <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> | ||
218 | <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> | ||
219 | <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> | ||
220 | video::SColor ( 255, 255, 255, 255 ), <span class="comment">// vertexColor</span> | ||
221 | 5, <span class="comment">// maxLOD</span> | ||
222 | <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> | ||
223 | 4 <span class="comment">// smoothFactor</span> | ||
224 | ); | ||
225 | |||
226 | terrain-><a class="code" href="classirr_1_1scene_1_1_i_scene_node.html#a2841d5077854b9981711a403f33762cd" title="Sets all material flags at once to a new value.">setMaterialFlag</a>(<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>); | ||
227 | |||
228 | terrain->setMaterialTexture(0, | ||
229 | driver->getTexture(<span class="stringliteral">"../../media/terrain-texture.jpg"</span>)); | ||
230 | terrain->setMaterialTexture(1, | ||
231 | driver->getTexture(<span class="stringliteral">"../../media/detailmap3.jpg"</span>)); | ||
232 | |||
233 | terrain->setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a065af4f8daeb15f81bfe0417a3f231b1" title="Detail mapped material.">video::EMT_DETAIL_MAP</a>); | ||
234 | |||
235 | terrain->scaleTexture(1.0f, 20.0f); | ||
236 | </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> | ||
237 | <div class="fragment"><pre class="fragment"> <span class="comment">// create triangle selector for the terrain </span> | ||
238 | scene::ITriangleSelector* selector | ||
239 | = smgr->createTerrainTriangleSelector(terrain, 0); | ||
240 | terrain->setTriangleSelector(selector); | ||
241 | |||
242 | <span class="comment">// create collision response animator and attach it to the camera</span> | ||
243 | scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( | ||
244 | selector, camera, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(60,100,60), | ||
245 | <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0), | ||
246 | <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,50,0)); | ||
247 | selector->drop(); | ||
248 | camera->addAnimator(anim); | ||
249 | anim->drop(); | ||
250 | </pre></div><p> If you need access to the terrain data you can also do this directly via the following code fragment. </p> | ||
251 | <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>); | ||
252 | terrain->getMeshBufferForLOD(*buffer, 0); | ||
253 | video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer->getVertexBuffer().getData(); | ||
254 | <span class="comment">// Work on data or get the IndexBuffer with a similar call.</span> | ||
255 | buffer->drop(); <span class="comment">// When done drop the buffer again.</span> | ||
256 | </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> | ||
257 | <div class="fragment"><pre class="fragment"> <span class="comment">// create skybox and skydome</span> | ||
258 | driver->setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa288b302e9d4faaba80c7796c7bc1682c">video::ETCF_CREATE_MIP_MAPS</a>, <span class="keyword">false</span>); | ||
259 | |||
260 | scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode( | ||
261 | driver->getTexture(<span class="stringliteral">"../../media/irrlicht2_up.jpg"</span>), | ||
262 | driver->getTexture(<span class="stringliteral">"../../media/irrlicht2_dn.jpg"</span>), | ||
263 | driver->getTexture(<span class="stringliteral">"../../media/irrlicht2_lf.jpg"</span>), | ||
264 | driver->getTexture(<span class="stringliteral">"../../media/irrlicht2_rt.jpg"</span>), | ||
265 | driver->getTexture(<span class="stringliteral">"../../media/irrlicht2_ft.jpg"</span>), | ||
266 | driver->getTexture(<span class="stringliteral">"../../media/irrlicht2_bk.jpg"</span>)); | ||
267 | scene::ISceneNode* skydome=smgr->addSkyDomeSceneNode(driver->getTexture(<span class="stringliteral">"../../media/skydome.jpg"</span>),16,8,0.95f,2.0f); | ||
268 | |||
269 | driver->setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa288b302e9d4faaba80c7796c7bc1682c">video::ETCF_CREATE_MIP_MAPS</a>, <span class="keyword">true</span>); | ||
270 | |||
271 | <span class="comment">// create event receiver</span> | ||
272 | MyEventReceiver receiver(terrain, skybox, skydome); | ||
273 | device->setEventReceiver(&receiver); | ||
274 | </pre></div><p>That's it, draw everything. </p> | ||
275 | <div class="fragment"><pre class="fragment"> <span class="keywordtype">int</span> lastFPS = -1; | ||
276 | |||
277 | <span class="keywordflow">while</span>(device->run()) | ||
278 | <span class="keywordflow">if</span> (device->isWindowActive()) | ||
279 | { | ||
280 | driver->beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, 0 ); | ||
281 | |||
282 | smgr->drawAll(); | ||
283 | env->drawAll(); | ||
284 | |||
285 | driver->endScene(); | ||
286 | |||
287 | <span class="comment">// display frames per second in window title</span> | ||
288 | <span class="keywordtype">int</span> fps = driver->getFPS(); | ||
289 | <span class="keywordflow">if</span> (lastFPS != fps) | ||
290 | { | ||
291 | <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">"Terrain Renderer - Irrlicht Engine ["</span>; | ||
292 | str += driver->getName(); | ||
293 | str += <span class="stringliteral">"] FPS:"</span>; | ||
294 | str += fps; | ||
295 | <span class="comment">// Also print terrain height of current camera position</span> | ||
296 | <span class="comment">// We can use camera position because terrain is located at coordinate origin</span> | ||
297 | str += <span class="stringliteral">" Height: "</span>; | ||
298 | str += terrain->getHeight(camera->getAbsolutePosition().X, | ||
299 | camera->getAbsolutePosition().Z); | ||
300 | |||
301 | device->setWindowCaption(str.c_str()); | ||
302 | lastFPS = fps; | ||
303 | } | ||
304 | } | ||
305 | |||
306 | device->drop(); | ||
307 | |||
308 | <span class="keywordflow">return</span> 0; | ||
309 | } | ||
310 | </pre></div><p>Now you know how to use terrain in Irrlicht. </p> | ||
311 | </div></div> | ||
312 | </div> | ||
313 | <div id="nav-path" class="navpath"> | ||
314 | <ul> | ||
315 | <!-- window showing the filter options --> | ||
316 | <div id="MSearchSelectWindow" | ||
317 | onmouseover="return searchBox.OnSearchSelectShow()" | ||
318 | onmouseout="return searchBox.OnSearchSelectHide()" | ||
319 | onkeydown="return searchBox.OnSearchSelectKey(event)"> | ||
320 | <a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark"> </span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark"> </span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark"> </span>Defines</a></div> | ||
321 | |||
322 | <!-- iframe showing the search results (closed by default) --> | ||
323 | <div id="MSearchResultsWindow"> | ||
324 | <iframe src="javascript:void(0)" frameborder="0" | ||
325 | name="MSearchResults" id="MSearchResults"> | ||
326 | </iframe> | ||
327 | </div> | ||
328 | |||
329 | |||
330 | <li class="footer"> | ||
331 | <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht | ||
332 | Engine</a> Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Tue Nov 6 2012 11:06:01 for Irrlicht 3D Engine by | ||
333 | <a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li> | ||
334 | </ul> | ||
335 | </div> | ||
336 | |||
337 | |||
338 | </body> | ||
339 | </html> | ||