Code: Select all
int a = 0;
SEvent event;
while (device->run())
{
if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
{
if (event.KeyInput.Key == KEY_KEY_W) a += 10;
}
Code: Select all
int a = 0;
SEvent event;
while (device->run())
{
if (event.EventType == EET_KEY_INPUT_EVENT && !event.KeyInput.PressedDown)
{
if (event.KeyInput.Key == KEY_KEY_W) a += 10;
}
The code is actually based on this tutorial...Perceval wrote:Take a look at this tutorial http://irrlicht.sourceforge.net/tut004.html, which explains how event receiver work
Sorry, no it is not. Either that or you have a very liiberal definition of 'based on'.The code is actually based on this tutorial...
I meant that I studied how to program the controls from that tutorial... my mistake.vitek wrote:Sorry, no it is not. Either that or you have a very liiberal definition of 'based on'.The code is actually based on this tutorial...
The tutorial uses an event receiver to handle events, buy you're trying to handle them in main. If you want to handle events using Irrlicht, you need an event receiver.
Travis
Here is the whole code. The comments were in Finnish so I removed most of them.Acki wrote:Show us your event receiver and main loop, please...
Code: Select all
#include<irrlicht.h>
using namespace irr;
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;
#ifdef _IRR_WINDOWS_
#pragma comment(lib, "Irrlicht.lib")
#endif
scene::ISceneNode* node = 0;
IrrlichtDevice* device = 0;
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (node != 0 && event.EventType == EET_KEY_INPUT_EVENT&&
!event.KeyInput.PressedDown)
{
switch(event.KeyInput.Key)
{
case KEY_KEY_W:
case KEY_KEY_S:
{
vector3df v = node->getPosition();
v.Y += event.KeyInput.Key == KEY_KEY_W ? 2.0f : -2.0f;
node->setPosition(v);
}
return true;
}
}
return false;
}
};
int main()
{
MyEventReceiver receiver;
IrrlichtDevice *device = createDevice(EDT_OPENGL, dimension2d<s32>(640,480), 16, false, false, false, &receiver);
IVideoDriver *driver = device->getVideoDriver();
ISceneManager *smgr = device->getSceneManager();
IGUIEnvironment *guienv = device->getGUIEnvironment();
//######## If I move the "//" from the next line to the line after that the controls will work just fine. ########
//node = smgr->addSphereSceneNode();
IAnimatedMesh *mesh = smgr->getMesh("../media/model.b3d");
IAnimatedMeshSceneNode *node = smgr->addAnimatedMeshSceneNode(mesh);
node->setAnimationSpeed(2000);
node->setMaterialFlag(EMF_LIGHTING, false);
node->setMaterialTexture(0, driver->getTexture("../media/model.png"))
smgr->addCameraSceneNode(0, vector3df(20,20,-20), vector3df(0,0,0));
while (device->run())
{
driver->beginScene(true, true, SColor(0,0,0, 0));
smgr->drawAll();
driver->endScene();
stringw fps = L"FPS ";
fps += driver->getFPS();
device->setWindowCaption(fps.c_str());
}
device->drop();
return 0;
}
How can I have been this stupid?Acki wrote:Ahhh, you have "node" declared 2 times, 1 global and 1 local !!!
change one of them to another name or remove the global one !!!
EDIT: sorry, in your case remove the local declaration and change the global one to IAnimatedMeshSceneNode *node = 0;...