(C++) Simple to use Event Receiver class for Irrlicht 1.3

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
sader
Posts: 28
Joined: Sat Sep 29, 2007 1:38 pm

Post by sader »

Exactly wat I was planing to code :) thanx.
But one question do we realy need Init() function?

This function practically just sets all variables to 0 so no effect :/ because those variables becomes zero when object is created plus
it's much nicer to set default values of variables with help of constructor, or do I miss something?
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

There is a bug that you can't control GUI events.
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
TheMiss
Posts: 14
Joined: Sun Apr 15, 2007 6:46 pm

Post by TheMiss »

MasterGod wrote:There is a bug that you can't control GUI events.
I can still do that :?
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

How? please tell me how do you handle GUI with this receiver?

PS: This is what I tried:
In MastEventReceiver.cpp

Code: Select all

virtual bool OnEvent(SEvent event)
   {
	  bool eventprocessed = false;

	  //////////////////////////////
      // GUI Input Event
      //////////////////////////////
      if (event.EventType == EET_GUI_EVENT)
      {
		  s32 id = event.GUIEvent.Caller->getID();

		  switch(event.GUIEvent.EventType)
		  {
		  case EGET_BUTTON_CLICKED:
			  if (id == 101)
			  {
				  device->closeDevice();
				  return true;
			  }
			  break;
		  default:
			  break;
		  }
      }

      //////////////////////////////
      // Keyboard Input Event
      //////////////////////////////
In Main.cpp

Code: Select all

	MastEventReceiver eventReceiver;
	eventReceiver.init();
	eventReceiver.getDevice(device);
	device->setEventReceiver(&eventReceiver);
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I found that if I disable the Whole mouse handling I can control GUI events.
Now, how can I enable both mouse handling and GUI handling?
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

TheMiss wrote:
MasterGod wrote:There is a bug that you can't control GUI events.
I can still do that :?
Yeah, your version of MastEventReceiver did the job.

PS:
Mastiff, did you neglect the "project"?
yaim031
Posts: 1
Joined: Sun Oct 21, 2007 6:36 am

Post by yaim031 »

MasterGod wrote:There is a bug that you can't control GUI events.
change

Code: Select all

return eventprocessed; 
to

Code: Select all

return false; 
christianclavet
Posts: 1638
Joined: Mon Apr 30, 2007 3:24 am
Location: Montreal, CANADA
Contact:

Post by christianclavet »

Hi. Mastiff

Could I use that code and be able to align the MOUSEX, MOUSEY with the UPVECTOR of the CAMERA. (I mean, be able to use it and modify it to do that) Can a FPSCamera can use that even handler?

I would like to make the camera walk on walls or ceiling like in "Prey".

You code seem to be a good start for that.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

I didn't hear from him since long time ago. I have a good feeling you can freely change his code as long as you keep this:

Code: Select all

/// MastEventReceiver code is © (Copyright) Robert E. Demarest, AKA Mastiff or Mastiff Odit
/// This file may be used in any non-commercial or commercial project as long as the following conditions are met:
/// You may not claim this code as being your own.
/// You may not use this code for any harmful, malicious or otherwise damaging programs. 
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Avian
Posts: 17
Joined: Sun Dec 16, 2007 7:14 am

Post by Avian »

qustion: Does this work with irr 1.4?
It works on 1.3, but stopped functioning when i upgraded to 1.4.
It compiles and runs fine, but it's stopped detecting when i press a key.

eg

Code: Select all

               if (eventReceiver.leftMouseDown()==true) {
               cout << "Test" << endl;
               }
will never return true.

Is this just a problem with me, my computer or something wrong with illicht?
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

With you.

Try debugging it to see what's happening and if you won't find the problem post here what you get..

It should work just fine with 1.4 although someone rewrote it in a much better way..
I've extended it a little bit, I can give you if you want.. Oh and it works with 1.4.. (If I remember right.., I think I tested it with some pre-beta SVN version at the time..)
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

okay i want it

Post by 3DModelerMan »

This is exactly what I need. I use 1.4.1, so if it works with 1.4 then it should work with 1.4.1 to, where's the download for the improved one?.
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
vargero
Posts: 4
Joined: Mon Jun 16, 2008 12:06 pm

[Help]

Post by vargero »

I need some help to use this code. Well, I have a class named gamecontrol, that do all initialization stuff, camera control and the game loop, something like that:

Code: Select all

gamecontrol::gamecontrol(int RX, int RY, int PB, char WM) {



		switch (WM) {
				case 'f': windowMode = true;
				break;
				case 'j': windowMode = false;
		}

		dispositivo = createDevice(
							EDT_SOFTWARE,
							dimension2d<s32>(RX, RY),
							PB,
							windowMode,
							false,
							false,
							0);

		driver 	= dispositivo->getVideoDriver();
		smgr 	= dispositivo->getSceneManager();
		guienv = dispositivo->getGUIEnvironment();
		
		ISceneNode* playerNode = smgr->addEmptySceneNode();

		scene::ICameraSceneNode * cam = smgr->addCameraSceneNode(
                playerNode,                                      //parent
                vector3df(0,75,100),                             //angleX, angleH, distance
                playerNode->getPosition(), //vector3df(0,0,0),   //look at...
                -1);
		dispositivo->getCursorControl()->setVisible(true);

		LoadChars();

}


void gamecontrol::LoadChars() {

	Cviking = new viking(this);

}


void gamecontrol::SetTituloJanela(wchar_t* titulo) {

 dispositivo->setWindowCaption(titulo);

}


void gamecontrol::run() {

	ControlaMundo();



	while(dispositivo->run())
    {

        driver->beginScene(true, true, SColor(0,255,0,0));

			smgr->drawAll();

			guienv->drawAll();


		driver->endScene();
    }

}

gamecontrol::~gamecontrol() {

 dispositivo->drop();

}

void gamecontrol::ControlaMundo() {

	Cviking->SetMovAndando();

}
(How) can I use the MastEventReceiver code among with that?
3DModelerMan
Posts: 1691
Joined: Sun May 18, 2008 9:42 pm

this does'nt work

Post by 3DModelerMan »

How come this does'nt work? here's my code

Code: Select all

#include <irrlicht.h>

#include "MastEventReceiver.cpp"

using namespace irr;

using namespace core;

using namespace scene;

using namespace video;

using namespace io;

using namespace gui;

//================================================================================
//main function
int main(int argc, char** argv)
{   //the master event receiver

    MastEventReceiver eventReceiver;
    eventReceiver.init();

    //creates an Irrlicht device

    IrrlichtDevice *device =
        createDevice(EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
            false, false, false, &eventReceiver);

    //sets the window caption of the device
    device->setWindowCaption(L"Wolfpack.");

    // gets a pointer to the video driver scene manager and gui environment.
    IVideoDriver* driver = device->getVideoDriver();
    ISceneManager* smgr = device->getSceneManager();
    IGUIEnvironment* guienv = device->getGUIEnvironment();
    //=============================================================================

    guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
        rect<int>(10,10,200,22), true);

    if ( MastEventReceiver->keyPressed(KEY_ESCAPE ))
    {  device->closeDevice();  }
    //=============================================================================
    //end of main function
    while(device->run())
    {
        eventReceiver.endEventProcess();
       //draw the world
        driver->beginScene(true, true, SColor(0,200,200,200));

        smgr->drawAll();
        guienv->drawAll();

        driver->endScene();

        eventReceiver.startEventProcess();

    }

    //delete the Irrlicht device
    device->drop();

    return 0;
}

And here's the error that I get

Code: Select all

 error: base operand of `->' has non-pointer type `MastEventReceiver'
Thanks :D .
That would be illogical captain...

My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
Dark_Kilauea
Posts: 368
Joined: Tue Aug 21, 2007 1:43 am
Location: The Middle of Nowhere

Post by Dark_Kilauea »

Code: Select all

MastEventReceiver->keyPressed(KEY_ESCAPE )
Should be this:

Code: Select all

MastEventReceiver.keyPressed(KEY_ESCAPE )
rogerborg wrote:Every time someone learns to use a debugger, an angel gets their wings.
Post Reply