I just learn irrlicht a few days ago..
For the shake of simplicity , i'm using IrrEventManager..
link:
http://irrlicht.sourceforge.net/phpBB2/ ... 510#156510
so everything running well..till i learn the Tutorial 5 User Interface..
So, i've got two setEventReceiver in my code...
This is the code that i've tried to make
Code: Select all
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#include <irrEventManager.h>
#ifdef _MSC_VER
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "EventManager.lib")
#endif
struct nuklir
{
IrrlichtDevice *device;
//s32 counter;
//IGUIListBox* listbox;
};
enum {GUI_ID_QUIT_BUTTON = 101};
class MyEventReceiver:public IEventReceiver{
public:
MyEventReceiver(nuklir & rudal) :sapi(rudal) { } //member dari myeventreceiver
virtual bool OnEvent(const SEvent& event)
{
if (event.EventType == EET_GUI_EVENT)
{ s32 id = event.GUIEvent.Caller->getID();
IGUIEnvironment* env = sapi.device->getGUIEnvironment();
switch(event.GUIEvent.EventType)
{
case EGET_BUTTON_CLICKED:
switch(id)
{
case GUI_ID_QUIT_BUTTON:
sapi.device->closeDevice();
return true;
}
break;
}
}
return false;
}
private:
nuklir & sapi;
};
int main()
{
IEventManager* enm;
IrrlichtDevice *device =
createDevice( video::EDT_DIRECT3D9, dimension2d<u32>(1024, 768), 16,
false, true, true, 0);
if (!device)
return 1;
enm = createEventManager();
//variable
scene::ISceneNode* bola1 = 0;
scene::ISceneNode* bola2 = 0;
scene::ISceneNode* node = 0;
scene::ITriangleSelector* selector = 0;
scene::ISceneNode *g_CameraPositionNode;
scene::ISceneNode *g_CameraTargetNode;
scene::ICameraSceneNode* camera = 0;
scene::ISceneNodeAnimator* mot2 =0;
scene::ISceneNodeAnimator* mot =0;
video::IVideoDriver* driver = device->getVideoDriver();
int tambah = 0;
scene::IAnimatedMesh* mesh = 0;
//Button=============================================================
IGUIEnvironment* env = device->getGUIEnvironment();
env->addButton(rect<s32>(10,240,110,240 + 32), 0, GUI_ID_QUIT_BUTTON,
L"Quit", L"Keluar");
nuklir rudal;
rudal.device = device;
// Then create the event receiver, giving it that context structure.
MyEventReceiver receiver(rudal);
IGUISkin* skin = env->getSkin();
IGUIFont* font = env->getFont("../../media/fonthaettenschweiler.bmp");
if (font)
skin->setFont(font);
skin->setFont(env->getBuiltInFont(), EGDF_TOOLTIP);
device->setEventReceiver(enm); ================================================>PROBLEM
device->setEventReceiver(&receiver) ;===============================================>PROBLEM
//===============================================================
device->setWindowCaption(L"Just Learn");
ISceneManager* smgr = device->getSceneManager();
IGUIEnvironment* guienv = device->getGUIEnvironment();
smgr->addLightSceneNode(0, core::vector3df(200,1000,200),
video::SColorf(1.0f,1.0f,1.0f),2000);
smgr->setAmbientLight(video::SColorf(0.3f,0.3f,0.3f));
device->getCursorControl()->setVisible(true);
//tambahan untuk parralax
video::IMaterialRenderer* renderer = driver->getMaterialRenderer(video::EMT_PARALLAX_MAP_SOLID);
driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
//MESH
IAnimatedMesh* kotak1 = smgr->getMesh("Model/beruang.irrmesh");
ISceneNode* nodekotak1= smgr->addAnimatedMeshSceneNode(kotak1);
nodekotak1->setScale(vector3df(3.0f,3.0f,3.0f));
nodekotak1->setPosition(core::vector3df(0,0,30));
nodekotak1->setMaterialFlag(video::EMF_LIGHTING, true);
while(device->run()&& driver)
{
vector3df pos = camera->getPosition();
if(enm->keyDown(irr::KEY_ESCAPE))
device->closeDevice();
else
if(enm->keyDown(irr::KEY_KEY_W))
pos.Y += 0.05f;
else
if(enm->keyDown(irr::KEY_KEY_S))
pos.Y -= 0.05f;
else
if(enm->keyDown(irr::KEY_KEY_A))
pos.X -= 0.05f;
else
if(enm->keyDown(irr::KEY_KEY_D))
pos.X += 0.05f;
camera->setPosition(pos);
driver->beginScene(true, true, 0);//SColor(255,100,101,140));
smgr->drawAll();
guienv->drawAll();
env->drawAll();
driver->endScene();
}
device->drop();
return 0;
}
device->setEventReceiver(enm); From IrrEventManager
device->setEventReceiver(&receiver); From GUI
How to combine both of my setEventReceiver..?
Thank you so much..