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