1
/** Example 017 Helloworld mobile
2
This example show Hello World for Windows mobile.
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.
5
You need a Filesystem, which is relative based to your executable.
10
#if defined ( _IRR_WINDOWS_ )
16
using namespace scene;
17
using namespace video;
21
#pragma comment(lib, "Irrlicht.lib")
23
class EventReceiver_basic : public IEventReceiver
26
IrrlichtDevice *Device;
28
EventReceiver_basic ( IrrlichtDevice *device ): Device ( device ) {}
30
virtual bool OnEvent(const SEvent& event)
32
if (event.EventType == EET_GUI_EVENT)
34
s32 id = event.GUIEvent.Caller->getID();
36
switch(event.GUIEvent.EventType)
38
case EGET_BUTTON_CLICKED:
41
Device->closeDevice();
51
class CSampleSceneNode : public ISceneNode
54
S3DVertex Vertices[4];
58
CSampleSceneNode(ISceneNode* parent, ISceneManager* mgr, s32 id)
59
: ISceneNode(parent, mgr, id)
61
Material.Wireframe = false;
62
Material.Lighting = false;
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);
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);
68
Box.reset(Vertices[0].Pos);
69
for (s32 i=1; i<4; ++i)
70
Box.addInternalPoint(Vertices[i].Pos);
72
virtual void OnRegisterSceneNode()
75
SceneManager->registerNodeForRendering(this);
77
ISceneNode::OnRegisterSceneNode();
82
u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 };
83
IVideoDriver* driver = SceneManager->getVideoDriver();
85
driver->setMaterial(Material);
86
driver->setTransform(ETS_WORLD, AbsoluteTransformation);
87
driver->drawIndexedTriangleList(&Vertices[0], 4, &indices[0], 4);
90
virtual const aabbox3d<f32>& getBoundingBox() const
95
virtual u32 getMaterialCount()
100
virtual SMaterial& getMaterial(u32 i)
107
Startup a Windows Mobile Device
109
IrrlichtDevice *startup()
111
// both software and burnings video can be used
112
E_DRIVER_TYPE driverType = EDT_SOFTWARE; // EDT_BURNINGSVIDEO;
115
IrrlichtDevice *device = 0;
117
#if defined (_IRR_USE_WINDOWS_CE_DEVICE_)
118
// set to standard mobile fullscreen 240x320
119
device = createDevice(driverType, dimension2d<u32>(240, 320), 16, true );
121
// on PC. use window mode
122
device = createDevice(driverType, dimension2d<u32>(240, 320), 16, false );
127
IVideoDriver* driver = device->getVideoDriver();
128
ISceneManager* smgr = device->getSceneManager();
129
IGUIEnvironment* guienv = device->getGUIEnvironment();
131
// set the filesystem relative to the executable
132
#if defined (_IRR_WINDOWS_)
135
GetModuleFileNameW ( 0, buf, 255 );
138
base = base.subString ( 0, base.findLast ( '\\' ) + 1 );
139
device->getFileSystem()->addFileArchive ( base );
143
IGUIStaticText *text = guienv->addStaticText(L"FPS: 25",
144
rect<s32>(140,15,200,30), false, false, 0, 100 );
146
guienv->addButton(core::rect<int>(200,10,238,30), 0, 2, L"Quit");
149
guienv->addImage(driver->getTexture("../../media/irrlichtlogo3.png"),
150
core::position2d<s32>(0,-2));
156
int run ( IrrlichtDevice *device )
159
if (device->isWindowActive())
161
device->getVideoDriver()->beginScene(true, true, SColor(0,100,100,100));
162
device->getSceneManager()->drawAll();
163
device->getGUIEnvironment()->drawAll();
164
device->getVideoDriver()->endScene ();
166
IGUIElement *stat = device->getGUIEnvironment()->
167
getRootGUIElement()->getElementFromId ( 100 );
170
stringw str = L"FPS: ";
171
str += (s32)device->getVideoDriver()->getFPS();
173
stat->setText ( str.c_str() );
183
int example_customscenenode()
186
IrrlichtDevice *device = startup();
188
return 1; // could not create selected driver.
190
// create engine and camera
191
EventReceiver_basic receiver(device);
192
device->setEventReceiver(&receiver);
194
IVideoDriver* driver = device->getVideoDriver();
195
ISceneManager* smgr = device->getSceneManager();
196
IGUIEnvironment* guienv = device->getGUIEnvironment();
199
smgr->addCameraSceneNode(0, vector3df(0,-40,0), vector3df(0,0,0));
201
CSampleSceneNode *myNode =
202
new CSampleSceneNode(smgr->getRootSceneNode(), smgr, 666);
204
ISceneNodeAnimator* anim =
205
smgr->createRotationAnimator(vector3df(0.8f, 0, 0.8f));
209
myNode->addAnimator(anim);
211
anim = 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
217
return run ( device );
220
class EventReceiver_terrain : public IEventReceiver
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)
227
Skybox->setVisible(true);
228
Skydome->setVisible(false);
231
bool OnEvent(const SEvent& event)
233
if (event.EventType == EET_GUI_EVENT)
235
s32 id = event.GUIEvent.Caller->getID();
237
switch(event.GUIEvent.EventType)
239
case EGET_BUTTON_CLICKED:
242
Device->closeDevice();
248
// check if user presses the key 'W' or 'D'
249
if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
251
switch (event.KeyInput.Key)
253
case irr::KEY_KEY_W: // switch wire frame mode
254
Terrain->setMaterialFlag(video::EMF_WIREFRAME,
255
!Terrain->getMaterial(0).Wireframe);
256
Terrain->setMaterialFlag(video::EMF_POINTCLOUD, false);
258
case irr::KEY_KEY_P: // switch wire frame mode
259
Terrain->setMaterialFlag(video::EMF_POINTCLOUD,
260
!Terrain->getMaterial(0).PointCloud);
261
Terrain->setMaterialFlag(video::EMF_WIREFRAME, false);
263
case irr::KEY_KEY_D: // toggle detail map
264
Terrain->setMaterialType(
265
Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ?
266
video::EMT_DETAIL_MAP : video::EMT_SOLID);
268
case irr::KEY_KEY_S: // toggle skies
270
Skybox->setVisible(showBox);
271
Skydome->setVisible(!showBox);
282
IrrlichtDevice *Device;
283
scene::ISceneNode* Terrain;
284
scene::ISceneNode* Skybox;
285
scene::ISceneNode* Skydome;
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.
294
int example_terrain()
297
IrrlichtDevice *device = startup();
299
return 1; // could not create selected driver.
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
307
video::IVideoDriver* driver = device->getVideoDriver();
308
scene::ISceneManager* smgr = device->getSceneManager();
309
gui::IGUIEnvironment* env = device->getGUIEnvironment();
313
//env->getSkin()->setFont(env->getFont("../../media/fontlucida.png"));
315
// add some help text
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);
321
scene::ICameraSceneNode* camera =
322
smgr->addCameraSceneNodeFPS(0,100.0f,1.2f);
324
camera->setPosition(core::vector3df(2700*2,255*2,2600*2));
325
camera->setTarget(core::vector3df(2397*2,343*2,2700*2));
326
camera->setFarValue(42000.0f);
328
// disable mouse cursor
329
device->getCursorControl()->setVisible(false);
332
Here comes the terrain renderer scene node: We add it just like any
333
other scene node to the scene using
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
336
texture. The terrain renderer loads it and creates the 3D terrain from
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
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
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
345
whole terrain, and the second one (detail map) 20 times.
348
// add terrain scene node
349
scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
350
"../../media/terrain-heightmap.bmp",
353
core::vector3df(0.f, 0.f, 0.f), // position
354
core::vector3df(0.f, 0.f, 0.f), // rotation
355
core::vector3df(40.f, 4.4f, 40.f), // scale
356
video::SColor ( 255, 255, 255, 255 ), // vertexColor
358
scene::ETPS_17, // patchSize
364
terrain->setMaterialFlag(video::EMF_LIGHTING, false);
366
terrain->setMaterialTexture(0,
367
driver->getTexture("../../media/terrain-texture.jpg"));
368
terrain->setMaterialTexture(1,
369
driver->getTexture("../../media/detailmap3.jpg"));
371
terrain->setMaterialType(video::EMT_DETAIL_MAP);
373
terrain->scaleTexture(1.0f, 20.0f);
374
//terrain->setDebugDataVisible ( true );
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
379
collision tutorial. The terrain triangle selector works together with the
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
385
// create triangle selector for the terrain
386
scene::ITriangleSelector* selector
387
= smgr->createTerrainTriangleSelector(terrain, 0);
388
terrain->setTriangleSelector(selector);
390
// create collision response animator and attach it to the camera
391
scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator(
392
selector, camera, core::vector3df(60,100,60),
393
core::vector3df(0,0,0),
394
core::vector3df(0,50,0));
396
camera->addAnimator(anim);
399
/* If you need access to the terrain data you can also do this directly via the following code fragment.
401
scene::CDynamicMeshBuffer* buffer = new scene::CDynamicMeshBuffer(video::EVT_2TCOORDS, video::EIT_16BIT);
402
terrain->getMeshBufferForLOD(*buffer, 0);
403
video::S3DVertex2TCoords* data = (video::S3DVertex2TCoords*)buffer->getVertexBuffer().getData();
404
// Work on data or get the IndexBuffer with a similar call.
405
buffer->drop(); // When done drop the buffer again.
409
To make the user be able to switch between normal and wireframe mode,
410
we create an instance of the event reciever from above and let Irrlicht
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
413
exclusive with the skybox by pressing 'S'.
416
// create skybox and skydome
417
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
419
scene::ISceneNode* skybox=smgr->addSkyBoxSceneNode(
420
driver->getTexture("../../media/irrlicht2_up.jpg"),
421
driver->getTexture("../../media/irrlicht2_dn.jpg"),
422
driver->getTexture("../../media/irrlicht2_lf.jpg"),
423
driver->getTexture("../../media/irrlicht2_rt.jpg"),
424
driver->getTexture("../../media/irrlicht2_ft.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);
428
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
430
// create event receiver
431
EventReceiver_terrain receiver( device, terrain, skybox, skydome);
432
device->setEventReceiver(&receiver);
434
return run ( device );
439
int example_helloworld()
442
IrrlichtDevice *device = startup();
444
return 1; // could not create selected driver.
446
IVideoDriver* driver = device->getVideoDriver();
447
ISceneManager* smgr = device->getSceneManager();
448
IGUIEnvironment* guienv = device->getGUIEnvironment();
450
IAnimatedMesh* mesh = smgr->getMesh("../../media/sydney.md2");
456
IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode( mesh );
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
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
463
texture to the mesh. Without it the mesh would be drawn using only a
468
node->setMaterialFlag(EMF_LIGHTING, false);
469
node->setMD2Animation(scene::EMAT_STAND);
470
node->setMaterialTexture( 0, driver->getTexture("../../media/sydney.bmp") );
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
476
approximately the place where our md2 model is.
478
smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));
480
EventReceiver_basic receiver(device);
481
device->setEventReceiver(&receiver);
483
return run ( device );
487
#if defined (_IRR_USE_WINDOWS_CE_DEVICE_)
488
#pragma comment(linker, "/subsystem:WINDOWSCE /ENTRY:main")
489
#elif defined (_IRR_WINDOWS_)
490
#pragma comment(linker, "/subsystem:windows /ENTRY:mainCRTStartup")
497
example_helloworld ();
498
example_customscenenode();