controling a FPScam and a normal cam with the same keys

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.
Post Reply
knutcj
Posts: 5
Joined: Tue Jan 02, 2007 10:14 pm

controling a FPScam and a normal cam with the same keys

Post by knutcj »

Evnin' all.

I'm making an application where I want two different cameras, one normal FPScam and a normal cameranode I'm moving arround like an overview camera.
Anyways... I want to use the same keys for both, and I just can't figure out how to do it.

I want the FPScamera to move with the default settings (arrowkeys and mouse) so so far I've just added it with the keymap paramaeter set to 0 (zero). So in my eventreciever class, before I make a case for KEY_LEFT, KEY_RIGHT, etc. I go through an if statement that checks the ID of the active camera before I check for eventtype and then do the switch statement.

Code: Select all

if(smgr->getActiveCamera()->getID() == 2)
{
     if(event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown)
      {
      switch(event.KeyInput.Key)
            {
	//Left
	case KEY_LEFT:
                {
This makes my custom camera move perfectly, but nothing happens with the FPScam. Not even when I give it a keymap to play with

Code: Select all

//snatched from the API
SKeyMap keyMap[8];
keyMap[0].Action = EKA_MOVE_FORWARD;
keyMap[0].KeyCode = KEY_UP;
keyMap[1].Action = EKA_MOVE_FORWARD;
keyMap[1].KeyCode = KEY_KEY_W;

keyMap[2].Action = EKA_MOVE_BACKWARD;
keyMap[2].KeyCode = KEY_DOWN;
keyMap[3].Action = EKA_MOVE_BACKWARD;
keyMap[3].KeyCode = KEY_KEY_S;

keyMap[4].Action = EKA_STRAFE_LEFT;
keyMap[4].KeyCode = KEY_LEFT;
keyMap[5].Action = EKA_STRAFE_LEFT;
keyMap[5].KeyCode = KEY_KEY_A;

keyMap[6].Action = EKA_STRAFE_RIGHT;
keyMap[6].KeyCode = KEY_RIGHT;
keyMap[7].Action = EKA_STRAFE_RIGHT;
keyMap[7].KeyCode = KEY_KEY_D;

camera = smgr->addCameraSceneNodeFPS(0, 60.0f, 20.0f, 1, keyMap, 0, true);
This keymap doesn't even make the FPScamera move with the W,A,Sor D keys!?

since the addCameraSceneNode doesn't take an eventrecieverparameter (woah! Long word), I'm kinda stuck... Any ideas?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

You want two cameras to respond to key presses and mouse input simultaneously? I don't think that will work out very well because they both would need to access and update the mouse position.

If you want both cameras to be able to respond to keyboard and mouse input, but you want them to take turns responding to input, you need to provide the user with away to switch cameras. When the user wants to switch cameras, all you need to do is change the active camera. I provided code that did this for another user some time ago. You can find that code here.

If you are really convinced you need to write your camera movement code in your event receiver, you can't always handle the key/mouse input events. You need to let the events get processed as they normally would so that the FPS camera will use them. You can do this by returning false from your event receiver.

Travis
greenya
Posts: 1012
Joined: Sun Jan 21, 2007 1:46 pm
Location: Ukraine
Contact:

Re: controling a FPScam and a normal cam with the same keys

Post by greenya »

Size of Key Map missing.

This
knutcj wrote:

Code: Select all

camera = smgr->addCameraSceneNodeFPS(0, 60.0f, 20.0f, 1, keyMap, 0, true);
definetly should become

Code: Select all

camera = smgr->addCameraSceneNodeFPS(0, 60.0f, 20.0f, 1, keyMap, sizeof(keyMap), true);
rooly
Posts: 224
Joined: Tue Oct 25, 2005 4:32 pm
Location: Louisiana, USA, backwater country
Contact:

Post by rooly »

your forgetting one thing it seems. the fps camera sets itself as an event receiver. when you replace that data with your own event reciever, you effectively ignore any commands being sent to the fps cam. if you'd switch your call order, i'm sure you'll find that the fps cam works where the normal doesn't.
When banks compete, you win.
When ISPs compete, you win.
When electronics retailers compete, you win.
When governments compete...you get drafted.
knutcj
Posts: 5
Joined: Tue Jan 02, 2007 10:14 pm

Post by knutcj »

Thnx all.
Vitek - of course I'm switching the active camera. I should have mentioned that in the post.

Greenya - Thnx. I'd forgotten about that. That might stirr things up a bit... me hopes.

Rooly - This I haven't tried actually, and i will as soon as i get home from my boring day-job. The only thing is... If I don't use any of the keys used to control the FPScam in my eventreciever, both cameras work fine. So I don't think it'll work, but we'll see. Allso... I think I do add the FPScam to the scenemanager after I've adde the normal cameranode, if that's what you mean?

The reason I want this, is becaus I don't want the user to have to swithch hands whenever they change the camera. I allso don't want to have to create a completely new sett of movements for the FPS cam, as I'm quite sure I'll do a far worse job of it than what has already been done.
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

As pointed out by greenya, you need to pass the number of entries in the keymap. The code he posted was close but not correct.

Code: Select all

// you can do this. it automatically calculates the right value when
// you add or remove a key mapping
camera = smgr->addCameraSceneNodeFPS(0, 60.0f, 20.0f, 1, keyMap, sizeof(keyMap) / sizeof(*keyMap), true);

// or you could do this and update the size if you change the key mapping
camera = smgr->addCameraSceneNodeFPS(0, 60.0f, 20.0f, 1, keyMap, 8, true);
Also, you don't have to create a static camera and an FPS camera if you want both cameras to behave like FPS cameras. You can easily create two FPS cameras and switch between them with a key. You won't need to write a bunch of camera movement code in your event receiver. All you will have to do is write code to handle switching cameras. Again, the multiple camera example I linked to shows you what you need to do for that.

Travis
Post Reply