Problem with the events
-
- Posts: 73
- Joined: Thu Apr 05, 2007 7:01 pm
- Location: France
- Contact:
Problem with the events
Hello all, for a little game, i would like to create a camera like in RTS games. I've made the first part (with the mouse), and now i would like when i press a key that the camera moves.
For my camera i have a class, and i do not know how i can do to use this class in the member OnEvent of the class MyEventReceiver.
Can you help me?
Thanks a lot.
For my camera i have a class, and i do not know how i can do to use this class in the member OnEvent of the class MyEventReceiver.
Can you help me?
Thanks a lot.
When you want you can!
Quand on veut on peut!
Quand on veut on peut!
-
- Posts: 73
- Joined: Thu Apr 05, 2007 7:01 pm
- Location: France
- Contact:
-
- Posts: 73
- Joined: Thu Apr 05, 2007 7:01 pm
- Location: France
- Contact:
My event receiver using keysDown[]:
As you see constructor assigns default false value to all keysDown[] array members and then OnEvent() sets specific member to true or false when it is pressed down or not pressed down.
Code: Select all
Controller::Controller()
{
u32 k = 0;
for (k = 0; k < KEY_KEY_CODES_COUNT; ++k)
keysDown[k] = false;
printf("Controller created\n");
}
bool Controller::OnEvent(SEvent event)
{
if(event.EventType == EET_KEY_INPUT_EVENT)
{
keysDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
}
else
return false;
}
-
- Posts: 73
- Joined: Thu Apr 05, 2007 7:01 pm
- Location: France
- Contact:
Ok, but then how can i apply this code for my camera? (i'm sorry but i'm really a newbie with Irrlicht). In fact would you can show me a code who does this: the full class MyEventReceiver (that you've called Controller isn't it?), and then a code who shows how to use this for the camera?
Thanks a lot
Thanks a lot
When you want you can!
Quand on veut on peut!
Quand on veut on peut!
-
- Posts: 73
- Joined: Thu Apr 05, 2007 7:01 pm
- Location: France
- Contact:
Actualy i would like to know if i can do this in a function in an other file:
This code wouldn't be in the Controller class.
Code: Select all
if(keysDown[KEY_KEY_I])
{
/* My camera's action */
}
When you want you can!
Quand on veut on peut!
Quand on veut on peut!
From ICameraSceneNode.h
Basically, the active camera node gets input on it's own, in the same way as a user created event receiver, so you don't need to catch the input in the event receiver and pass it to the cam, it's done automatically.
Code: Select all
//! It is possible to send mouse and key events to the camera.
/** Most cameras
may ignore this input, but camera scene nodes which are created for
example with ISceneManager::addMayaCameraSceneNode or
ISceneManager::addMeshViewerCameraSceneNode, may want to get this input
for changing their position, look at target or whatever. */
virtual bool OnEvent(SEvent event) = 0;
If you don't have anything nice to say, don't say anything at all.
-
- Posts: 73
- Joined: Thu Apr 05, 2007 7:01 pm
- Location: France
- Contact:
you have to create bool OnEvent(SEvent event); method in your camera then. it should be very similar to that i wrote you before.
Its not hard to answer to you but i suggest you firstly take a deep look at tutorials and never ask information that you can find yourself. I know its hard in the beginning but now you are asking us tu write for you what you need. Its not good. you will never learn
Code: Select all
bool YourCamClass::OnEvent(SEvent event)
{
if(event.EventType == EET_KEY_INPUT_EVENT) //Checks if keyboard key is pressed down
{
if(event.KeyInput.Key == KEY_KEY_I)
{
// do your stuff
return true;
}
}
else
return false;
}
-
- Posts: 73
- Joined: Thu Apr 05, 2007 7:01 pm
- Location: France
- Contact:
Yes i know and i'm sorry, i search but i don't find, i don't think yet Irrlicht ^^roxaz wrote:Its not hard to answer to you but i suggest you firstly take a deep look at tutorials and never ask information that you can find yourself. I know its hard in the beginning but now you are asking us tu write for you what you need. Its not good. you will never learn
I've understood your code, and i've tried it, but that does not work
This is my code (just the importants parts):
Code: Select all
/* The declaration of my class */
class RTSCamera
{
private:
/* Caméra */
irr::scene::ICameraSceneNode *mp_camera;
/* Variables pour l'environnement */
irr::video::IVideoDriver* mp_driver;
irr::scene::ISceneManager* mp_smgr;
irr::gui::IGUIEnvironment* mp_env;
/* Variable contenant l'état des touches du clavier */
bool m_keysDown[irr::KEY_KEY_CODES_COUNT];
public:
/* Fonction pour la gestion des évennements */
bool OnEvent(irr::SEvent event);
/* Constructeur */
RTSCamera(irr::video::IVideoDriver* driver, irr::scene::ISceneManager* smgr,
irr::gui::IGUIEnvironment* env);
/* Constructeur de copie */
RTSCamera(const RTSCamera &Camera);
/* Destructeur */
~RTSCamera(void);
};
/* The code of the events */
/* Fonction pour la gestion des évennements */
bool RTSCamera::OnEvent(SEvent event)
{
std::cout << "ok" << std::endl;
/* On regarde si il y a un évennement venant d'une touche */
if(event.EventType == EET_KEY_INPUT_EVENT)
{
m_keysDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return true;
}
else
{
return false;
}
}
Thanks a lot
When you want you can!
Quand on veut on peut!
Quand on veut on peut!
You need to hook your camera helper into the event system somehow. You can do this a few different ways.
- you could make RTSCamera inherit from IEventReceiver and pass a pointer to your rts camera to the device method setEventReceiver.
- you could make RTSCamera inherit from ICameraSceneNode and you could make your camera delegate method calls to the camera that you keep a pointer to. You would have to tell the scene manager that your camera is the active camera by calling setActiveCamera.
- you could use your own external event receiver [see tutorials] that forwards key press events to your camera.
- you could write an event receiver that just sets the key states [pressed or not] and then call methods on the RTSCamera to tell it what to do based on the pressed keys.