Problem with the events

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
The BasheR
Posts: 73
Joined: Thu Apr 05, 2007 7:01 pm
Location: France
Contact:

Post by The BasheR »

Ok, thank you but i have any questions:

1- For the first way, is it possible in my code to pass to the device 2 methods setEventReceiver? Because i need my own external event receiver for the general code, and i need also the event for the camera, so is it possible to have 2 eventReceiver for the device?
2- For the 4th way, if i write this code, would it work?

Code: Select all

/* My own external event receiver class */
class MyEventReceiver : public IEventReceiver
{
public:
   MyEventReceiver(bool* keysDown)
	{
             u32 k = 0;
            for (k = 0; k < KEY_KEY_CODES_COUNT; ++k)
            {
                   m_keysDown[k] = keysDown[k];
             }
	}

	bool OnEvent(SEvent event)
	{
             if(event.EventType == EET_KEY_INPUT_EVENT)
            {
                  m_keysDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
                 return true;
             }
             else
             {
                  return false;
              } 
	}
private:
   bool m_keysDown[KEY_KEY_CODES_COUNT];
};


/* My main function */
int main()
{
   /*....... My code ......*/
   MyEventReceiver receiver(Camera.getKeysDown());
   device->setEventReceiver(&receiver);
   /*........ My code .....*/
}
In this code Camera.getKeysDown() would return a table of bools.

EDIT The answer for my first question is no, so i foget it.
I've tried the second way but i've an error who says:

"can not declare variable 'camera' to be of type 'RTSCamera'
because the following virtuals functions are abstract:
virtual void irr::scene::ISceneNode::render()
........."

Someone can explain me this error and how to resolve it?[/b]
When you want you can!
Quand on veut on peut!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

The answer to your first question is yes. You can create an event receiver that forwards events to your other event receiver and your camera. This can be very useful, but you can cause yourself some headaches.

Yes, your code would probably work. I don't know if I'd implement it that way, but it looks like it would work.

If you make RTSCamera inherit from ICameraSceneNode you need to implement all of the abstract methods in your derived class.

Travis
The BasheR
Posts: 73
Joined: Thu Apr 05, 2007 7:01 pm
Location: France
Contact:

Post by The BasheR »

For my code, i think it would work, but it would not do what i want, because i want it to modify directly the table of bools in the camera class, and in my code that is an other table of bools who is modified.

Then for the problem with the error message:
Have i to recode all the abstracts functions or, have i only to put their prototype in the header of my class?

Also can you give me an example for the first way? Because i'm lost :(
Thank you
When you want you can!
Quand on veut on peut!
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

because i want it to modify directly the table of bools in the camera class
You can't do that. You can't access private members of a class that you are not a friend of.
Have i to recode all the abstracts functions or, have i only to put their prototype in the header of my class?
You have to write them out. They would just call the functions of the camera that your RTS camera contains, so they would just be one line long.
Also can you give me an example for the first way?
Um, you've already done that above...
The BasheR
Posts: 73
Joined: Thu Apr 05, 2007 7:01 pm
Location: France
Contact:

Post by The BasheR »

Thank you that's working :)
When you want you can!
Quand on veut on peut!
Post Reply