class MyEventReceiver : public IEventReceiver { public: MyEventReceiver(scene::ISceneNode* terrain) { // store pointer to terrain so we can change its drawing mode Terrain = terrain; }
bool OnEvent(SEvent event) { // check if user presses the key 'W' or 'D' if (event.EventType == irr::EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown) { switch (event.KeyInput.Key) { case irr::KEY_KEY_W: // switch wire frame mode Terrain->setMaterialFlag(video::EMF_WIREFRAME, !Terrain->getMaterial(0).Wireframe); return true; case irr::KEY_KEY_D: // toggle detail map Terrain->setMaterialType( Terrain->getMaterial(0).MaterialType == video::EMT_SOLID ? video::EMT_DETAIL_MAP : video::EMT_SOLID); return true; } } return false; }
// add irrlicht logo env->addImage(driver->getTexture("../../media/irrlichtlogoalpha.tga"), core::position2d(10,10));
// add some help text gui::IGUIStaticText* text = env->addStaticText( L"Press 'W' to change wireframe mode\nPress 'D' to toggle detail map", core::rect(10,453,200,475), true, true, 0, -1, true);
// add camera scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,1200.0f); camera->setPosition(core::vector3df(1900*2,255*2,3700*2)); camera->setTarget(core::vector3df(2397*2,343*2,2700*2)); camera->setFarValue(12000.0f);
// create triangle selector for the terrain scene::ITriangleSelector* selector = smgr->createTerrainTriangleSelector(terrain, 0); terrain->setTriangleSelector(selector); selector->drop();
// create collision response animator and attach it to the camera scene::ISceneNodeAnimator* anim = smgr->createCollisionResponseAnimator( selector, camera, core::vector3df(60,100,60), core::vector3df(0,0,0), core::vector3df(0,50,0)); camera->addAnimator(anim); anim->drop();
为了使用户能在普通模式和线框模式之间转换,我们根据上面定义的事件接收器类创建一个事件接收器并告诉IrrLicht引擎。另外,我们还添加一个已经在其它例子(译注:mesh viewer)中使用过的天空盒。In addition, we add the skybox which we already used in lots of Irrlicht examples.