aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/doc/html/example015.html
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libraries/irrlicht-1.8/doc/html/example015.html253
1 files changed, 253 insertions, 0 deletions
diff --git a/libraries/irrlicht-1.8/doc/html/example015.html b/libraries/irrlicht-1.8/doc/html/example015.html
new file mode 100644
index 0000000..cf29a60
--- /dev/null
+++ b/libraries/irrlicht-1.8/doc/html/example015.html
@@ -0,0 +1,253 @@
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 15: Loading Scenes from .irr Files</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">
69var 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('example015.html','');
84</script>
85<div id="doc-content">
86<div class="header">
87 <div class="headertitle">
88<div class="title">Tutorial 15: Loading Scenes from .irr Files </div> </div>
89</div>
90<div class="contents">
91<div class="textblock"><div class="image">
92<img src="015shot.jpg" alt="015shot.jpg"/>
93</div>
94 <p>Since version 1.1, Irrlicht is able to save and load the full scene graph into an .irr file, an xml based format. There is an editor available to edit those files, named irrEdit (<a href="http://www.ambiera.com/irredit">http://www.ambiera.com/irredit</a>) which can also be used as world and particle editor. This tutorial shows how to use .irr files.</p>
95<p>Lets start: Create an Irrlicht device and setup the window. </p>
96<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>
97<span class="preprocessor">#include &quot;<a class="code" href="driver_choice_8h.html">driverChoice.h</a>&quot;</span>
98
99<span class="keyword">using namespace </span>irr;
100
101<span class="preprocessor">#ifdef _MSC_VER</span>
102<span class="preprocessor"></span><span class="preprocessor">#pragma comment(lib, &quot;Irrlicht.lib&quot;)</span>
103<span class="preprocessor"></span><span class="preprocessor">#endif</span>
104<span class="preprocessor"></span>
105<span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>** argv)
106{
107 <span class="comment">// ask user for driver</span>
108 <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();
109 <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>)
110 <span class="keywordflow">return</span> 1;
111
112 <span class="comment">// create device and exit if creation failed</span>
113
114 <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 =
115 <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, <a class="code" href="classirr_1_1core_1_1dimension2d.html">core::dimension2d&lt;u32&gt;</a>(640, 480));
116
117 <span class="keywordflow">if</span> (device == 0)
118 <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span>
119
120 device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a3d7c98d520bf18ce1973c6f1439a7c0f" title="Sets the caption of the window.">setWindowCaption</a>(L<span class="stringliteral">&quot;Load .irr file example&quot;</span>);
121
122 <a class="code" href="classirr_1_1video_1_1_i_video_driver.html" title="Interface to driver which is able to perform 2d and 3d graphics functions.">video::IVideoDriver</a>* driver = device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#ada90707ba5c645d47e000e4e0f87c4c4" title="Provides access to the video driver for drawing 3d and 2d geometry.">getVideoDriver</a>();
123 <a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html" title="The Scene Manager manages scene nodes, mesh recources, cameras and all the other stuff.">scene::ISceneManager</a>* smgr = device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a891b503ff4d5041296d88f23f97d7b3d" title="Provides access to the scene manager.">getSceneManager</a>();
124</pre></div><p>Now load our .irr file. .irr files can store the whole scene graph including animators, materials and particle systems. And there is also the possibility to store arbitrary user data for every scene node in that file. To keep this example simple, we are simply loading the scene here. See the documentation at ISceneManager::loadScene and ISceneManager::saveScene for more information. So to load and display a complicated huge scene, we only need a single call to loadScene(). </p>
125<div class="fragment"><pre class="fragment"> <span class="comment">// load the scene</span>
126 <span class="keywordflow">if</span> (argc&gt;1)
127 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#aa7641dd33e84fca7946ed17047349a3e" title="Loads a scene. Note that the current scene is not cleared before.">loadScene</a>(argv[1]);
128 <span class="keywordflow">else</span>
129 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#aa7641dd33e84fca7946ed17047349a3e" title="Loads a scene. Note that the current scene is not cleared before.">loadScene</a>(<span class="stringliteral">&quot;../../media/example.irr&quot;</span>);
130</pre></div><p>Now we'll create a camera, and give it a collision response animator that's built from the mesh nodes in the scene we just loaded. </p>
131<div class="fragment"><pre class="fragment"> scene::ICameraSceneNode * camera = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#ac312cbc85161678d00192880f2cdddbb" title="Adds a camera scene node with an animator which provides mouse and keyboard control appropriate for f...">addCameraSceneNodeFPS</a>(0, 50.f, 0.1f);
132
133 <span class="comment">// Create a meta triangle selector to hold several triangle selectors.</span>
134 scene::IMetaTriangleSelector * meta = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#aee99e59dc55fe9f8c3507df68f84a9ff" title="Creates a meta triangle selector.">createMetaTriangleSelector</a>();
135</pre></div><p>Now we will find all the nodes in the scene and create triangle selectors for all suitable nodes. Typically, you would want to make a more informed decision about which nodes to performs collision checks on; you could capture that information in the node name or Id. </p>
136<div class="fragment"><pre class="fragment"> core::array&lt;scene::ISceneNode *&gt; nodes;
137 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a9afcad318b725b5f95e19c839145d3d6" title="Get scene nodes by type.">getSceneNodesFromType</a>(<a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bdaa61d9ba5a5ec51a33600f83fb8bd71f5" title="Will match with any scene node when checking types.">scene::ESNT_ANY</a>, nodes); <span class="comment">// Find all nodes</span>
138
139 <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">u32</a> i=0; i &lt; nodes.size(); ++i)
140 {
141 scene::ISceneNode * node = nodes[i];
142 scene::ITriangleSelector * selector = 0;
143
144 <span class="keywordflow">switch</span>(node-&gt;getType())
145 {
146 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda44d66f5c284aed4d0698d6854b6a72e3" title="simple cube scene node">scene::ESNT_CUBE</a>:
147 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda073d7fe9dfd49f24cb13bfae56d8d3b6" title="Animated Mesh Scene Node.">scene::ESNT_ANIMATED_MESH</a>:
148 <span class="comment">// Because the selector won&#39;t animate with the mesh,</span>
149 <span class="comment">// and is only being used for camera collision, we&#39;ll just use an approximate</span>
150 <span class="comment">// bounding box instead of ((scene::IAnimatedMeshSceneNode*)node)-&gt;getMesh(0)</span>
151 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#adb717113b4203e92f2bd95c84488059c" title="Creates a simple dynamic ITriangleSelector, based on a axis aligned bounding box.">createTriangleSelectorFromBoundingBox</a>(node);
152 <span class="keywordflow">break</span>;
153
154 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda25998267ed8640ca0c432df23f1b71fe" title="Mesh Scene Node.">scene::ESNT_MESH</a>:
155 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda46ad007c8d7d278a6a3769714c5dacdb" title="Sphere scene node.">scene::ESNT_SPHERE</a>: <span class="comment">// Derived from IMeshSceneNode</span>
156 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a266625379b1558e9be1dc062ea4e71f7" title="Creates a simple ITriangleSelector, based on a mesh.">createTriangleSelector</a>(((scene::IMeshSceneNode*)node)-&gt;getMesh(), node);
157 <span class="keywordflow">break</span>;
158
159 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda699880de1c55e8ed4ae24b0e07df972a" title="Terrain Scene Node.">scene::ESNT_TERRAIN</a>:
160 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#af52f8c74e08637b7643d239542371bc5" title="Creates a triangle selector which can select triangles from a terrain scene node.">createTerrainTriangleSelector</a>((scene::ITerrainSceneNode*)node);
161 <span class="keywordflow">break</span>;
162
163 <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda1cbab0e001b2df07ef2a253434532a52" title="Octree Scene Node.">scene::ESNT_OCTREE</a>:
164 selector = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a4ed7d3b34f4d0c70395b6d464fe32b96" title="Creates a Triangle Selector, optimized by an octree.">createOctreeTriangleSelector</a>(((scene::IMeshSceneNode*)node)-&gt;getMesh(), node);
165 <span class="keywordflow">break</span>;
166
167 <span class="keywordflow">default</span>:
168 <span class="comment">// Don&#39;t create a selector for this node type</span>
169 <span class="keywordflow">break</span>;
170 }
171
172 <span class="keywordflow">if</span>(selector)
173 {
174 <span class="comment">// Add it to the meta selector, which will take a reference to it</span>
175 meta-&gt;addTriangleSelector(selector);
176 <span class="comment">// And drop my reference to it, so that the meta selector owns it.</span>
177 selector-&gt;drop();
178 }
179 }
180</pre></div><p>Now that the mesh scene nodes have had triangle selectors created and added to the meta selector, create a collision response animator from that meta selector. </p>
181<div class="fragment"><pre class="fragment"> scene::ISceneNodeAnimator* anim = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a67b266cc40ebd66b5d21c26a78f002be" title="Creates a special scene node animator for doing automatic collision detection and response...">createCollisionResponseAnimator</a>(
182 meta, camera, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(5,5,5),
183 <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,0));
184 meta-&gt;drop(); <span class="comment">// I&#39;m done with the meta selector now</span>
185
186 camera-&gt;addAnimator(anim);
187 anim-&gt;drop(); <span class="comment">// I&#39;m done with the animator now</span>
188
189 <span class="comment">// And set the camera position so that it doesn&#39;t start off stuck in the geometry</span>
190 camera-&gt;setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0.f, 20.f, 0.f));
191
192 <span class="comment">// Point the camera at the cube node, by finding the first node of type ESNT_CUBE</span>
193 scene::ISceneNode * cube = smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a5ab8e8f8cc8456a3ea881c75dfe505bb" title="Get the first scene node with the specified type.">getSceneNodeFromType</a>(<a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda44d66f5c284aed4d0698d6854b6a72e3" title="simple cube scene node">scene::ESNT_CUBE</a>);
194 <span class="keywordflow">if</span>(cube)
195 camera-&gt;setTarget(cube-&gt;getAbsolutePosition());
196</pre></div><p>That's it. Draw everything and finish as usual. </p>
197<div class="fragment"><pre class="fragment"> <span class="keywordtype">int</span> lastFPS = -1;
198
199 <span class="keywordflow">while</span>(device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a0489f8151dc43f6f41503ffb5a160b35" title="Runs the device.">run</a>())
200 <span class="keywordflow">if</span> (device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#abd3c88336b739da2694883d5ffd25a70" title="Returns if the window is active.">isWindowActive</a>())
201 {
202 driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a015b8f2f18c260a00a858181be1e9945" title="Applications must call this method before performing any rendering.">beginScene</a>(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(0,200,200,200));
203 smgr-&gt;<a class="code" href="classirr_1_1scene_1_1_i_scene_manager.html#a04240262904667c821bd9de5e5fd9b02" title="Draws all the scene nodes.">drawAll</a>();
204 driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a75f61a93c5fc9fdf161c044d27bc994e" title="Presents the rendered image to the screen.">endScene</a>();
205
206 <span class="keywordtype">int</span> fps = driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a5b71428402c0b6a3b18b8f2fa408af13" title="Returns current frames per second value.">getFPS</a>();
207
208 <span class="keywordflow">if</span> (lastFPS != fps)
209 {
210 <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str = L<span class="stringliteral">&quot;Load Irrlicht File example - Irrlicht Engine [&quot;</span>;
211 str += driver-&gt;<a class="code" href="classirr_1_1video_1_1_i_video_driver.html#a87ca51832295b2dceaa1e258daf863f1" title="Gets name of this video driver.">getName</a>();
212 str += <span class="stringliteral">&quot;] FPS:&quot;</span>;
213 str += fps;
214
215 device-&gt;<a class="code" href="classirr_1_1_irrlicht_device.html#a3d7c98d520bf18ce1973c6f1439a7c0f" title="Sets the caption of the window.">setWindowCaption</a>(str.c_str());
216 lastFPS = fps;
217 }
218
219 }
220
221 device-&gt;<a class="code" href="classirr_1_1_i_reference_counted.html#afb169a857e0d2cdb96b8821cb9bff17a" title="Drops the object. Decrements the reference counter by one.">drop</a>();
222
223 <span class="keywordflow">return</span> 0;
224}
225</pre></div> </div></div>
226</div>
227 <div id="nav-path" class="navpath">
228 <ul>
229<!-- window showing the filter options -->
230<div id="MSearchSelectWindow"
231 onmouseover="return searchBox.OnSearchSelectShow()"
232 onmouseout="return searchBox.OnSearchSelectHide()"
233 onkeydown="return searchBox.OnSearchSelectKey(event)">
234<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>
235
236<!-- iframe showing the search results (closed by default) -->
237<div id="MSearchResultsWindow">
238<iframe src="javascript:void(0)" frameborder="0"
239 name="MSearchResults" id="MSearchResults">
240</iframe>
241</div>
242
243
244 <li class="footer">
245<a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht
246Engine</a> Documentation &copy; 2003-2012 by Nikolaus Gebhardt. Generated on Tue Nov 6 2012 11:06:01 for Irrlicht 3D Engine by
247<a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li>
248 </ul>
249 </div>
250
251
252</body>
253</html>