Page 1 of 1

irrlicht complete tutorial

Posted: Sat Dec 05, 2009 2:48 am
by siyuangao
I tried to search a complete tutorial for irrlicht engine, but i just can't find one, the one on the forum is too short and i have problems with it. when i go through the third chapter, the compiler just can't compile the program for me. it give me this error.

74 G:\Desktop\Irrlicht Engine\main.cpp cannot declare variable `rv' to be of type `MyEventReceiver'

This is the key receiver, can anybody help me with that and find me a better tutorial?? Thanks

Posted: Sat Dec 05, 2009 4:25 am
by Ulf
Did you download the source of Irrlicht? And then run the example solution?

Or did you copy and paste the code from the internet (wiki) into your own project?
You should download the package and load the example solution. It should work, as the environment is set up to compile.

Posted: Sat Dec 05, 2009 2:26 pm
by siyuangao
I did download the newest version of the engine and all other examples works fine, but when i try to add the code for key controlled movements, the Dev-C++ compiler gives me this kind of error.

Posted: Sat Dec 05, 2009 2:42 pm
by randomMesh
You should post the whole error message. :roll:

But since i have telepathic capabilities, it can tell you that have to change the signature of the event receiver's OnEvent method to:

Code: Select all

bool OnEvent(const irr::SEvent& event)

Posted: Sat Dec 05, 2009 4:56 pm
by siyuangao
The error message is like this.

32 G:\Desktop\irrlicht\main.cpp cannot declare variable `rv' to be of type `MyEventReceiver'
32 G:\Desktop\irrlicht\main.cpp because the following virtual functions are abstract:
351 F:\irrlicht-1.5.1\include\IEventReceiver.h virtual bool irr::IEventReceiver::OnEvent(const irr::SEvent&)
Here is the code of my sample program

Code: Select all

#include <cstdlib>
#include <iostream>
#include <irrlicht.h>

using namespace std;
using namespace irr; 
using namespace core; 
using namespace scene; 
using namespace video; 
using namespace gui; 
bool keys[irr::KEY_KEY_CODES_COUNT];
class MyEventReceiver : public IEventReceiver { 
 public: 
  bool OnEvent(SEvent event)  { 
  if(event.EventType == irr::EET_KEY_INPUT_EVENT){ 
   keys[event.KeyInput.Key] = event.KeyInput.PressedDown; 
   return false; 
  } 
   return false; 
  } 
}; 

#pragma comment(lib, Irrlicht.lib); 
 


int main()
{ 
    IrrlichtDevice* device = createDevice(EDT_OPENGL); 
    IVideoDriver* video = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    MyEventReceiver rv; 
    device->setEventReceiver(&rv);
    for(int x=0; x<irr::KEY_KEY_CODES_COUNT; x++) keys[x] = false;
    ISceneNode* cube = smgr->addCubeSceneNode(); 
    cube->setPosition(vector3df(0,0,5));
    while(device->run() && device)
    {
                        if(keys[KEY_KEY_W]) { 
   cube->setPosition(cube->getPosition()+vector3df(0,0,5)); 
                                                            } 
                         video->beginScene(true, true, video::SColor(255,0,0,255)); 
                         smgr->drawAll(); 
                         video->endScene();
    }
    return EXIT_SUCCESS;
}

Posted: Sat Dec 05, 2009 5:10 pm
by randomMesh
That's exactly what my magic crystal ball told me. So just change the method's signature to the one i already posted and you're fine.

Image

Posted: Sat Dec 05, 2009 5:54 pm
by siyuangao
Thanks :lol:

Posted: Tue Dec 08, 2009 1:45 pm
by Kirjuxa
You have no Constructor defined in your class,

i think thats why the compiling crashes