diff options
Diffstat (limited to 'libraries/irrlicht-1.8/examples/17.HelloWorld_Mobile/main.cpp')
-rw-r--r-- | libraries/irrlicht-1.8/examples/17.HelloWorld_Mobile/main.cpp | 1006 |
1 files changed, 503 insertions, 503 deletions
diff --git a/libraries/irrlicht-1.8/examples/17.HelloWorld_Mobile/main.cpp b/libraries/irrlicht-1.8/examples/17.HelloWorld_Mobile/main.cpp index 4fc15cd..0c7840d 100644 --- a/libraries/irrlicht-1.8/examples/17.HelloWorld_Mobile/main.cpp +++ b/libraries/irrlicht-1.8/examples/17.HelloWorld_Mobile/main.cpp | |||
@@ -1,503 +1,503 @@ | |||
1 | /** Example 017 Helloworld mobile | 1 | /** Example 017 Helloworld mobile |
2 | This example show Hello World for Windows mobile. | 2 | This example show Hello World for Windows mobile. |
3 | It compiles on other platform too. The only differences between the original | 3 | It compiles on other platform too. The only differences between the original |
4 | examples are. You need a GUI, because otherwise you can't quit the application. | 4 | examples are. You need a GUI, because otherwise you can't quit the application. |
5 | You need a Filesystem, which is relative based to your executable. | 5 | You need a Filesystem, which is relative based to your executable. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <irrlicht.h> | 8 | #include <irrlicht.h> |
9 | 9 | ||
10 | #if defined ( _IRR_WINDOWS_ ) | 10 | #if defined ( _IRR_WINDOWS_ ) |
11 | #include <windows.h> | 11 | #include <windows.h> |
12 | #endif | 12 | #endif |
13 | 13 | ||
14 | using namespace irr; | 14 | using namespace irr; |
15 | using namespace core; | 15 | using namespace core; |
16 | using namespace scene; | 16 | using namespace scene; |
17 | using namespace video; | 17 | using namespace video; |
18 | using namespace io; | 18 | using namespace io; |
19 | using namespace gui; | 19 | using namespace gui; |
20 | 20 | ||
21 | #pragma comment(lib, "Irrlicht.lib") | 21 | #pragma comment(lib, "Irrlicht.lib") |
22 | 22 | ||
23 | class EventReceiver_basic : public IEventReceiver | 23 | class EventReceiver_basic : public IEventReceiver |
24 | { | 24 | { |
25 | private: | 25 | private: |
26 | IrrlichtDevice *Device; | 26 | IrrlichtDevice *Device; |
27 | public: | 27 | public: |
28 | EventReceiver_basic ( IrrlichtDevice *device ): Device ( device ) {} | 28 | EventReceiver_basic ( IrrlichtDevice *device ): Device ( device ) {} |
29 | 29 | ||
30 | virtual bool OnEvent(const SEvent& event) | 30 | virtual bool OnEvent(const SEvent& event) |
31 | { | 31 | { |
32 | if (event.EventType == EET_GUI_EVENT) | 32 | if (event.EventType == EET_GUI_EVENT) |
33 | { | 33 | { |
34 | s32 id = event.GUIEvent.Caller->getID(); | 34 | s32 id = event.GUIEvent.Caller->getID(); |
35 | 35 | ||
36 | switch(event.GUIEvent.EventType) | 36 | switch(event.GUIEvent.EventType) |
37 | { | 37 | { |
38 | case EGET_BUTTON_CLICKED: | 38 | case EGET_BUTTON_CLICKED: |
39 | if (id == 2) | 39 | if (id == 2) |
40 | { | 40 | { |
41 | Device->closeDevice(); | 41 | Device->closeDevice(); |
42 | return true; | 42 | return true; |
43 | } break; | 43 | } break; |
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
47 | return false; | 47 | return false; |
48 | } | 48 | } |
49 | }; | 49 | }; |
50 | 50 | ||
51 | class CSampleSceneNode : public ISceneNode | 51 | class CSampleSceneNode : public ISceneNode |
52 | { | 52 | { |
53 | aabbox3d<f32> Box; | 53 | aabbox3d<f32> Box; |
54 | S3DVertex Vertices[4]; | 54 | S3DVertex Vertices[4]; |
55 | SMaterial Material; | 55 | SMaterial Material; |
56 | public: | 56 | public: |
57 | 57 | ||
58 | CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id) | 58 | CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id) |
59 | : ISceneNode(parent, mgr, id) | 59 | : ISceneNode(parent, mgr, id) |
60 | { | 60 | { |
61 | Material.Wireframe = false; | 61 | Material.Wireframe = false; |
62 | Material.Lighting = false; | 62 | Material.Lighting = false; |
63 | 63 | ||
64 | Vertices[0] = S3DVertex(0,0,10, 1,1,0, SColor(255,0,255,255), 0, 1); | 64 | Vertices[0] = S3DVertex(0,0,10, 1,1,0, SColor(255,0,255,255), 0, 1); |
65 | Vertices[1] = S3DVertex(10,0,-10, 1,0,0, SColor(255,255,0,255), 1, 1); | 65 | Vertices[1] = S3DVertex(10,0,-10, 1,0,0, SColor(255,255,0,255), 1, 1); |
66 | Vertices[2] = S3DVertex(0,20,0, 0,1,1, SColor(255,255,255,0), 1, 0); | 66 | Vertices[2] = S3DVertex(0,20,0, 0,1,1, SColor(255,255,255,0), 1, 0); |
67 | Vertices[3] = S3DVertex(-10,0,-10, 0,0,1, SColor(255,0,255,0), 0, 0); | 67 | Vertices[3] = S3DVertex(-10,0,-10, 0,0,1, SColor(255,0,255,0), 0, 0); |
68 | Box.reset(Vertices[0].Pos); | 68 | Box.reset(Vertices[0].Pos); |
69 | for (s32 i=1; i<4; ++i) | 69 | for (s32 i=1; i<4; ++i) |
70 | Box.addInternalPoint(Vertices[i].Pos); | 70 | Box.addInternalPoint(Vertices[i].Pos); |
71 | } | 71 | } |
72 | virtual void OnRegisterSceneNode() | 72 | virtual void OnRegisterSceneNode() |
73 | { | 73 | { |
74 | if (IsVisible) | 74 | if (IsVisible) |
75 | SceneManager->registerNodeForRendering(this); | 75 | SceneManager->registerNodeForRendering(this); |
76 | 76 | ||
77 | ISceneNode::OnRegisterSceneNode(); | 77 | ISceneNode::OnRegisterSceneNode(); |
78 | } | 78 | } |
79 | 79 | ||
80 | virtual void render() | 80 | virtual void render() |
81 | { | 81 | { |
82 | u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 }; | 82 | u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 }; |
83 | IVideoDriver* driver = SceneManager->getVideoDriver(); | 83 | IVideoDriver* driver = SceneManager->getVideoDriver(); |
84 | 84 | ||
85 | driver->setMaterial(Material); | 85 | driver->setMaterial(Material); |
86 | driver->setTransform(ETS_WORLD, AbsoluteTransformation); | 86 | driver->setTransform(ETS_WORLD, AbsoluteTransformation); |
87 | driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4); | 87 | driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4); |
88 | } | 88 | } |
89 | 89 | ||
90 | virtual const aabbox3d<f32>& getBoundingBox() const | 90 | virtual const aabbox3d<f32>& getBoundingBox() const |
91 | { | 91 | { |
92 | return Box; | 92 | return Box; |
93 | } | 93 | } |
94 | 94 | ||
95 | virtual u32 getMaterialCount() | 95 | virtual u32 getMaterialCount() |
96 | { | 96 | { |
97 | return 1; | 97 | return 1; |
98 | } | 98 | } |
99 | 99 | ||
100 | virtual SMaterial& getMaterial(u32 i) | 100 | virtual SMaterial& getMaterial(u32 i) |
101 | { | 101 | { |
102 | return Material; | 102 | return Material; |
103 | } | 103 | } |
104 | }; | 104 | }; |
105 | 105 | ||
106 | /*! | 106 | /*! |
107 | Startup a Windows Mobile Device | 107 | Startup a Windows Mobile Device |
108 | */ | 108 | */ |
109 | IrrlichtDevice *startup() | 109 | IrrlichtDevice *startup() |
110 | { | 110 | { |
111 | // both software and burnings video can be used | 111 | // both software and burnings video can be used |
112 | E_DRIVER_TYPE driverType = EDT_SOFTWARE; // EDT_BURNINGSVIDEO; | 112 | E_DRIVER_TYPE driverType = EDT_SOFTWARE; // EDT_BURNINGSVIDEO; |
113 | 113 | ||
114 | // create device | 114 | // create device |
115 | IrrlichtDevice *device = 0; | 115 | IrrlichtDevice *device = 0; |
116 | 116 | ||
117 | #if defined (_IRR_USE_WINDOWS_CE_DEVICE_) | 117 | #if defined (_IRR_USE_WINDOWS_CE_DEVICE_) |
118 | // set to standard mobile fullscreen 240x320 | 118 | // set to standard mobile fullscreen 240x320 |
119 | device = createDevice(driverType, dimension2d<u32>(240, 320), 16, true ); | 119 | device = createDevice(driverType, dimension2d<u32>(240, 320), 16, true ); |
120 | #else | 120 | #else |
121 | // on PC. use window mode | 121 | // on PC. use window mode |
122 | device = createDevice(driverType, dimension2d<u32>(240, 320), 16, false ); | 122 | device = createDevice(driverType, dimension2d<u32>(240, 320), 16, false ); |
123 | #endif | 123 | #endif |
124 | if ( 0 == device ) | 124 | if ( 0 == device ) |
125 | return 0; | 125 | return 0; |
126 | 126 | ||
127 | IVideoDriver* driver = device->getVideoDriver(); | 127 | IVideoDriver* driver = device->getVideoDriver(); |
128 | ISceneManager* smgr = device->getSceneManager(); | 128 | ISceneManager* smgr = device->getSceneManager(); |
129 | IGUIEnvironment* guienv = device->getGUIEnvironment(); | 129 | IGUIEnvironment* guienv = device->getGUIEnvironment(); |
130 | 130 | ||
131 | // set the filesystem relative to the executable | 131 | // set the filesystem relative to the executable |
132 | #if defined (_IRR_WINDOWS_) | 132 | #if defined (_IRR_WINDOWS_) |
133 | { | 133 | { |
134 | wchar_t buf[255]; | 134 | wchar_t buf[255]; |
135 | GetModuleFileNameW ( 0, buf, 255 ); | 135 | GetModuleFileNameW ( 0, buf, 255 ); |
136 | 136 | ||
137 | io::path base = buf; | 137 | io::path base = buf; |
138 | base = base.subString ( 0, base.findLast ( '\\' ) + 1 ); | 138 | base = base.subString ( 0, base.findLast ( '\\' ) + 1 ); |
139 | device->getFileSystem()->addFileArchive ( base ); | 139 | device->getFileSystem()->addFileArchive ( base ); |
140 | } | 140 | } |
141 | #endif | 141 | #endif |
142 | 142 | ||
143 | IGUIStaticText *text = guienv->addStaticText(L"FPS: 25", | 143 | IGUIStaticText *text = guienv->addStaticText(L"FPS: 25", |
144 | rect<s32>(140,15,200,30), false, false, 0, 100 ); | 144 | rect<s32>(140,15,200,30), false, false, 0, 100 ); |
145 | 145 | ||
146 | guienv->addButton(core::rect<int>(200,10,238,30), 0, 2, L"Quit"); | 146 | guienv->addButton(core::rect<int>(200,10,238,30), 0, 2, L"Quit"); |
147 | 147 | ||
148 | // add irrlicht logo | 148 | // add irrlicht logo |
149 | guienv->addImage(driver->getTexture("../../media/irrlichtlogo3.png"), | 149 | guienv->addImage(driver->getTexture("../../media/irrlichtlogo3.png"), |
150 | core::position2d<s32>(0,-2)); | 150 | core::position2d<s32>(0,-2)); |
151 | return device; | 151 | return device; |
152 | } | 152 | } |
153 | 153 | ||
154 | /*! | 154 | /*! |
155 | */ | 155 | */ |
156 | int run ( IrrlichtDevice *device ) | 156 | int run ( IrrlichtDevice *device ) |
157 | { | 157 | { |
158 | while(device->run()) | 158 | while(device->run()) |
159 | if (device->isWindowActive()) | 159 | if (device->isWindowActive()) |
160 | { | 160 | { |
161 | device->getVideoDriver()->beginScene(true, true, SColor(0,100,100,100)); | 161 | device->getVideoDriver()->beginScene(true, true, SColor(0,100,100,100)); |
162 | device->getSceneManager()->drawAll(); | 162 | device->getSceneManager()->drawAll(); |
163 | device->getGUIEnvironment()->drawAll(); | 163 | device->getGUIEnvironment()->drawAll(); |
164 | device->getVideoDriver()->endScene (); | 164 | device->getVideoDriver()->endScene (); |
165 | 165 | ||
166 | IGUIElement *stat = device->getGUIEnvironment()-> | 166 | IGUIElement *stat = device->getGUIEnvironment()-> |
167 | getRootGUIElement()->getElementFromId ( 100 ); | 167 | getRootGUIElement()->getElementFromId ( 100 ); |
168 | if ( stat ) | 168 | if ( stat ) |
169 | { | 169 | { |
170 | stringw str = L"FPS: "; | 170 | stringw str = L"FPS: "; |
171 | str += (s32)device->getVideoDriver()->getFPS(); | 171 | str += (s32)device->getVideoDriver()->getFPS(); |
172 | 172 | ||
173 | stat->setText ( str.c_str() ); | 173 | stat->setText ( str.c_str() ); |
174 | } | 174 | } |
175 | } | 175 | } |
176 | 176 | ||
177 | device->drop(); | 177 | device->drop(); |
178 | return 0; | 178 | return 0; |
179 | } | 179 | } |
180 | 180 | ||
181 | /*! | 181 | /*! |
182 | */ | 182 | */ |
183 | int example_customscenenode() | 183 | int example_customscenenode() |
184 | { | 184 | { |
185 | // create device | 185 | // create device |
186 | IrrlichtDevice *device = startup(); | 186 | IrrlichtDevice *device = startup(); |
187 | if (device == 0) | 187 | if (device == 0) |
188 | return 1; // could not create selected driver. | 188 | return 1; // could not create selected driver. |
189 | 189 | ||
190 | // create engine and camera | 190 | // create engine and camera |
191 | EventReceiver_basic receiver(device); | 191 | EventReceiver_basic receiver(device); |
192 | device->setEventReceiver(&receiver); | 192 | device->setEventReceiver(&receiver); |
193 | 193 | ||
194 | IVideoDriver* driver = device->getVideoDriver(); | 194 | IVideoDriver* driver = device->getVideoDriver(); |
195 | ISceneManager* smgr = device->getSceneManager(); | 195 | ISceneManager* smgr = device->getSceneManager(); |
196 | IGUIEnvironment* guienv = device->getGUIEnvironment(); | 196 | IGUIEnvironment* guienv = device->getGUIEnvironment(); |
197 | 197 | ||
198 | 198 | ||
199 | smgr->addCameraSceneNode(0, vector3df(0,-40,0), vector3df(0,0,0)); | 199 | smgr->addCameraSceneNode(0, vector3df(0,-40,0), vector3df(0,0,0)); |
200 | 200 | ||
201 | CSampleSceneNode *myNode = | 201 | CSampleSceneNode *myNode = |
202 | new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666); | 202 | new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666); |
203 | 203 | ||
204 | ISceneNodeAnimator* anim = | 204 | ISceneNodeAnimator* anim = |
205 | smgr->createRotationAnimator(vector3df(0.8f, 0, 0.8f)); | 205 | smgr->createRotationAnimator(vector3df(0.8f, 0, 0.8f)); |
206 | 206 | ||
207 | if(anim) | 207 | if(anim) |
208 | { | 208 | { |
209 | myNode->addAnimator(anim); | 209 | myNode->addAnimator(anim); |
210 | anim->drop(); | 210 | anim->drop(); |
211 | anim = 0; // As I shouldn't refer to it again, ensure that I can't | 211 | anim = 0; // As I shouldn't refer to it again, ensure that I can't |
212 | } | 212 | } |
213 | 213 | ||
214 | myNode->drop(); | 214 | myNode->drop(); |
215 | myNode = 0; // As I shouldn't refer to it again, ensure that I can't | 215 | myNode = 0; // As I shouldn't refer to it again, ensure that I can't |
216 | 216 | ||
217 | return run ( device ); | 217 | return run ( device ); |
218 | } | 218 | } |
219 | 219 | ||
220 | class EventReceiver_terrain : public IEventReceiver | 220 | class EventReceiver_terrain : public IEventReceiver |
221 | { | 221 | { |
222 | public: | 222 | public: |
223 | 223 | ||
224 | EventReceiver_terrain(IrrlichtDevice *device, scene::ISceneNode* terrain, scene::ISceneNode* skybox, scene::ISceneNode* skydome) : | 224 | EventReceiver_terrain(IrrlichtDevice *device, scene::ISceneNode* terrain, scene::ISceneNode* skybox, scene::ISceneNode* skydome) : |
225 | Device ( device ), Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true) | 225 | Device ( device ), Terrain(terrain), Skybox(skybox), Skydome(skydome), showBox(true) |
226 | { | 226 | { |
227 | Skybox->setVisible(true); | 227 | Skybox->setVisible(true); |
228 | Skydome->setVisible(false); | 228 | Skydome->setVisible(false); |
229 | } | 229 | } |
230 | 230 | ||
231 | bool OnEvent(const SEvent& event) | 231 | bool OnEvent(const SEvent& event) |
232 | { | 232 | { |
233 | if (event.EventType == EET_GUI_EVENT) | 233 | if (event.EventType == EET_GUI_EVENT) |
234 | { | 234 | { |
235 | s32 id = event.GUIEvent.Caller->getID(); | 235 | s32 id = event.GUIEvent.Caller->getID(); |
236 | 236 | ||
237 | switch(event.GUIEvent.EventType) | 237 | switch(event.GUIEvent.EventType) |
238 | { | 238 | { |
239 | case EGET_BUTTON_CLICKED: | 239 | case EGET_BUTTON_CLICKED: |
240 | if (id == 2) | 240 | if (id == 2) |
241 | { | 241 | { |
242 | Device->closeDevice(); | 242 | Device->closeDevice(); |
243 | return true; | 243 | return true; |
244 | } break; | 244 | } break; |
245 | } | 245 | } |
246 | } | 246 | } |
247 | 247 | ||
248 | // check if user presses the key 'W' or 'D' | 248 | // check if user presses the key 'W' or 'D' |
249 | if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) | 249 | if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) |
250 | { | 250 | { |
251 | switch (event.KeyInput.Key) | 251 | switch (event.KeyInput.Key) |
252 | { | 252 | { |
253 | case irr::KEY_KEY_W: // switch wire frame mode | 253 | case irr::KEY_KEY_W: // switch wire frame mode |
254 | Terrain->setMaterialFlag(video::EMF_WIREFRAME, | 254 | Terrain->setMaterialFlag(video::EMF_WIREFRAME, |
255 | !Terrain->getMaterial(0).Wireframe); | 255 | !Terrain->getMaterial(0).Wireframe); |
256 | Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false); | 256 | Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false); |
257 | return true; | 257 | return true; |
258 | case irr::KEY_KEY_P: // switch wire frame mode | 258 | case irr::KEY_KEY_P: // switch wire frame mode |
259 | Terrain->setMaterialFlag(video::EMF_POINTCLOUD, | 259 | Terrain->setMaterialFlag(video::EMF_POINTCLOUD, |
260 | !Terrain->getMaterial(0).PointCloud); | 260 | !Terrain->getMaterial(0).PointCloud); |
261 | Terrain->setMaterialFlag(video::EMF_WIREFRAME, false); | 261 | Terrain->setMaterialFlag(video::EMF_WIREFRAME, false); |
262 | return true; | 262 | return true; |
263 | case irr::KEY_KEY_D: // toggle detail map | 263 | case irr::KEY_KEY_D: // toggle detail map |
264 | Terrain->setMaterialType( | 264 | Terrain->setMaterialType( |
265 | Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ? | 265 | Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ? |
266 | video::EMT_DETAIL_MAP : video::EMT_SOLID); | 266 | video::EMT_DETAIL_MAP : video::EMT_SOLID); |
267 | return true; | 267 | return true; |
268 | case irr::KEY_KEY_S: // toggle skies | 268 | case irr::KEY_KEY_S: // toggle skies |
269 | showBox=!showBox; | 269 | showBox=!showBox; |
270 | Skybox->setVisible(showBox); | 270 | Skybox->setVisible(showBox); |
271 | Skydome->setVisible(!showBox); | 271 | Skydome->setVisible(!showBox); |
272 | return true; | 272 | return true; |
273 | default: | 273 | default: |
274 | break; | 274 | break; |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | return false; | 278 | return false; |
279 | } | 279 | } |
280 | 280 | ||
281 | private: | 281 | private: |
282 | IrrlichtDevice *Device; | 282 | IrrlichtDevice *Device; |
283 | scene::ISceneNode* Terrain; | 283 | scene::ISceneNode* Terrain; |
284 | scene::ISceneNode* Skybox; | 284 | scene::ISceneNode* Skybox; |
285 | scene::ISceneNode* Skydome; | 285 | scene::ISceneNode* Skydome; |
286 | bool showBox; | 286 | bool showBox; |
287 | }; | 287 | }; |
288 | 288 | ||
289 | 289 | ||
290 | /* | 290 | /* |
291 | The start of the main function starts like in most other example. We ask the user | 291 | The start of the main function starts like in most other example. We ask the user |
292 | for the desired renderer and start it up. This time with the advanced parameter handling. | 292 | for the desired renderer and start it up. This time with the advanced parameter handling. |
293 | */ | 293 | */ |
294 | int example_terrain() | 294 | int example_terrain() |
295 | { | 295 | { |
296 | // create device | 296 | // create device |
297 | IrrlichtDevice *device = startup(); | 297 | IrrlichtDevice *device = startup(); |
298 | if (device == 0) | 298 | if (device == 0) |
299 | return 1; // could not create selected driver. | 299 | return 1; // could not create selected driver. |
300 | 300 | ||
301 | /* | 301 | /* |
302 | First, we add standard stuff to the scene: A nice irrlicht engine | 302 | First, we add standard stuff to the scene: A nice irrlicht engine |
303 | logo, a small help text, a user controlled camera, and we disable | 303 | logo, a small help text, a user controlled camera, and we disable |
304 | the mouse cursor. | 304 | the mouse cursor. |
305 | */ | 305 | */ |
306 | 306 | ||
307 | video::IVideoDriver* driver = device->getVideoDriver(); | 307 | video::IVideoDriver* driver = device->getVideoDriver(); |
308 | scene::ISceneManager* smgr = device->getSceneManager(); | 308 | scene::ISceneManager* smgr = device->getSceneManager(); |
309 | gui::IGUIEnvironment* env = device->getGUIEnvironment(); | 309 | gui::IGUIEnvironment* env = device->getGUIEnvironment(); |
310 | 310 | ||
311 | 311 | ||
312 | //set other font | 312 | //set other font |
313 | //env->getSkin()->setFont(env->getFont("../../media/fontlucida.png")); | 313 | //env->getSkin()->setFont(env->getFont("../../media/fontlucida.png")); |
314 | 314 | ||
315 | // add some help text | 315 | // add some help text |
316 | env->addStaticText( | 316 | env->addStaticText( |
317 | L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome", | 317 | L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map\nPress 'S' to toggle skybox/skydome", |
318 | core::rect<s32>(5,250,235,320), true, true, 0, -1, true); | 318 | core::rect<s32>(5,250,235,320), true, true, 0, -1, true); |
319 | 319 | ||
320 | // add camera | 320 | // add camera |
321 | scene::ICameraSceneNode* camera = | 321 | scene::ICameraSceneNode* camera = |
322 | smgr->addCameraSceneNodeFPS(0,100.0f,1.2f); | 322 | smgr->addCameraSceneNodeFPS(0,100.0f,1.2f); |
323 | 323 | ||
324 | camera->setPosition(core::vector3df(2700*2,255*2,2600*2)); | 324 | camera->setPosition(core::vector3df(2700*2,255*2,2600*2)); |
325 | camera->setTarget(core::vector3df(2397*2,343*2,2700*2)); | 325 | camera->setTarget(core::vector3df(2397*2,343*2,2700*2)); |
326 | camera->setFarValue(42000.0f); | 326 | camera->setFarValue(42000.0f); |
327 | 327 | ||
328 | // disable mouse cursor | 328 | // disable mouse cursor |
329 | device->getCursorControl()->setVisible(false); | 329 | device->getCursorControl()->setVisible(false); |
330 | 330 | ||
331 | /* | 331 | /* |
332 | Here comes the terrain renderer scene node: We add it just like any | 332 | Here comes the terrain renderer scene node: We add it just like any |
333 | other scene node to the scene using | 333 | other scene node to the scene using |
334 | ISceneManager::addTerrainSceneNode(). The only parameter we use is a | 334 | ISceneManager::addTerrainSceneNode(). The only parameter we use is a |
335 | file name to the heightmap we use. A heightmap is simply a gray scale | 335 | file name to the heightmap we use. A heightmap is simply a gray scale |
336 | texture. The terrain renderer loads it and creates the 3D terrain from | 336 | texture. The terrain renderer loads it and creates the 3D terrain from |
337 | it. | 337 | it. |
338 | 338 | ||
339 | To make the terrain look more big, we change the scale factor of | 339 | To make the terrain look more big, we change the scale factor of |
340 | it to (40, 4.4, 40). Because we don't have any dynamic lights in the | 340 | it to (40, 4.4, 40). Because we don't have any dynamic lights in the |
341 | scene, we switch off the lighting, and we set the file | 341 | scene, we switch off the lighting, and we set the file |
342 | terrain-texture.jpg as texture for the terrain and detailmap3.jpg as | 342 | terrain-texture.jpg as texture for the terrain and detailmap3.jpg as |
343 | second texture, called detail map. At last, we set the scale values for | 343 | second texture, called detail map. At last, we set the scale values for |
344 | the texture: The first texture will be repeated only one time over the | 344 | the texture: The first texture will be repeated only one time over the |
345 | whole terrain, and the second one (detail map) 20 times. | 345 | whole terrain, and the second one (detail map) 20 times. |
346 | */ | 346 | */ |
347 | 347 | ||
348 | // add terrain scene node | 348 | // add terrain scene node |
349 | scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( | 349 | scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode( |
350 | "../../media/terrain-heightmap.bmp", | 350 | "../../media/terrain-heightmap.bmp", |
351 | 0, // parent node | 351 | 0, // parent node |
352 | -1, // node id | 352 | -1, // node id |
353 | core::vector3df(0.f, 0.f, 0.f), // position | 353 | core::vector3df(0.f, 0.f, 0.f), // position |
354 | core::vector3df(0.f, 0.f, 0.f), // rotation | 354 | core::vector3df(0.f, 0.f, 0.f), // rotation |
355 | core::vector3df(40.f, 4.4f, 40.f), // scale | 355 | core::vector3df(40.f, 4.4f, 40.f), // scale |
356 | video::SColor ( 255, 255, 255, 255 ), // vertexColor | 356 | video::SColor ( 255, 255, 255, 255 ), // vertexColor |
357 | 5, // maxLOD | 357 | 5, // maxLOD |
358 | scene::ETPS_17, // patchSize | 358 | scene::ETPS_17, // patchSize |
359 | 4 // smoothFactor | 359 | 4 // smoothFactor |
360 | ); | 360 | ); |
361 | 361 | ||
362 | if ( terrain ) | 362 | if ( terrain ) |
363 | { | 363 | { |
364 | terrain->setMaterialFlag(video::EMF_LIGHTING, false); | 364 | terrain->setMaterialFlag(video::EMF_LIGHTING, false); |
365 | 365 | ||
366 | terrain->setMaterialTexture(0, | 366 | terrain->setMaterialTexture(0, |
367 | driver->getTexture("../../media/terrain-texture.jpg")); | 367 | driver->getTexture("../../media/terrain-texture.jpg")); |
368 | terrain->setMaterialTexture(1, | 368 | terrain->setMaterialTexture(1, |
369 | driver->getTexture("../../media/detailmap3.jpg")); | 369 | driver->getTexture("../../media/detailmap3.jpg")); |
370 | 370 | ||
371 | terrain->setMaterialType(video::EMT_DETAIL_MAP); | 371 | terrain->setMaterialType(video::EMT_DETAIL_MAP); |
372 | 372 | ||
373 | terrain->scaleTexture(1.0f, 20.0f); | 373 | terrain->scaleTexture(1.0f, 20.0f); |
374 | //terrain->setDebugDataVisible ( true ); | 374 | //terrain->setDebugDataVisible ( true ); |
375 | 375 | ||
376 | /* | 376 | /* |
377 | To be able to do collision with the terrain, we create a triangle selector. | 377 | To be able to do collision with the terrain, we create a triangle selector. |
378 | If you want to know what triangle selectors do, just take a look into the | 378 | If you want to know what triangle selectors do, just take a look into the |
379 | collision tutorial. The terrain triangle selector works together with the | 379 | collision tutorial. The terrain triangle selector works together with the |
380 | terrain. To demonstrate this, we create a collision response animator | 380 | terrain. To demonstrate this, we create a collision response animator |
381 | and attach it to the camera, so that the camera will not be able to fly | 381 | and attach it to the camera, so that the camera will not be able to fly |
382 | through the terrain. | 382 | through the terrain. |
383 | */ | 383 | */ |
384 | 384 | ||
385 | // create triangle selector for the terrain | 385 | // create triangle selector for the terrain |
386 | scene::ITriangleSelector* selector | 386 | scene::ITriangleSelector* selector |
387 | = smgr->createTerrainTriangleSelector(terrain, 0); | 387 | = smgr->createTerrainTriangleSelector(terrain, 0); |
388 | terrain->setTriangleSelector(selector); | 388 | terrain->setTriangleSelector(selector); |
389 | 389 | ||
390 | // create collision response animator and attach it to the camera | 390 | // create collision response animator and attach it to the camera |
391 | scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( | 391 | scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( |
392 | selector, camera, core::vector3df(60,100,60), | 392 | selector, camera, core::vector3df(60,100,60), |
393 | core::vector3df(0,0,0), | 393 | core::vector3df(0,0,0), |
394 | core::vector3df(0,50,0)); | 394 | core::vector3df(0,50,0)); |
395 | selector->drop(); | 395 | selector->drop(); |
396 | camera->addAnimator(anim); | 396 | camera->addAnimator(anim); |
397 | anim->drop(); | 397 | anim->drop(); |
398 | 398 | ||
399 | /* If you need access to the terrain data you can also do this directly via the following code fragment. | 399 | /* If you need access to the terrain data you can also do this directly via the following code fragment. |
400 | */ | 400 | */ |
401 | scene::CDynamicMeshBuffer* buffer = new scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT); | 401 | scene::CDynamicMeshBuffer* buffer = new scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT); |
402 | terrain->getMeshBufferForLOD(*buffer, 0); | 402 | terrain->getMeshBufferForLOD(*buffer, 0); |
403 | video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer->getVertexBuffer().getData(); | 403 | video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer->getVertexBuffer().getData(); |
404 | // Work on data or get the IndexBuffer with a similar call. | 404 | // Work on data or get the IndexBuffer with a similar call. |
405 | buffer->drop(); // When done drop the buffer again. | 405 | buffer->drop(); // When done drop the buffer again. |
406 | } | 406 | } |
407 | 407 | ||
408 | /* | 408 | /* |
409 | To make the user be able to switch between normal and wireframe mode, | 409 | To make the user be able to switch between normal and wireframe mode, |
410 | we create an instance of the event receiver from above and let Irrlicht | 410 | we create an instance of the event receiver from above and let Irrlicht |
411 | know about it. In addition, we add the skybox which we already used in | 411 | know about it. In addition, we add the skybox which we already used in |
412 | lots of Irrlicht examples and a skydome, which is shown mutually | 412 | lots of Irrlicht examples and a skydome, which is shown mutually |
413 | exclusive with the skybox by pressing 'S'. | 413 | exclusive with the skybox by pressing 'S'. |
414 | */ | 414 | */ |
415 | 415 | ||
416 | // create skybox and skydome | 416 | // create skybox and skydome |
417 | driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); | 417 | driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false); |
418 | 418 | ||
419 | scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode( | 419 | scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode( |
420 | driver->getTexture("../../media/irrlicht2_up.jpg"), | 420 | driver->getTexture("../../media/irrlicht2_up.jpg"), |
421 | driver->getTexture("../../media/irrlicht2_dn.jpg"), | 421 | driver->getTexture("../../media/irrlicht2_dn.jpg"), |
422 | driver->getTexture("../../media/irrlicht2_lf.jpg"), | 422 | driver->getTexture("../../media/irrlicht2_lf.jpg"), |
423 | driver->getTexture("../../media/irrlicht2_rt.jpg"), | 423 | driver->getTexture("../../media/irrlicht2_rt.jpg"), |
424 | driver->getTexture("../../media/irrlicht2_ft.jpg"), | 424 | driver->getTexture("../../media/irrlicht2_ft.jpg"), |
425 | driver->getTexture("../../media/irrlicht2_bk.jpg")); | 425 | driver->getTexture("../../media/irrlicht2_bk.jpg")); |
426 | scene::ISceneNode* skydome=smgr->addSkyDomeSceneNode(driver->getTexture("../../media/skydome.jpg"),16,8,0.95f,2.0f); | 426 | scene::ISceneNode* skydome=smgr->addSkyDomeSceneNode(driver->getTexture("../../media/skydome.jpg"),16,8,0.95f,2.0f); |
427 | 427 | ||
428 | driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true); | 428 | driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true); |
429 | 429 | ||
430 | // create event receiver | 430 | // create event receiver |
431 | EventReceiver_terrain receiver( device, terrain, skybox, skydome); | 431 | EventReceiver_terrain receiver( device, terrain, skybox, skydome); |
432 | device->setEventReceiver(&receiver); | 432 | device->setEventReceiver(&receiver); |
433 | 433 | ||
434 | return run ( device ); | 434 | return run ( device ); |
435 | } | 435 | } |
436 | 436 | ||
437 | /* | 437 | /* |
438 | */ | 438 | */ |
439 | int example_helloworld() | 439 | int example_helloworld() |
440 | { | 440 | { |
441 | // create device | 441 | // create device |
442 | IrrlichtDevice *device = startup(); | 442 | IrrlichtDevice *device = startup(); |
443 | if (device == 0) | 443 | if (device == 0) |
444 | return 1; // could not create selected driver. | 444 | return 1; // could not create selected driver. |
445 | 445 | ||
446 | IVideoDriver* driver = device->getVideoDriver(); | 446 | IVideoDriver* driver = device->getVideoDriver(); |
447 | ISceneManager* smgr = device->getSceneManager(); | 447 | ISceneManager* smgr = device->getSceneManager(); |
448 | IGUIEnvironment* guienv = device->getGUIEnvironment(); | 448 | IGUIEnvironment* guienv = device->getGUIEnvironment(); |
449 | 449 | ||
450 | IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2"); | 450 | IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2"); |
451 | if (!mesh) | 451 | if (!mesh) |
452 | { | 452 | { |
453 | device->drop(); | 453 | device->drop(); |
454 | return 1; | 454 | return 1; |
455 | } | 455 | } |
456 | IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh ); | 456 | IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh ); |
457 | 457 | ||
458 | /* | 458 | /* |
459 | To let the mesh look a little bit nicer, we change its material. We | 459 | To let the mesh look a little bit nicer, we change its material. We |
460 | disable lighting because we do not have a dynamic light in here, and | 460 | disable lighting because we do not have a dynamic light in here, and |
461 | the mesh would be totally black otherwise. Then we set the frame loop, | 461 | the mesh would be totally black otherwise. Then we set the frame loop, |
462 | such that the predefined STAND animation is used. And last, we apply a | 462 | such that the predefined STAND animation is used. And last, we apply a |
463 | texture to the mesh. Without it the mesh would be drawn using only a | 463 | texture to the mesh. Without it the mesh would be drawn using only a |
464 | color. | 464 | color. |
465 | */ | 465 | */ |
466 | if (node) | 466 | if (node) |
467 | { | 467 | { |
468 | node->setMaterialFlag(EMF_LIGHTING, false); | 468 | node->setMaterialFlag(EMF_LIGHTING, false); |
469 | node->setMD2Animation(scene::EMAT_STAND); | 469 | node->setMD2Animation(scene::EMAT_STAND); |
470 | node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") ); | 470 | node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") ); |
471 | } | 471 | } |
472 | 472 | ||
473 | /* | 473 | /* |
474 | To look at the mesh, we place a camera into 3d space at the position | 474 | To look at the mesh, we place a camera into 3d space at the position |
475 | (0, 30, -40). The camera looks from there to (0,5,0), which is | 475 | (0, 30, -40). The camera looks from there to (0,5,0), which is |
476 | approximately the place where our md2 model is. | 476 | approximately the place where our md2 model is. |
477 | */ | 477 | */ |
478 | smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0)); | 478 | smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0)); |
479 | 479 | ||
480 | EventReceiver_basic receiver(device); | 480 | EventReceiver_basic receiver(device); |
481 | device->setEventReceiver(&receiver); | 481 | device->setEventReceiver(&receiver); |
482 | 482 | ||
483 | return run ( device ); | 483 | return run ( device ); |
484 | 484 | ||
485 | } | 485 | } |
486 | 486 | ||
487 | #if defined (_IRR_USE_WINDOWS_CE_DEVICE_) | 487 | #if defined (_IRR_USE_WINDOWS_CE_DEVICE_) |
488 | #pragma comment(linker, "/subsystem:WINDOWSCE /ENTRY:main") | 488 | #pragma comment(linker, "/subsystem:WINDOWSCE /ENTRY:main") |
489 | #elif defined (_IRR_WINDOWS_) | 489 | #elif defined (_IRR_WINDOWS_) |
490 | #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") | 490 | #pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup") |
491 | #endif | 491 | #endif |
492 | 492 | ||
493 | /* | 493 | /* |
494 | */ | 494 | */ |
495 | int main() | 495 | int main() |
496 | { | 496 | { |
497 | example_helloworld (); | 497 | example_helloworld (); |
498 | example_customscenenode(); | 498 | example_customscenenode(); |
499 | //example_terrain(); | 499 | //example_terrain(); |
500 | } | 500 | } |
501 | 501 | ||
502 | /* | 502 | /* |
503 | **/ | 503 | **/ |