diff options
Diffstat (limited to 'libraries/irrlicht-1.8/doc/html/example009.html')
-rw-r--r-- | libraries/irrlicht-1.8/doc/html/example009.html | 1043 |
1 files changed, 0 insertions, 1043 deletions
diff --git a/libraries/irrlicht-1.8/doc/html/example009.html b/libraries/irrlicht-1.8/doc/html/example009.html deleted file mode 100644 index 5e77e57..0000000 --- a/libraries/irrlicht-1.8/doc/html/example009.html +++ /dev/null | |||
@@ -1,1043 +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 9: Mesh Viewer</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('example009.html',''); | ||
84 | </script> | ||
85 | <div id="doc-content"> | ||
86 | <div class="header"> | ||
87 | <div class="headertitle"> | ||
88 | <div class="title">Tutorial 9: Mesh Viewer </div> </div> | ||
89 | </div> | ||
90 | <div class="contents"> | ||
91 | <div class="textblock"><div class="image"> | ||
92 | <img src="009shot.jpg" alt="009shot.jpg"/> | ||
93 | </div> | ||
94 | <p>This tutorial show how to create a more complex application with the engine. We construct a simple mesh viewer using the user interface API and the scene management of Irrlicht. The tutorial show how to create and use Buttons, Windows, Toolbars, Menus, ComboBoxes, Tabcontrols, Editboxes, Images, MessageBoxes, SkyBoxes, and how to parse XML files with the integrated XML reader of the engine.</p> | ||
95 | <p>We start like in most other tutorials: Include all necessary header files, add a comment to let the engine be linked with the right .lib file in Visual Studio, and declare some global variables. We also add two 'using namespace' statements, so we do not need to write the whole names of all classes. In this tutorial, we use a lot stuff from the gui namespace. </p> | ||
96 | <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> | ||
97 | <span class="preprocessor">#include "<a class="code" href="driver_choice_8h.html">driverChoice.h</a>"</span> | ||
98 | |||
99 | <span class="keyword">using namespace </span>irr; | ||
100 | <span class="keyword">using namespace </span>gui; | ||
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">#endif</span> | ||
105 | </pre></div><p>Some global variables used later on </p> | ||
106 | <div class="fragment"><pre class="fragment">IrrlichtDevice *Device = 0; | ||
107 | <a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a> StartUpModelFile; | ||
108 | <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> MessageText; | ||
109 | <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> Caption; | ||
110 | scene::ISceneNode* Model = 0; | ||
111 | scene::ISceneNode* SkyBox = 0; | ||
112 | <span class="keywordtype">bool</span> Octree=<span class="keyword">false</span>; | ||
113 | <span class="keywordtype">bool</span> UseLight=<span class="keyword">false</span>; | ||
114 | |||
115 | scene::ICameraSceneNode* Camera[2] = {0, 0}; | ||
116 | |||
117 | <span class="comment">// Values used to identify individual GUI elements</span> | ||
118 | <span class="keyword">enum</span> | ||
119 | { | ||
120 | GUI_ID_DIALOG_ROOT_WINDOW = 0x10000, | ||
121 | |||
122 | GUI_ID_X_SCALE, | ||
123 | GUI_ID_Y_SCALE, | ||
124 | GUI_ID_Z_SCALE, | ||
125 | |||
126 | GUI_ID_OPEN_MODEL, | ||
127 | GUI_ID_SET_MODEL_ARCHIVE, | ||
128 | GUI_ID_LOAD_AS_OCTREE, | ||
129 | |||
130 | GUI_ID_SKY_BOX_VISIBLE, | ||
131 | GUI_ID_TOGGLE_DEBUG_INFO, | ||
132 | |||
133 | GUI_ID_DEBUG_OFF, | ||
134 | GUI_ID_DEBUG_BOUNDING_BOX, | ||
135 | GUI_ID_DEBUG_NORMALS, | ||
136 | GUI_ID_DEBUG_SKELETON, | ||
137 | GUI_ID_DEBUG_WIRE_OVERLAY, | ||
138 | GUI_ID_DEBUG_HALF_TRANSPARENT, | ||
139 | GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES, | ||
140 | GUI_ID_DEBUG_ALL, | ||
141 | |||
142 | GUI_ID_MODEL_MATERIAL_SOLID, | ||
143 | GUI_ID_MODEL_MATERIAL_TRANSPARENT, | ||
144 | GUI_ID_MODEL_MATERIAL_REFLECTION, | ||
145 | |||
146 | GUI_ID_CAMERA_MAYA, | ||
147 | GUI_ID_CAMERA_FIRST_PERSON, | ||
148 | |||
149 | GUI_ID_POSITION_TEXT, | ||
150 | |||
151 | GUI_ID_ABOUT, | ||
152 | GUI_ID_QUIT, | ||
153 | |||
154 | GUI_ID_TEXTUREFILTER, | ||
155 | GUI_ID_SKIN_TRANSPARENCY, | ||
156 | GUI_ID_SKIN_ANIMATION_FPS, | ||
157 | |||
158 | GUI_ID_BUTTON_SET_SCALE, | ||
159 | GUI_ID_BUTTON_SCALE_MUL10, | ||
160 | GUI_ID_BUTTON_SCALE_DIV10, | ||
161 | GUI_ID_BUTTON_OPEN_MODEL, | ||
162 | GUI_ID_BUTTON_SHOW_ABOUT, | ||
163 | GUI_ID_BUTTON_SHOW_TOOLBOX, | ||
164 | GUI_ID_BUTTON_SELECT_ARCHIVE, | ||
165 | |||
166 | GUI_ID_ANIMATION_INFO, | ||
167 | |||
168 | <span class="comment">// And some magic numbers</span> | ||
169 | MAX_FRAMERATE = 80, | ||
170 | DEFAULT_FRAMERATE = 30 | ||
171 | }; | ||
172 | </pre></div><p>Toggle between various cameras </p> | ||
173 | <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> setActiveCamera(scene::ICameraSceneNode* newActive) | ||
174 | { | ||
175 | <span class="keywordflow">if</span> (0 == Device) | ||
176 | <span class="keywordflow">return</span>; | ||
177 | |||
178 | scene::ICameraSceneNode * active = Device->getSceneManager()->getActiveCamera(); | ||
179 | active->setInputReceiverEnabled(<span class="keyword">false</span>); | ||
180 | |||
181 | newActive->setInputReceiverEnabled(<span class="keyword">true</span>); | ||
182 | Device->getSceneManager()->setActiveCamera(newActive); | ||
183 | } | ||
184 | </pre></div><p>Set the skin transparency by changing the alpha values of all skin-colors </p> | ||
185 | <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> setSkinTransparency(<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> alpha, <a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html" title="A skin modifies the look of the GUI elements.">irr::gui::IGUISkin</a> * skin) | ||
186 | { | ||
187 | <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=0; i<<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aaf340f49e2e0827c0f06fdf65098554af">irr::gui::EGDC_COUNT</a> ; ++i) | ||
188 | { | ||
189 | video::SColor col = skin-><a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ad1afa2e5e34c30e0cbfb85b1dee2dbe3" title="returns default color">getColor</a>((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i); | ||
190 | col.setAlpha(alpha); | ||
191 | skin-><a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ab9782296ba881872207a0915a81d7807" title="sets a default color">setColor</a>((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">EGUI_DEFAULT_COLOR</a>)i, col); | ||
192 | } | ||
193 | } | ||
194 | </pre></div><p>Update the display of the model scaling </p> | ||
195 | <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> updateScaleInfo(scene::ISceneNode* model) | ||
196 | { | ||
197 | IGUIElement* toolboxWnd = Device->getGUIEnvironment()->getRootGUIElement()->getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>); | ||
198 | <span class="keywordflow">if</span> (!toolboxWnd) | ||
199 | <span class="keywordflow">return</span>; | ||
200 | <span class="keywordflow">if</span> (!model) | ||
201 | { | ||
202 | toolboxWnd->getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)->setText( L<span class="stringliteral">"-"</span> ); | ||
203 | toolboxWnd->getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)->setText( L<span class="stringliteral">"-"</span> ); | ||
204 | toolboxWnd->getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)->setText( L<span class="stringliteral">"-"</span> ); | ||
205 | } | ||
206 | <span class="keywordflow">else</span> | ||
207 | { | ||
208 | <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a> scale = model->getScale(); | ||
209 | toolboxWnd->getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)->setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(scale.X).c_str() ); | ||
210 | toolboxWnd->getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)->setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(scale.Y).c_str() ); | ||
211 | toolboxWnd->getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)->setText( <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(scale.Z).c_str() ); | ||
212 | } | ||
213 | } | ||
214 | </pre></div><p>Function showAboutText() displays a messagebox with a caption and a message text. The texts will be stored in the MessageText and Caption variables at startup. </p> | ||
215 | <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> showAboutText() | ||
216 | { | ||
217 | <span class="comment">// create modal message box with the text</span> | ||
218 | <span class="comment">// loaded from the xml file.</span> | ||
219 | Device->getGUIEnvironment()->addMessageBox( | ||
220 | Caption.c_str(), MessageText.c_str()); | ||
221 | } | ||
222 | </pre></div><p>Function loadModel() loads a model and displays it using an addAnimatedMeshSceneNode and the scene manager. Nothing difficult. It also displays a short message box, if the model could not be loaded. </p> | ||
223 | <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> loadModel(<span class="keyword">const</span> <a class="code" href="namespaceirr.html#a9395eaea339bcb546b319e9c96bf7410" title="8 bit character variable.">c8</a>* fn) | ||
224 | { | ||
225 | <span class="comment">// modify the name if it a .pk3 file</span> | ||
226 | |||
227 | <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a> filename(fn); | ||
228 | |||
229 | <a class="code" href="namespaceirr_1_1io.html#ab1bdc45edb3f94d8319c02bc0f840ee1" title="Type used for all file system related strings.">io::path</a> extension; | ||
230 | <a class="code" href="namespaceirr_1_1core.html#abebbe8b229dc865ebeb9bb0fd367d6ea" title="get the filename extension from a file path">core::getFileNameExtension</a>(extension, filename); | ||
231 | extension.make_lower(); | ||
232 | |||
233 | <span class="comment">// if a texture is loaded apply it to the current model..</span> | ||
234 | <span class="keywordflow">if</span> (extension == <span class="stringliteral">".jpg"</span> || extension == <span class="stringliteral">".pcx"</span> || | ||
235 | extension == <span class="stringliteral">".png"</span> || extension == <span class="stringliteral">".ppm"</span> || | ||
236 | extension == <span class="stringliteral">".pgm"</span> || extension == <span class="stringliteral">".pbm"</span> || | ||
237 | extension == <span class="stringliteral">".psd"</span> || extension == <span class="stringliteral">".tga"</span> || | ||
238 | extension == <span class="stringliteral">".bmp"</span> || extension == <span class="stringliteral">".wal"</span> || | ||
239 | extension == <span class="stringliteral">".rgb"</span> || extension == <span class="stringliteral">".rgba"</span>) | ||
240 | { | ||
241 | video::ITexture * texture = | ||
242 | Device->getVideoDriver()->getTexture( filename ); | ||
243 | <span class="keywordflow">if</span> ( texture && Model ) | ||
244 | { | ||
245 | <span class="comment">// always reload texture</span> | ||
246 | Device->getVideoDriver()->removeTexture(texture); | ||
247 | texture = Device->getVideoDriver()->getTexture( filename ); | ||
248 | |||
249 | Model->setMaterialTexture(0, texture); | ||
250 | } | ||
251 | <span class="keywordflow">return</span>; | ||
252 | } | ||
253 | <span class="comment">// if a archive is loaded add it to the FileArchive..</span> | ||
254 | <span class="keywordflow">else</span> <span class="keywordflow">if</span> (extension == <span class="stringliteral">".pk3"</span> || extension == <span class="stringliteral">".zip"</span> || extension == <span class="stringliteral">".pak"</span> || extension == <span class="stringliteral">".npk"</span>) | ||
255 | { | ||
256 | Device->getFileSystem()->addFileArchive(filename.c_str()); | ||
257 | <span class="keywordflow">return</span>; | ||
258 | } | ||
259 | |||
260 | <span class="comment">// load a model into the engine</span> | ||
261 | |||
262 | <span class="keywordflow">if</span> (Model) | ||
263 | Model->remove(); | ||
264 | |||
265 | Model = 0; | ||
266 | |||
267 | <span class="keywordflow">if</span> (extension==<span class="stringliteral">".irr"</span>) | ||
268 | { | ||
269 | core::array<scene::ISceneNode*> outNodes; | ||
270 | Device->getSceneManager()->loadScene(filename); | ||
271 | Device->getSceneManager()->getSceneNodesFromType(<a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda073d7fe9dfd49f24cb13bfae56d8d3b6" title="Animated Mesh Scene Node.">scene::ESNT_ANIMATED_MESH</a>, outNodes); | ||
272 | <span class="keywordflow">if</span> (outNodes.size()) | ||
273 | Model = outNodes[0]; | ||
274 | <span class="keywordflow">return</span>; | ||
275 | } | ||
276 | |||
277 | scene::IAnimatedMesh* m = Device->getSceneManager()->getMesh( filename.c_str() ); | ||
278 | |||
279 | <span class="keywordflow">if</span> (!m) | ||
280 | { | ||
281 | <span class="comment">// model could not be loaded</span> | ||
282 | |||
283 | <span class="keywordflow">if</span> (StartUpModelFile != filename) | ||
284 | Device->getGUIEnvironment()->addMessageBox( | ||
285 | Caption.c_str(), L<span class="stringliteral">"The model could not be loaded. "</span> \ | ||
286 | L<span class="stringliteral">"Maybe it is not a supported file format."</span>); | ||
287 | <span class="keywordflow">return</span>; | ||
288 | } | ||
289 | |||
290 | <span class="comment">// set default material properties</span> | ||
291 | |||
292 | <span class="keywordflow">if</span> (Octree) | ||
293 | Model = Device->getSceneManager()->addOctreeSceneNode(m->getMesh(0)); | ||
294 | <span class="keywordflow">else</span> | ||
295 | { | ||
296 | scene::IAnimatedMeshSceneNode* animModel = Device->getSceneManager()->addAnimatedMeshSceneNode(m); | ||
297 | animModel->setAnimationSpeed(30); | ||
298 | Model = animModel; | ||
299 | } | ||
300 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, UseLight); | ||
301 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3efe2d4921909a842adfc44dacc74520" title="Normalizes normals. Default: false.">video::EMF_NORMALIZE_NORMALS</a>, UseLight); | ||
302 | <span class="comment">// Model->setMaterialFlag(video::EMF_BACK_FACE_CULLING, false);</span> | ||
303 | Model->setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea25111b15f03bee9a99498737286916dc" title="No Debug Data ( Default )">scene::EDS_OFF</a>); | ||
304 | |||
305 | <span class="comment">// we need to uncheck the menu entries. would be cool to fake a menu event, but</span> | ||
306 | <span class="comment">// that's not so simple. so we do it brute force</span> | ||
307 | gui::IGUIContextMenu* menu = (gui::IGUIContextMenu*)Device->getGUIEnvironment()->getRootGUIElement()->getElementFromId(GUI_ID_TOGGLE_DEBUG_INFO, <span class="keyword">true</span>); | ||
308 | <span class="keywordflow">if</span> (menu) | ||
309 | <span class="keywordflow">for</span>(<span class="keywordtype">int</span> item = 1; item < 6; ++item) | ||
310 | menu->setItemChecked(item, <span class="keyword">false</span>); | ||
311 | updateScaleInfo(Model); | ||
312 | } | ||
313 | </pre></div><p>Function createToolBox() creates a toolbox window. In this simple mesh viewer, this toolbox only contains a tab control with three edit boxes for changing the scale of the displayed model. </p> | ||
314 | <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> createToolBox() | ||
315 | { | ||
316 | <span class="comment">// remove tool box if already there</span> | ||
317 | IGUIEnvironment* env = Device->getGUIEnvironment(); | ||
318 | IGUIElement* root = env->getRootGUIElement(); | ||
319 | IGUIElement* e = root->getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>); | ||
320 | <span class="keywordflow">if</span> (e) | ||
321 | e->remove(); | ||
322 | |||
323 | <span class="comment">// create the toolbox window</span> | ||
324 | IGUIWindow* wnd = env->addWindow(core::rect<s32>(600,45,800,480), | ||
325 | <span class="keyword">false</span>, L<span class="stringliteral">"Toolset"</span>, 0, GUI_ID_DIALOG_ROOT_WINDOW); | ||
326 | |||
327 | <span class="comment">// create tab control and tabs</span> | ||
328 | IGUITabControl* tab = env->addTabControl( | ||
329 | core::rect<s32>(2,20,800-602,480-7), wnd, <span class="keyword">true</span>, <span class="keyword">true</span>); | ||
330 | |||
331 | IGUITab* t1 = tab->addTab(L<span class="stringliteral">"Config"</span>); | ||
332 | |||
333 | <span class="comment">// add some edit boxes and a button to tab one</span> | ||
334 | env->addStaticText(L<span class="stringliteral">"Scale:"</span>, | ||
335 | core::rect<s32>(10,20,60,45), <span class="keyword">false</span>, <span class="keyword">false</span>, t1); | ||
336 | env->addStaticText(L<span class="stringliteral">"X:"</span>, core::rect<s32>(22,48,40,66), <span class="keyword">false</span>, <span class="keyword">false</span>, t1); | ||
337 | env->addEditBox(L<span class="stringliteral">"1.0"</span>, core::rect<s32>(40,46,130,66), <span class="keyword">true</span>, t1, GUI_ID_X_SCALE); | ||
338 | env->addStaticText(L<span class="stringliteral">"Y:"</span>, core::rect<s32>(22,82,40,96), <span class="keyword">false</span>, <span class="keyword">false</span>, t1); | ||
339 | env->addEditBox(L<span class="stringliteral">"1.0"</span>, core::rect<s32>(40,76,130,96), <span class="keyword">true</span>, t1, GUI_ID_Y_SCALE); | ||
340 | env->addStaticText(L<span class="stringliteral">"Z:"</span>, core::rect<s32>(22,108,40,126), <span class="keyword">false</span>, <span class="keyword">false</span>, t1); | ||
341 | env->addEditBox(L<span class="stringliteral">"1.0"</span>, core::rect<s32>(40,106,130,126), <span class="keyword">true</span>, t1, GUI_ID_Z_SCALE); | ||
342 | |||
343 | env->addButton(core::rect<s32>(10,134,85,165), t1, GUI_ID_BUTTON_SET_SCALE, L<span class="stringliteral">"Set"</span>); | ||
344 | |||
345 | <span class="comment">// quick scale buttons</span> | ||
346 | env->addButton(core::rect<s32>(65,20,95,40), t1, GUI_ID_BUTTON_SCALE_MUL10, L<span class="stringliteral">"* 10"</span>); | ||
347 | env->addButton(core::rect<s32>(100,20,130,40), t1, GUI_ID_BUTTON_SCALE_DIV10, L<span class="stringliteral">"* 0.1"</span>); | ||
348 | |||
349 | updateScaleInfo(Model); | ||
350 | |||
351 | <span class="comment">// add transparency control</span> | ||
352 | env->addStaticText(L<span class="stringliteral">"GUI Transparency Control:"</span>, | ||
353 | core::rect<s32>(10,200,150,225), <span class="keyword">true</span>, <span class="keyword">false</span>, t1); | ||
354 | IGUIScrollBar* scrollbar = env->addScrollBar(<span class="keyword">true</span>, | ||
355 | core::rect<s32>(10,225,150,240), t1, GUI_ID_SKIN_TRANSPARENCY); | ||
356 | scrollbar->setMax(255); | ||
357 | scrollbar->setPos(255); | ||
358 | |||
359 | <span class="comment">// add framerate control</span> | ||
360 | env->addStaticText(L<span class="stringliteral">":"</span>, core::rect<s32>(10,240,150,265), <span class="keyword">true</span>, <span class="keyword">false</span>, t1); | ||
361 | env->addStaticText(L<span class="stringliteral">"Framerate:"</span>, | ||
362 | core::rect<s32>(12,240,75,265), <span class="keyword">false</span>, <span class="keyword">false</span>, t1); | ||
363 | <span class="comment">// current frame info</span> | ||
364 | env->addStaticText(L<span class="stringliteral">""</span>, core::rect<s32>(75,240,200,265), <span class="keyword">false</span>, <span class="keyword">false</span>, t1, | ||
365 | GUI_ID_ANIMATION_INFO); | ||
366 | scrollbar = env->addScrollBar(<span class="keyword">true</span>, | ||
367 | core::rect<s32>(10,265,150,280), t1, GUI_ID_SKIN_ANIMATION_FPS); | ||
368 | scrollbar->setMax(MAX_FRAMERATE); | ||
369 | scrollbar->setMin(-MAX_FRAMERATE); | ||
370 | scrollbar->setPos(DEFAULT_FRAMERATE); | ||
371 | scrollbar->setSmallStep(1); | ||
372 | } | ||
373 | </pre></div><p>Function updateToolBox() is called each frame to update dynamic information in the toolbox. </p> | ||
374 | <div class="fragment"><pre class="fragment"><span class="keywordtype">void</span> updateToolBox() | ||
375 | { | ||
376 | IGUIEnvironment* env = Device->getGUIEnvironment(); | ||
377 | IGUIElement* root = env->getRootGUIElement(); | ||
378 | IGUIElement* dlg = root->getElementFromId(GUI_ID_DIALOG_ROOT_WINDOW, <span class="keyword">true</span>); | ||
379 | <span class="keywordflow">if</span> (!dlg ) | ||
380 | <span class="keywordflow">return</span>; | ||
381 | |||
382 | <span class="comment">// update the info we have about the animation of the model</span> | ||
383 | IGUIStaticText * aniInfo = (IGUIStaticText *)(dlg->getElementFromId(GUI_ID_ANIMATION_INFO, <span class="keyword">true</span>)); | ||
384 | <span class="keywordflow">if</span> (aniInfo) | ||
385 | { | ||
386 | <span class="keywordflow">if</span> ( Model && <a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda073d7fe9dfd49f24cb13bfae56d8d3b6" title="Animated Mesh Scene Node.">scene::ESNT_ANIMATED_MESH</a> == Model->getType() ) | ||
387 | { | ||
388 | scene::IAnimatedMeshSceneNode* animatedModel = (scene::IAnimatedMeshSceneNode*)Model; | ||
389 | |||
390 | <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str( (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)<a class="code" href="namespaceirr_1_1core.html#a894a901069c34298987761c5f3d74f1f">core::round_</a>(animatedModel->getAnimationSpeed()) ); | ||
391 | str += L<span class="stringliteral">" Frame: "</span>; | ||
392 | str += <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>((<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a>)animatedModel->getFrameNr()); | ||
393 | aniInfo->setText(str.c_str()); | ||
394 | } | ||
395 | <span class="keywordflow">else</span> | ||
396 | aniInfo->setText(L<span class="stringliteral">""</span>); | ||
397 | } | ||
398 | } | ||
399 | |||
400 | <span class="keywordtype">void</span> onKillFocus() | ||
401 | { | ||
402 | <span class="comment">// Avoid that the FPS-camera continues moving when the user presses alt-tab while </span> | ||
403 | <span class="comment">// moving the camera. </span> | ||
404 | <span class="keyword">const</span> core::list<scene::ISceneNodeAnimator*>& animators = Camera[1]->getAnimators(); | ||
405 | core::list<irr::scene::ISceneNodeAnimator*>::ConstIterator iter = animators.begin(); | ||
406 | <span class="keywordflow">while</span> ( iter != animators.end() ) | ||
407 | { | ||
408 | <span class="keywordflow">if</span> ( (*iter)->getType() == <a class="code" href="namespaceirr_1_1scene.html#a327a1e43872705cf8f3f3342fb307d19ae40c836272ace5bf243baaca72dba55c" title="FPS camera animator.">scene::ESNAT_CAMERA_FPS</a> ) | ||
409 | { | ||
410 | <span class="comment">// we send a key-down event for all keys used by this animator</span> | ||
411 | scene::ISceneNodeAnimatorCameraFPS * fpsAnimator = <span class="keyword">static_cast<</span>scene::ISceneNodeAnimatorCameraFPS*<span class="keyword">></span>(*iter); | ||
412 | <span class="keyword">const</span> core::array<SKeyMap>& keyMap = fpsAnimator->getKeyMap(); | ||
413 | <span class="keywordflow">for</span> ( <a class="code" href="namespaceirr.html#a0416a53257075833e7002efd0a18e804" title="32 bit unsigned variable.">irr::u32</a> i=0; i< keyMap.size(); ++i ) | ||
414 | { | ||
415 | <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...">irr::SEvent</a> event; | ||
416 | <span class="keyword">event</span>.<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.">EET_KEY_INPUT_EVENT</a>; | ||
417 | <span class="keyword">event</span>.KeyInput.Key = keyMap[i].KeyCode; | ||
418 | <span class="keyword">event</span>.KeyInput.PressedDown = <span class="keyword">false</span>; | ||
419 | fpsAnimator->OnEvent(event); | ||
420 | } | ||
421 | } | ||
422 | ++iter; | ||
423 | } | ||
424 | } | ||
425 | </pre></div><p>Function hasModalDialog() checks if we currently have a modal dialog open. </p> | ||
426 | <div class="fragment"><pre class="fragment"><span class="keywordtype">bool</span> hasModalDialog() | ||
427 | { | ||
428 | <span class="keywordflow">if</span> ( !Device ) | ||
429 | <span class="keywordflow">return</span> <span class="keyword">false</span>; | ||
430 | IGUIEnvironment* env = Device->getGUIEnvironment(); | ||
431 | IGUIElement * focused = env->getFocus(); | ||
432 | <span class="keywordflow">while</span> ( focused ) | ||
433 | { | ||
434 | <span class="keywordflow">if</span> ( focused->isVisible() && focused->hasType(<a class="code" href="namespaceirr_1_1gui.html#ae4d66df0ecf4117cdbcf9f22404bd254aabc2c9519ef201dce8bd898d2566e53b" title="A modal screen.">EGUIET_MODAL_SCREEN</a>) ) | ||
435 | <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
436 | focused = focused->getParent(); | ||
437 | } | ||
438 | <span class="keywordflow">return</span> <span class="keyword">false</span>; | ||
439 | } | ||
440 | </pre></div><p>To get all the events sent by the GUI Elements, we need to create an event receiver. This one is really simple. If an event occurs, it checks the id of the caller and the event type, and starts an action based on these values. For example, if a menu item with id GUI_ID_OPEN_MODEL was selected, it opens a file-open-dialog. </p> | ||
441 | <div class="fragment"><pre class="fragment"><span class="keyword">class </span>MyEventReceiver : <span class="keyword">public</span> IEventReceiver | ||
442 | { | ||
443 | <span class="keyword">public</span>: | ||
444 | <span class="keyword">virtual</span> <span class="keywordtype">bool</span> OnEvent(<span class="keyword">const</span> SEvent& event) | ||
445 | { | ||
446 | <span class="comment">// Escape swaps Camera Input</span> | ||
447 | <span class="keywordflow">if</span> (event.EventType == <a class="code" href="namespaceirr.html#ac9eed96e06e85ce3c86fcbbbe9e48a0ca6f90390f3147a1693e5e2e3422d6ca09" title="A key input event.">EET_KEY_INPUT_EVENT</a> && | ||
448 | event.KeyInput.PressedDown == <span class="keyword">false</span>) | ||
449 | { | ||
450 | <span class="keywordflow">if</span> ( OnKeyUp(event.KeyInput.Key) ) | ||
451 | <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
452 | } | ||
453 | |||
454 | <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>) | ||
455 | { | ||
456 | <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->getID(); | ||
457 | IGUIEnvironment* env = Device->getGUIEnvironment(); | ||
458 | |||
459 | <span class="keywordflow">switch</span>(event.GUIEvent.EventType) | ||
460 | { | ||
461 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a90e8bebdd49f2a2e451b1105a87ee7ef" title="A menu item was selected in a (context) menu.">EGET_MENU_ITEM_SELECTED</a>: | ||
462 | <span class="comment">// a menu item was clicked</span> | ||
463 | OnMenuItemSelected( (IGUIContextMenu*)event.GUIEvent.Caller ); | ||
464 | <span class="keywordflow">break</span>; | ||
465 | |||
466 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a5b6504cf6b541d5ad95407c384632873" title="A file has been selected in the file dialog.">EGET_FILE_SELECTED</a>: | ||
467 | { | ||
468 | <span class="comment">// load the model file, selected in the file open dialog</span> | ||
469 | IGUIFileOpenDialog* dialog = | ||
470 | (IGUIFileOpenDialog*)event.GUIEvent.Caller; | ||
471 | loadModel(<a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a>(dialog->getFileName()).c_str()); | ||
472 | } | ||
473 | <span class="keywordflow">break</span>; | ||
474 | |||
475 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a2eea536494edcde2bb2608bda9d352b2" title="A scrollbar has changed its position.">EGET_SCROLL_BAR_CHANGED</a>: | ||
476 | |||
477 | <span class="comment">// control skin transparency</span> | ||
478 | <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_SKIN_TRANSPARENCY) | ||
479 | { | ||
480 | <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); | ||
481 | setSkinTransparency(pos, env->getSkin()); | ||
482 | } | ||
483 | <span class="comment">// control animation speed</span> | ||
484 | <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_SKIN_ANIMATION_FPS) | ||
485 | { | ||
486 | <span class="keyword">const</span> <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); | ||
487 | <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1scene.html#acad3d7ef92a9807d391ba29120f3b7bda073d7fe9dfd49f24cb13bfae56d8d3b6" title="Animated Mesh Scene Node.">scene::ESNT_ANIMATED_MESH</a> == Model->getType()) | ||
488 | ((scene::IAnimatedMeshSceneNode*)Model)->setAnimationSpeed((<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)pos); | ||
489 | } | ||
490 | <span class="keywordflow">break</span>; | ||
491 | |||
492 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808aef7f9081622a71160e161c80eb07d436" title="The selection in a combo box has been changed.">EGET_COMBO_BOX_CHANGED</a>: | ||
493 | |||
494 | <span class="comment">// control anti-aliasing/filtering</span> | ||
495 | <span class="keywordflow">if</span> (<span class="keywordtype">id</span> == GUI_ID_TEXTUREFILTER) | ||
496 | { | ||
497 | OnTextureFilterSelected( (IGUIComboBox*)event.GUIEvent.Caller ); | ||
498 | } | ||
499 | <span class="keywordflow">break</span>; | ||
500 | |||
501 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1gui.html#aeac71ad17341a4b6e9026ae11d576808a308ee345c92444931f83e48354072d98" title="A button was clicked.">EGET_BUTTON_CLICKED</a>: | ||
502 | |||
503 | <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>) | ||
504 | { | ||
505 | <span class="keywordflow">case</span> GUI_ID_BUTTON_SET_SCALE: | ||
506 | { | ||
507 | <span class="comment">// set scale</span> | ||
508 | gui::IGUIElement* root = env->getRootGUIElement(); | ||
509 | <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a> scale; | ||
510 | <a class="code" href="namespaceirr_1_1core.html#ade1071a878633f2f6d8a75c5d11fec19" title="Typedef for character strings.">core::stringc</a> s; | ||
511 | |||
512 | s = root->getElementFromId(GUI_ID_X_SCALE, <span class="keyword">true</span>)->getText(); | ||
513 | scale.X = (<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str()); | ||
514 | s = root->getElementFromId(GUI_ID_Y_SCALE, <span class="keyword">true</span>)->getText(); | ||
515 | scale.Y = (<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str()); | ||
516 | s = root->getElementFromId(GUI_ID_Z_SCALE, <span class="keyword">true</span>)->getText(); | ||
517 | scale.Z = (<a class="code" href="namespaceirr.html#a0277be98d67dc26ff93b1a6a1d086b07" title="32 bit floating point variable.">f32</a>)atof(s.c_str()); | ||
518 | |||
519 | <span class="keywordflow">if</span> (Model) | ||
520 | Model->setScale(scale); | ||
521 | updateScaleInfo(Model); | ||
522 | } | ||
523 | <span class="keywordflow">break</span>; | ||
524 | <span class="keywordflow">case</span> GUI_ID_BUTTON_SCALE_MUL10: | ||
525 | <span class="keywordflow">if</span> (Model) | ||
526 | Model->setScale(Model->getScale()*10.f); | ||
527 | updateScaleInfo(Model); | ||
528 | <span class="keywordflow">break</span>; | ||
529 | <span class="keywordflow">case</span> GUI_ID_BUTTON_SCALE_DIV10: | ||
530 | <span class="keywordflow">if</span> (Model) | ||
531 | Model->setScale(Model->getScale()*0.1f); | ||
532 | updateScaleInfo(Model); | ||
533 | <span class="keywordflow">break</span>; | ||
534 | <span class="keywordflow">case</span> GUI_ID_BUTTON_OPEN_MODEL: | ||
535 | env->addFileOpenDialog(L<span class="stringliteral">"Please select a model file to open"</span>); | ||
536 | <span class="keywordflow">break</span>; | ||
537 | <span class="keywordflow">case</span> GUI_ID_BUTTON_SHOW_ABOUT: | ||
538 | showAboutText(); | ||
539 | <span class="keywordflow">break</span>; | ||
540 | <span class="keywordflow">case</span> GUI_ID_BUTTON_SHOW_TOOLBOX: | ||
541 | createToolBox(); | ||
542 | <span class="keywordflow">break</span>; | ||
543 | <span class="keywordflow">case</span> GUI_ID_BUTTON_SELECT_ARCHIVE: | ||
544 | env->addFileOpenDialog(L<span class="stringliteral">"Please select your game archive/directory"</span>); | ||
545 | <span class="keywordflow">break</span>; | ||
546 | } | ||
547 | |||
548 | <span class="keywordflow">break</span>; | ||
549 | <span class="keywordflow">default</span>: | ||
550 | <span class="keywordflow">break</span>; | ||
551 | } | ||
552 | } | ||
553 | |||
554 | <span class="keywordflow">return</span> <span class="keyword">false</span>; | ||
555 | } | ||
556 | </pre></div><p>Handle key-up events </p> | ||
557 | <div class="fragment"><pre class="fragment"> <span class="keywordtype">bool</span> OnKeyUp(<a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3">irr::EKEY_CODE</a> keyCode) | ||
558 | { | ||
559 | <span class="comment">// Don't handle keys if we have a modal dialog open as it would lead </span> | ||
560 | <span class="comment">// to unexpected application behaviour for the user.</span> | ||
561 | <span class="keywordflow">if</span> ( hasModalDialog() ) | ||
562 | <span class="keywordflow">return</span> <span class="keyword">false</span>; | ||
563 | |||
564 | <span class="keywordflow">if</span> (keyCode == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3aab32bfc194f119e5d5b9b39527bbcd61">irr::KEY_ESCAPE</a>) | ||
565 | { | ||
566 | <span class="keywordflow">if</span> (Device) | ||
567 | { | ||
568 | scene::ICameraSceneNode * camera = | ||
569 | Device->getSceneManager()->getActiveCamera(); | ||
570 | <span class="keywordflow">if</span> (camera) | ||
571 | { | ||
572 | camera->setInputReceiverEnabled( !camera->isInputReceiverEnabled() ); | ||
573 | } | ||
574 | <span class="keywordflow">return</span> <span class="keyword">true</span>; | ||
575 | } | ||
576 | } | ||
577 | <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a5427274e34fd5587155fe8b3b12d96a8">irr::KEY_F1</a>) | ||
578 | { | ||
579 | <span class="keywordflow">if</span> (Device) | ||
580 | { | ||
581 | IGUIElement* elem = Device->getGUIEnvironment()->getRootGUIElement()->getElementFromId(GUI_ID_POSITION_TEXT); | ||
582 | <span class="keywordflow">if</span> (elem) | ||
583 | elem->setVisible(!elem->isVisible()); | ||
584 | } | ||
585 | } | ||
586 | <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3a864770d5fa3f9713dc7a37f66f6b84fc">irr::KEY_KEY_M</a>) | ||
587 | { | ||
588 | <span class="keywordflow">if</span> (Device) | ||
589 | Device->minimizeWindow(); | ||
590 | } | ||
591 | <span class="keywordflow">else</span> <span class="keywordflow">if</span> (keyCode == <a class="code" href="namespaceirr.html#a54da2a0e231901735e3da1b0edf72eb3ae1f51392abd7c04d8129d2c85dbd391c">irr::KEY_KEY_L</a>) | ||
592 | { | ||
593 | UseLight=!UseLight; | ||
594 | <span class="keywordflow">if</span> (Model) | ||
595 | { | ||
596 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3acea597a2692b8415486a464a7f954d34" title="Will this material be lighted? Default: true.">video::EMF_LIGHTING</a>, UseLight); | ||
597 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a3efe2d4921909a842adfc44dacc74520" title="Normalizes normals. Default: false.">video::EMF_NORMALIZE_NORMALS</a>, UseLight); | ||
598 | } | ||
599 | } | ||
600 | <span class="keywordflow">return</span> <span class="keyword">false</span>; | ||
601 | } | ||
602 | </pre></div><p>Handle "menu item clicked" events. </p> | ||
603 | <div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> OnMenuItemSelected( IGUIContextMenu* menu ) | ||
604 | { | ||
605 | <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> <span class="keywordtype">id</span> = menu->getItemCommandId(menu->getSelectedItem()); | ||
606 | IGUIEnvironment* env = Device->getGUIEnvironment(); | ||
607 | |||
608 | <span class="keywordflow">switch</span>(<span class="keywordtype">id</span>) | ||
609 | { | ||
610 | <span class="keywordflow">case</span> GUI_ID_OPEN_MODEL: <span class="comment">// FilOnButtonSetScalinge -> Open Model</span> | ||
611 | env->addFileOpenDialog(L<span class="stringliteral">"Please select a model file to open"</span>); | ||
612 | <span class="keywordflow">break</span>; | ||
613 | <span class="keywordflow">case</span> GUI_ID_SET_MODEL_ARCHIVE: <span class="comment">// File -> Set Model Archive</span> | ||
614 | env->addFileOpenDialog(L<span class="stringliteral">"Please select your game archive/directory"</span>); | ||
615 | <span class="keywordflow">break</span>; | ||
616 | <span class="keywordflow">case</span> GUI_ID_LOAD_AS_OCTREE: <span class="comment">// File -> LoadAsOctree</span> | ||
617 | Octree = !Octree; | ||
618 | menu->setItemChecked(menu->getSelectedItem(), Octree); | ||
619 | <span class="keywordflow">break</span>; | ||
620 | <span class="keywordflow">case</span> GUI_ID_QUIT: <span class="comment">// File -> Quit</span> | ||
621 | Device->closeDevice(); | ||
622 | <span class="keywordflow">break</span>; | ||
623 | <span class="keywordflow">case</span> GUI_ID_SKY_BOX_VISIBLE: <span class="comment">// View -> Skybox</span> | ||
624 | menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem())); | ||
625 | SkyBox->setVisible(!SkyBox->isVisible()); | ||
626 | <span class="keywordflow">break</span>; | ||
627 | <span class="keywordflow">case</span> GUI_ID_DEBUG_OFF: <span class="comment">// View -> Debug Information</span> | ||
628 | menu->setItemChecked(menu->getSelectedItem()+1, <span class="keyword">false</span>); | ||
629 | menu->setItemChecked(menu->getSelectedItem()+2, <span class="keyword">false</span>); | ||
630 | menu->setItemChecked(menu->getSelectedItem()+3, <span class="keyword">false</span>); | ||
631 | menu->setItemChecked(menu->getSelectedItem()+4, <span class="keyword">false</span>); | ||
632 | menu->setItemChecked(menu->getSelectedItem()+5, <span class="keyword">false</span>); | ||
633 | menu->setItemChecked(menu->getSelectedItem()+6, <span class="keyword">false</span>); | ||
634 | <span class="keywordflow">if</span> (Model) | ||
635 | Model->setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea25111b15f03bee9a99498737286916dc" title="No Debug Data ( Default )">scene::EDS_OFF</a>); | ||
636 | <span class="keywordflow">break</span>; | ||
637 | <span class="keywordflow">case</span> GUI_ID_DEBUG_BOUNDING_BOX: <span class="comment">// View -> Debug Information</span> | ||
638 | menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem())); | ||
639 | <span class="keywordflow">if</span> (Model) | ||
640 | Model->setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model->isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea19e56bb3d3b18134fa63e0529629b427" title="Show Bounding Boxes of SceneNode.">scene::EDS_BBOX</a>)); | ||
641 | <span class="keywordflow">break</span>; | ||
642 | <span class="keywordflow">case</span> GUI_ID_DEBUG_NORMALS: <span class="comment">// View -> Debug Information</span> | ||
643 | menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem())); | ||
644 | <span class="keywordflow">if</span> (Model) | ||
645 | Model->setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model->isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea2713e470ee18ec9bfe40fdfb502f8b05" title="Show Vertex Normals.">scene::EDS_NORMALS</a>)); | ||
646 | <span class="keywordflow">break</span>; | ||
647 | <span class="keywordflow">case</span> GUI_ID_DEBUG_SKELETON: <span class="comment">// View -> Debug Information</span> | ||
648 | menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem())); | ||
649 | <span class="keywordflow">if</span> (Model) | ||
650 | Model->setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model->isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbeaa7664e189b8641ac54cf27f70f6d8144" title="Shows Skeleton/Tags.">scene::EDS_SKELETON</a>)); | ||
651 | <span class="keywordflow">break</span>; | ||
652 | <span class="keywordflow">case</span> GUI_ID_DEBUG_WIRE_OVERLAY: <span class="comment">// View -> Debug Information</span> | ||
653 | menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem())); | ||
654 | <span class="keywordflow">if</span> (Model) | ||
655 | Model->setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model->isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea349b086537ac770f09935af4e31d3f3e" title="Overlays Mesh Wireframe.">scene::EDS_MESH_WIRE_OVERLAY</a>)); | ||
656 | <span class="keywordflow">break</span>; | ||
657 | <span class="keywordflow">case</span> GUI_ID_DEBUG_HALF_TRANSPARENT: <span class="comment">// View -> Debug Information</span> | ||
658 | menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem())); | ||
659 | <span class="keywordflow">if</span> (Model) | ||
660 | Model->setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model->isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea1def9e1b7d86e286b07a4b7179e6ed85" title="Temporary use transparency Material Type.">scene::EDS_HALF_TRANSPARENCY</a>)); | ||
661 | <span class="keywordflow">break</span>; | ||
662 | <span class="keywordflow">case</span> GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES: <span class="comment">// View -> Debug Information</span> | ||
663 | menu->setItemChecked(menu->getSelectedItem(), !menu->isItemChecked(menu->getSelectedItem())); | ||
664 | <span class="keywordflow">if</span> (Model) | ||
665 | Model->setDebugDataVisible((<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbe" title="An enumeration for all types of debug data for built-in scene nodes (flags)">scene::E_DEBUG_SCENE_TYPE</a>)(Model->isDebugDataVisible()^<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea0179a3df80ac09143dfffed0bd9e99d1" title="Show Bounding Boxes of all MeshBuffers.">scene::EDS_BBOX_BUFFERS</a>)); | ||
666 | <span class="keywordflow">break</span>; | ||
667 | <span class="keywordflow">case</span> GUI_ID_DEBUG_ALL: <span class="comment">// View -> Debug Information</span> | ||
668 | menu->setItemChecked(menu->getSelectedItem()-1, <span class="keyword">true</span>); | ||
669 | menu->setItemChecked(menu->getSelectedItem()-2, <span class="keyword">true</span>); | ||
670 | menu->setItemChecked(menu->getSelectedItem()-3, <span class="keyword">true</span>); | ||
671 | menu->setItemChecked(menu->getSelectedItem()-4, <span class="keyword">true</span>); | ||
672 | menu->setItemChecked(menu->getSelectedItem()-5, <span class="keyword">true</span>); | ||
673 | menu->setItemChecked(menu->getSelectedItem()-6, <span class="keyword">true</span>); | ||
674 | <span class="keywordflow">if</span> (Model) | ||
675 | Model->setDebugDataVisible(<a class="code" href="namespaceirr_1_1scene.html#a52b664c4c988113735042b168fc32dbea24ffe5e6e99d589b3c80181e7c7dd4e2" title="Show all debug infos.">scene::EDS_FULL</a>); | ||
676 | <span class="keywordflow">break</span>; | ||
677 | <span class="keywordflow">case</span> GUI_ID_ABOUT: <span class="comment">// Help->About</span> | ||
678 | showAboutText(); | ||
679 | <span class="keywordflow">break</span>; | ||
680 | <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_SOLID: <span class="comment">// View -> Material -> Solid</span> | ||
681 | <span class="keywordflow">if</span> (Model) | ||
682 | Model->setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a9bc471b9c18c9e2d20496004d2a2e803" title="Standard solid material.">video::EMT_SOLID</a>); | ||
683 | <span class="keywordflow">break</span>; | ||
684 | <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_TRANSPARENT: <span class="comment">// View -> Material -> Transparent</span> | ||
685 | <span class="keywordflow">if</span> (Model) | ||
686 | Model->setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a1b5a814c4466aca2943ff056003a50d1" title="A transparent material.">video::EMT_TRANSPARENT_ADD_COLOR</a>); | ||
687 | <span class="keywordflow">break</span>; | ||
688 | <span class="keywordflow">case</span> GUI_ID_MODEL_MATERIAL_REFLECTION: <span class="comment">// View -> Material -> Reflection</span> | ||
689 | <span class="keywordflow">if</span> (Model) | ||
690 | Model->setMaterialType(<a class="code" href="namespaceirr_1_1video.html#ac8e9b6c66f7cebabd1a6d30cbc5430f1a42a8b6f5c933864ca104b3d46692c43b" title="Look like a reflection of the environment around it.">video::EMT_SPHERE_MAP</a>); | ||
691 | <span class="keywordflow">break</span>; | ||
692 | |||
693 | <span class="keywordflow">case</span> GUI_ID_CAMERA_MAYA: | ||
694 | setActiveCamera(Camera[0]); | ||
695 | <span class="keywordflow">break</span>; | ||
696 | <span class="keywordflow">case</span> GUI_ID_CAMERA_FIRST_PERSON: | ||
697 | setActiveCamera(Camera[1]); | ||
698 | <span class="keywordflow">break</span>; | ||
699 | } | ||
700 | } | ||
701 | </pre></div><p>Handle the event that one of the texture-filters was selected in the corresponding combobox. </p> | ||
702 | <div class="fragment"><pre class="fragment"> <span class="keywordtype">void</span> OnTextureFilterSelected( IGUIComboBox* combo ) | ||
703 | { | ||
704 | <a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> pos = combo->getSelected(); | ||
705 | <span class="keywordflow">switch</span> (pos) | ||
706 | { | ||
707 | <span class="keywordflow">case</span> 0: | ||
708 | <span class="keywordflow">if</span> (Model) | ||
709 | { | ||
710 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3afbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">false</span>); | ||
711 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a7a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">false</span>); | ||
712 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">false</span>); | ||
713 | } | ||
714 | <span class="keywordflow">break</span>; | ||
715 | <span class="keywordflow">case</span> 1: | ||
716 | <span class="keywordflow">if</span> (Model) | ||
717 | { | ||
718 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3afbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">true</span>); | ||
719 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a7a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">false</span>); | ||
720 | } | ||
721 | <span class="keywordflow">break</span>; | ||
722 | <span class="keywordflow">case</span> 2: | ||
723 | <span class="keywordflow">if</span> (Model) | ||
724 | { | ||
725 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3afbf2b289d416e70466e4ab05e97b4934" title="Is bilinear filtering enabled? Default: true.">video::EMF_BILINEAR_FILTER</a>, <span class="keyword">false</span>); | ||
726 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a7a2ed21d879b182fbc767a4c20d72eef" title="Is trilinear filtering enabled? Default: false.">video::EMF_TRILINEAR_FILTER</a>, <span class="keyword">true</span>); | ||
727 | } | ||
728 | <span class="keywordflow">break</span>; | ||
729 | <span class="keywordflow">case</span> 3: | ||
730 | <span class="keywordflow">if</span> (Model) | ||
731 | { | ||
732 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">true</span>); | ||
733 | } | ||
734 | <span class="keywordflow">break</span>; | ||
735 | <span class="keywordflow">case</span> 4: | ||
736 | <span class="keywordflow">if</span> (Model) | ||
737 | { | ||
738 | Model->setMaterialFlag(<a class="code" href="namespaceirr_1_1video.html#a8a3bc00ae8137535b9fbc5f40add70d3a941c0756b9dc3f987a183a401c6fd4ad" title="Is anisotropic filtering? Default: false.">video::EMF_ANISOTROPIC_FILTER</a>, <span class="keyword">false</span>); | ||
739 | } | ||
740 | <span class="keywordflow">break</span>; | ||
741 | } | ||
742 | } | ||
743 | }; | ||
744 | </pre></div><p>Most of the hard work is done. We only need to create the Irrlicht Engine device and all the buttons, menus and toolbars. We start up the engine as usual, using <a class="el" href="namespaceirr.html#abaf4d8719cc26b0d30813abf85e47c76" title="Creates an Irrlicht device. The Irrlicht device is the root object for using the engine.">createDevice()</a>. To make our application catch events, we set our eventreceiver as parameter. As you can see, there is also a call to IrrlichtDevice::setResizeable(). This makes the render window resizeable, which is quite useful for a mesh viewer. </p> | ||
745 | <div class="fragment"><pre class="fragment"><span class="keywordtype">int</span> main(<span class="keywordtype">int</span> argc, <span class="keywordtype">char</span>* argv[]) | ||
746 | { | ||
747 | <span class="comment">// ask user for driver</span> | ||
748 | <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(); | ||
749 | <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>) | ||
750 | <span class="keywordflow">return</span> 1; | ||
751 | |||
752 | <span class="comment">// create device and exit if creation failed</span> | ||
753 | MyEventReceiver receiver; | ||
754 | 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, core::dimension2d<u32>(800, 600), | ||
755 | 16, <span class="keyword">false</span>, <span class="keyword">false</span>, <span class="keyword">false</span>, &receiver); | ||
756 | |||
757 | <span class="keywordflow">if</span> (Device == 0) | ||
758 | <span class="keywordflow">return</span> 1; <span class="comment">// could not create selected driver.</span> | ||
759 | |||
760 | Device->setResizable(<span class="keyword">true</span>); | ||
761 | |||
762 | Device->setWindowCaption(L<span class="stringliteral">"Irrlicht Engine - Loading..."</span>); | ||
763 | |||
764 | video::IVideoDriver* driver = Device->getVideoDriver(); | ||
765 | IGUIEnvironment* env = Device->getGUIEnvironment(); | ||
766 | scene::ISceneManager* smgr = Device->getSceneManager(); | ||
767 | smgr->getParameters()->setAttribute(<a class="code" href="namespaceirr_1_1scene.html#a157681b3ef101a801ce278e6f21de946" title="Name of the parameter specifying the COLLADA mesh loading mode.">scene::COLLADA_CREATE_SCENE_INSTANCES</a>, <span class="keyword">true</span>); | ||
768 | |||
769 | driver->setTextureCreationFlag(<a class="code" href="namespaceirr_1_1video.html#acaf6f7414534f7d62bff18c5bf11876fa20881e307a778c4a4fbb5327a60a93bb">video::ETCF_ALWAYS_32_BIT</a>, <span class="keyword">true</span>); | ||
770 | |||
771 | smgr->addLightSceneNode(0, <a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(200,200,200), | ||
772 | video::SColorf(1.0f,1.0f,1.0f),2000); | ||
773 | smgr->setAmbientLight(video::SColorf(0.3f,0.3f,0.3f)); | ||
774 | <span class="comment">// add our media directory as "search path"</span> | ||
775 | Device->getFileSystem()->addFileArchive(<span class="stringliteral">"../../media/"</span>); | ||
776 | </pre></div><p>The next step is to read the configuration file. It is stored in the xml format and looks a little bit like this:</p> | ||
777 | <div class="fragment"><pre class="fragment"> | ||
778 | <?xml version="1.0"?> | ||
779 | <config> | ||
780 | <startUpModel file="some filename" /> | ||
781 | <messageText caption="Irrlicht Engine Mesh Viewer"> | ||
782 | Hello! | ||
783 | </messageText> | ||
784 | </config> | ||
785 | </pre></div><p>We need the data stored in there to be written into the global variables StartUpModelFile, MessageText and Caption. This is now done using the Irrlicht Engine integrated XML parser: </p> | ||
786 | <div class="fragment"><pre class="fragment"> <span class="comment">// read configuration from xml file</span> | ||
787 | |||
788 | <a class="code" href="namespaceirr_1_1io.html#a9dc6291fb7e4c73155a3e3c8339f9bff" title="An xml reader for wide characters, derived from IReferenceCounted.">io::IXMLReader</a>* xml = Device->getFileSystem()->createXMLReader( L<span class="stringliteral">"config.xml"</span>); | ||
789 | |||
790 | <span class="keywordflow">while</span>(xml && xml->read()) | ||
791 | { | ||
792 | <span class="keywordflow">switch</span>(xml->getNodeType()) | ||
793 | { | ||
794 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1io.html#a86a02676c9cbb822e04d60c81b4f33eda0edf973f8ca0f6097f69369539d432a4">io::EXN_TEXT</a>: | ||
795 | <span class="comment">// in this xml file, the only text which occurs is the</span> | ||
796 | <span class="comment">// messageText</span> | ||
797 | MessageText = xml->getNodeData(); | ||
798 | <span class="keywordflow">break</span>; | ||
799 | <span class="keywordflow">case</span> <a class="code" href="namespaceirr_1_1io.html#a86a02676c9cbb822e04d60c81b4f33eda9df4f5baccc23a0ad1f6fa64d8de2fc0" title="An xml element such as <foo>.">io::EXN_ELEMENT</a>: | ||
800 | { | ||
801 | <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(<span class="stringliteral">"startUpModel"</span>) == xml->getNodeName()) | ||
802 | StartUpModelFile = xml->getAttributeValue(L<span class="stringliteral">"file"</span>); | ||
803 | <span class="keywordflow">else</span> | ||
804 | <span class="keywordflow">if</span> (<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(<span class="stringliteral">"messageText"</span>) == xml->getNodeName()) | ||
805 | Caption = xml->getAttributeValue(L<span class="stringliteral">"caption"</span>); | ||
806 | } | ||
807 | <span class="keywordflow">break</span>; | ||
808 | <span class="keywordflow">default</span>: | ||
809 | <span class="keywordflow">break</span>; | ||
810 | } | ||
811 | } | ||
812 | |||
813 | <span class="keywordflow">if</span> (xml) | ||
814 | xml->drop(); <span class="comment">// don't forget to delete the xml reader</span> | ||
815 | |||
816 | <span class="keywordflow">if</span> (argc > 1) | ||
817 | StartUpModelFile = argv[1]; | ||
818 | </pre></div><p>That wasn't difficult. Now we'll set a nicer font and create the Menu. It is possible to create submenus for every menu item. The call menu->addItem(L"File", -1, true, true); for example adds a new menu Item with the name "File" and the id -1. The following parameter says that the menu item should be enabled, and the last one says, that there should be a submenu. The submenu can now be accessed with menu->getSubMenu(0), because the "File" entry is the menu item with index 0. </p> | ||
819 | <div class="fragment"><pre class="fragment"> <span class="comment">// set a nicer font</span> | ||
820 | |||
821 | IGUISkin* skin = env->getSkin(); | ||
822 | IGUIFont* font = env-><a class="code" href="classirr_1_1gui_1_1_i_g_u_i_skin.html#ab1b2623d04688c4dfe106ca407171d6e" title="returns the default font">getFont</a>(<span class="stringliteral">"fonthaettenschweiler.bmp"</span>); | ||
823 | <span class="keywordflow">if</span> (font) | ||
824 | skin->setFont(font); | ||
825 | |||
826 | <span class="comment">// create menu</span> | ||
827 | gui::IGUIContextMenu* menu = env->addMenu(); | ||
828 | menu->addItem(L<span class="stringliteral">"File"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>); | ||
829 | menu->addItem(L<span class="stringliteral">"View"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>); | ||
830 | menu->addItem(L<span class="stringliteral">"Camera"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>); | ||
831 | menu->addItem(L<span class="stringliteral">"Help"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span>); | ||
832 | |||
833 | gui::IGUIContextMenu* submenu; | ||
834 | submenu = menu->getSubMenu(0); | ||
835 | submenu->addItem(L<span class="stringliteral">"Open Model File & Texture..."</span>, GUI_ID_OPEN_MODEL); | ||
836 | submenu->addItem(L<span class="stringliteral">"Set Model Archive..."</span>, GUI_ID_SET_MODEL_ARCHIVE); | ||
837 | submenu->addItem(L<span class="stringliteral">"Load as Octree"</span>, GUI_ID_LOAD_AS_OCTREE); | ||
838 | submenu->addSeparator(); | ||
839 | submenu->addItem(L<span class="stringliteral">"Quit"</span>, GUI_ID_QUIT); | ||
840 | |||
841 | submenu = menu->getSubMenu(1); | ||
842 | submenu->addItem(L<span class="stringliteral">"sky box visible"</span>, GUI_ID_SKY_BOX_VISIBLE, <span class="keyword">true</span>, <span class="keyword">false</span>, <span class="keyword">true</span>); | ||
843 | submenu->addItem(L<span class="stringliteral">"toggle model debug information"</span>, GUI_ID_TOGGLE_DEBUG_INFO, <span class="keyword">true</span>, <span class="keyword">true</span>); | ||
844 | submenu->addItem(L<span class="stringliteral">"model material"</span>, -1, <span class="keyword">true</span>, <span class="keyword">true</span> ); | ||
845 | |||
846 | submenu = submenu->getSubMenu(1); | ||
847 | submenu->addItem(L<span class="stringliteral">"Off"</span>, GUI_ID_DEBUG_OFF); | ||
848 | submenu->addItem(L<span class="stringliteral">"Bounding Box"</span>, GUI_ID_DEBUG_BOUNDING_BOX); | ||
849 | submenu->addItem(L<span class="stringliteral">"Normals"</span>, GUI_ID_DEBUG_NORMALS); | ||
850 | submenu->addItem(L<span class="stringliteral">"Skeleton"</span>, GUI_ID_DEBUG_SKELETON); | ||
851 | submenu->addItem(L<span class="stringliteral">"Wire overlay"</span>, GUI_ID_DEBUG_WIRE_OVERLAY); | ||
852 | submenu->addItem(L<span class="stringliteral">"Half-Transparent"</span>, GUI_ID_DEBUG_HALF_TRANSPARENT); | ||
853 | submenu->addItem(L<span class="stringliteral">"Buffers bounding boxes"</span>, GUI_ID_DEBUG_BUFFERS_BOUNDING_BOXES); | ||
854 | submenu->addItem(L<span class="stringliteral">"All"</span>, GUI_ID_DEBUG_ALL); | ||
855 | |||
856 | submenu = menu->getSubMenu(1)->getSubMenu(2); | ||
857 | submenu->addItem(L<span class="stringliteral">"Solid"</span>, GUI_ID_MODEL_MATERIAL_SOLID); | ||
858 | submenu->addItem(L<span class="stringliteral">"Transparent"</span>, GUI_ID_MODEL_MATERIAL_TRANSPARENT); | ||
859 | submenu->addItem(L<span class="stringliteral">"Reflection"</span>, GUI_ID_MODEL_MATERIAL_REFLECTION); | ||
860 | |||
861 | submenu = menu->getSubMenu(2); | ||
862 | submenu->addItem(L<span class="stringliteral">"Maya Style"</span>, GUI_ID_CAMERA_MAYA); | ||
863 | submenu->addItem(L<span class="stringliteral">"First Person"</span>, GUI_ID_CAMERA_FIRST_PERSON); | ||
864 | |||
865 | submenu = menu->getSubMenu(3); | ||
866 | submenu->addItem(L<span class="stringliteral">"About"</span>, GUI_ID_ABOUT); | ||
867 | </pre></div><p>Below the menu we want a toolbar, onto which we can place colored buttons and important looking stuff like a senseless combobox. </p> | ||
868 | <div class="fragment"><pre class="fragment"> <span class="comment">// create toolbar</span> | ||
869 | |||
870 | gui::IGUIToolBar* bar = env->addToolBar(); | ||
871 | |||
872 | video::ITexture* image = driver->getTexture(<span class="stringliteral">"open.png"</span>); | ||
873 | bar->addButton(GUI_ID_BUTTON_OPEN_MODEL, 0, L<span class="stringliteral">"Open a model"</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>); | ||
874 | |||
875 | image = driver->getTexture(<span class="stringliteral">"tools.png"</span>); | ||
876 | bar->addButton(GUI_ID_BUTTON_SHOW_TOOLBOX, 0, L<span class="stringliteral">"Open Toolset"</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>); | ||
877 | |||
878 | image = driver->getTexture(<span class="stringliteral">"zip.png"</span>); | ||
879 | bar->addButton(GUI_ID_BUTTON_SELECT_ARCHIVE, 0, L<span class="stringliteral">"Set Model Archive"</span>,image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>); | ||
880 | |||
881 | image = driver->getTexture(<span class="stringliteral">"help.png"</span>); | ||
882 | bar->addButton(GUI_ID_BUTTON_SHOW_ABOUT, 0, L<span class="stringliteral">"Open Help"</span>, image, 0, <span class="keyword">false</span>, <span class="keyword">true</span>); | ||
883 | |||
884 | <span class="comment">// create a combobox for texture filters</span> | ||
885 | |||
886 | gui::IGUIComboBox* box = env->addComboBox(core::rect<s32>(250,4,350,23), bar, GUI_ID_TEXTUREFILTER); | ||
887 | box->addItem(L<span class="stringliteral">"No filtering"</span>); | ||
888 | box->addItem(L<span class="stringliteral">"Bilinear"</span>); | ||
889 | box->addItem(L<span class="stringliteral">"Trilinear"</span>); | ||
890 | box->addItem(L<span class="stringliteral">"Anisotropic"</span>); | ||
891 | box->addItem(L<span class="stringliteral">"Isotropic"</span>); | ||
892 | </pre></div><p>To make the editor look a little bit better, we disable transparent gui elements, and add an Irrlicht Engine logo. In addition, a text showing the current frames per second value is created and the window caption is changed. </p> | ||
893 | <div class="fragment"><pre class="fragment"> <span class="comment">// disable alpha</span> | ||
894 | |||
895 | <span class="keywordflow">for</span> (<a class="code" href="namespaceirr.html#ac66849b7a6ed16e30ebede579f9b47c6" title="32 bit signed variable.">s32</a> i=0; i<<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467aaf340f49e2e0827c0f06fdf65098554af">gui::EGDC_COUNT</a> ; ++i) | ||
896 | { | ||
897 | video::SColor col = env->getSkin()->getColor((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">gui::EGUI_DEFAULT_COLOR</a>)i); | ||
898 | col.setAlpha(255); | ||
899 | env->getSkin()->setColor((<a class="code" href="namespaceirr_1_1gui.html#abd15860fde29833c48daff5f95d5467a" title="Enumeration for skin colors.">gui::EGUI_DEFAULT_COLOR</a>)i, col); | ||
900 | } | ||
901 | |||
902 | <span class="comment">// add a tabcontrol</span> | ||
903 | |||
904 | createToolBox(); | ||
905 | |||
906 | <span class="comment">// create fps text</span> | ||
907 | |||
908 | IGUIStaticText* fpstext = env->addStaticText(L<span class="stringliteral">""</span>, | ||
909 | core::rect<s32>(400,4,570,23), <span class="keyword">true</span>, <span class="keyword">false</span>, bar); | ||
910 | |||
911 | IGUIStaticText* postext = env->addStaticText(L<span class="stringliteral">""</span>, | ||
912 | core::rect<s32>(10,50,470,80),<span class="keyword">false</span>, <span class="keyword">false</span>, 0, GUI_ID_POSITION_TEXT); | ||
913 | postext->setVisible(<span class="keyword">false</span>); | ||
914 | |||
915 | <span class="comment">// set window caption</span> | ||
916 | |||
917 | Caption += <span class="stringliteral">" - ["</span>; | ||
918 | Caption += driver->getName(); | ||
919 | Caption += <span class="stringliteral">"]"</span>; | ||
920 | Device->setWindowCaption(Caption.c_str()); | ||
921 | </pre></div><p>That's nearly the whole application. We simply show the about message box at start up, and load the first model. To make everything look better, a skybox is created and a user controlled camera, to make the application a little bit more interactive. Finally, everything is drawn in a standard drawing loop. </p> | ||
922 | <div class="fragment"><pre class="fragment"> <span class="comment">// show about message box and load default model</span> | ||
923 | <span class="keywordflow">if</span> (argc==1) | ||
924 | showAboutText(); | ||
925 | loadModel(StartUpModelFile.c_str()); | ||
926 | |||
927 | <span class="comment">// add skybox</span> | ||
928 | |||
929 | SkyBox = smgr->addSkyBoxSceneNode( | ||
930 | driver->getTexture(<span class="stringliteral">"irrlicht2_up.jpg"</span>), | ||
931 | driver->getTexture(<span class="stringliteral">"irrlicht2_dn.jpg"</span>), | ||
932 | driver->getTexture(<span class="stringliteral">"irrlicht2_lf.jpg"</span>), | ||
933 | driver->getTexture(<span class="stringliteral">"irrlicht2_rt.jpg"</span>), | ||
934 | driver->getTexture(<span class="stringliteral">"irrlicht2_ft.jpg"</span>), | ||
935 | driver->getTexture(<span class="stringliteral">"irrlicht2_bk.jpg"</span>)); | ||
936 | |||
937 | <span class="comment">// add a camera scene node</span> | ||
938 | Camera[0] = smgr->addCameraSceneNodeMaya(); | ||
939 | Camera[0]->setFarValue(20000.f); | ||
940 | <span class="comment">// Maya cameras reposition themselves relative to their target, so target the location</span> | ||
941 | <span class="comment">// where the mesh scene node is placed.</span> | ||
942 | Camera[0]->setTarget(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,30,0)); | ||
943 | |||
944 | Camera[1] = smgr->addCameraSceneNodeFPS(); | ||
945 | Camera[1]->setFarValue(20000.f); | ||
946 | Camera[1]->setPosition(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,0,-70)); | ||
947 | Camera[1]->setTarget(<a class="code" href="namespaceirr_1_1core.html#a06f169d08b5c429f5575acb7edbad811" title="Typedef for a f32 3d vector.">core::vector3df</a>(0,30,0)); | ||
948 | |||
949 | setActiveCamera(Camera[0]); | ||
950 | |||
951 | <span class="comment">// load the irrlicht engine logo</span> | ||
952 | IGUIImage *img = | ||
953 | env->addImage(driver->getTexture(<span class="stringliteral">"irrlichtlogo2.png"</span>), | ||
954 | core::position2d<s32>(10, driver->getScreenSize().Height - 128)); | ||
955 | |||
956 | <span class="comment">// lock the logo's edges to the bottom left corner of the screen</span> | ||
957 | img->setAlignment(<a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da4bb8a01452727274e18047a872da1809" title="Aligned to parent's top or left side (default)">EGUIA_UPPERLEFT</a>, <a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da4bb8a01452727274e18047a872da1809" title="Aligned to parent's top or left side (default)">EGUIA_UPPERLEFT</a>, | ||
958 | <a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da48b4d042b2d6cd63b876cef62c9cfb97" title="Aligned to parent's bottom or right side.">EGUIA_LOWERRIGHT</a>, <a class="code" href="namespaceirr_1_1gui.html#a19eb5fb40e67f108cb16aba922ddaa2da48b4d042b2d6cd63b876cef62c9cfb97" title="Aligned to parent's bottom or right side.">EGUIA_LOWERRIGHT</a>); | ||
959 | |||
960 | <span class="comment">// remember state so we notice when the window does lose the focus</span> | ||
961 | <span class="keywordtype">bool</span> hasFocus = Device->isWindowFocused(); | ||
962 | |||
963 | <span class="comment">// draw everything</span> | ||
964 | |||
965 | <span class="keywordflow">while</span>(Device->run() && driver) | ||
966 | { | ||
967 | <span class="comment">// Catch focus changes (workaround until Irrlicht has events for this)</span> | ||
968 | <span class="keywordtype">bool</span> focused = Device->isWindowFocused(); | ||
969 | <span class="keywordflow">if</span> ( hasFocus && !focused ) | ||
970 | onKillFocus(); | ||
971 | hasFocus = focused; | ||
972 | |||
973 | <span class="keywordflow">if</span> (Device->isWindowActive()) | ||
974 | { | ||
975 | driver->beginScene(<span class="keyword">true</span>, <span class="keyword">true</span>, video::SColor(150,50,50,50)); | ||
976 | |||
977 | smgr->drawAll(); | ||
978 | env->drawAll(); | ||
979 | |||
980 | driver->endScene(); | ||
981 | |||
982 | <span class="comment">// update information about current frame-rate</span> | ||
983 | <a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a> str(L<span class="stringliteral">"FPS: "</span>); | ||
984 | str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(driver->getFPS())); | ||
985 | str += L<span class="stringliteral">" Tris: "</span>; | ||
986 | str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(driver->getPrimitiveCountDrawn())); | ||
987 | fpstext->setText(str.c_str()); | ||
988 | |||
989 | <span class="comment">// update information about the active camera</span> | ||
990 | scene::ICameraSceneNode* cam = Device->getSceneManager()->getActiveCamera(); | ||
991 | str = L<span class="stringliteral">"Pos: "</span>; | ||
992 | str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam->getPosition().X)); | ||
993 | str += L<span class="stringliteral">" "</span>; | ||
994 | str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam->getPosition().Y)); | ||
995 | str += L<span class="stringliteral">" "</span>; | ||
996 | str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam->getPosition().Z)); | ||
997 | str += L<span class="stringliteral">" Tgt: "</span>; | ||
998 | str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam->getTarget().X)); | ||
999 | str += L<span class="stringliteral">" "</span>; | ||
1000 | str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam->getTarget().Y)); | ||
1001 | str += L<span class="stringliteral">" "</span>; | ||
1002 | str.append(<a class="code" href="namespaceirr_1_1core.html#aef83fafbb1b36fcce44c07c9be23a7f2" title="Typedef for wide character strings.">core::stringw</a>(cam->getTarget().Z)); | ||
1003 | postext->setText(str.c_str()); | ||
1004 | |||
1005 | <span class="comment">// update the tool dialog</span> | ||
1006 | updateToolBox(); | ||
1007 | } | ||
1008 | <span class="keywordflow">else</span> | ||
1009 | Device->yield(); | ||
1010 | } | ||
1011 | |||
1012 | Device->drop(); | ||
1013 | <span class="keywordflow">return</span> 0; | ||
1014 | } | ||
1015 | </pre></div> </div></div> | ||
1016 | </div> | ||
1017 | <div id="nav-path" class="navpath"> | ||
1018 | <ul> | ||
1019 | <!-- window showing the filter options --> | ||
1020 | <div id="MSearchSelectWindow" | ||
1021 | onmouseover="return searchBox.OnSearchSelectShow()" | ||
1022 | onmouseout="return searchBox.OnSearchSelectHide()" | ||
1023 | onkeydown="return searchBox.OnSearchSelectKey(event)"> | ||
1024 | <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> | ||
1025 | |||
1026 | <!-- iframe showing the search results (closed by default) --> | ||
1027 | <div id="MSearchResultsWindow"> | ||
1028 | <iframe src="javascript:void(0)" frameborder="0" | ||
1029 | name="MSearchResults" id="MSearchResults"> | ||
1030 | </iframe> | ||
1031 | </div> | ||
1032 | |||
1033 | |||
1034 | <li class="footer"> | ||
1035 | <a href="http://irrlicht.sourceforge.net" target="_blank">Irrlicht | ||
1036 | Engine</a> Documentation © 2003-2012 by Nikolaus Gebhardt. Generated on Tue Nov 6 2012 11:06:01 for Irrlicht 3D Engine by | ||
1037 | <a href="http://www.doxygen.org/index.html" target="_blank">Doxygen</a> 1.7.5.1 </li> | ||
1038 | </ul> | ||
1039 | </div> | ||
1040 | |||
1041 | |||
1042 | </body> | ||
1043 | </html> | ||