FPS Camera and Event Reciever

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
[ds] Swift
Posts: 20
Joined: Sun Nov 14, 2004 1:57 am
Location: Rochester, New York, USA

FPS Camera and Event Reciever

Post by [ds] Swift »

when i add an event reciever to the scene, it removes the built in controls for the camera which leaves me to set up key events to move it.

i cant figure out how to move the camera forward ( in the direction it is pointing ) or backards or strafe in that matter.

i want to be able to have an event reciever to allow the user to move, jump, crouch, w/e and also be able to still navigate, lol.

any solutions would be greatly appreciated. :)
There's a crack in everything -- That's how the light gets in.
[ds] Swift
Posts: 20
Joined: Sun Nov 14, 2004 1:57 am
Location: Rochester, New York, USA

Post by [ds] Swift »

never mind ppl. i figured it out.

if you add an event reciever, you need to add a SKeyMap[] to your camera for it to move via user input.

Code: Select all

SKeyMap keyMap[8];
keyMap[0].Action = EKA_MOVE_FORWARD; // what the key does
keyMap[0].KeyCode = KEY_UP; // what the key is
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;
then when you add your camera:

Code: Select all

camera = scenemgr -> addCameraSceneNodeFPS( 0, 100.0f, 300.0, -1, keyMap, 8 );
then inside your OnEvent(SEvent event) method. ( this is your event reciever. check the tutorials for more info. )

Code: Select all

if ( device -> getSceneManager() -> getActiveCamera() ) {
    device -> getSceneManager() -> getActiveCamera() -> OnEvent( event );
    return true;
}
jumping and crouching support are not built in, and must be created in your event reciever.
There's a crack in everything -- That's how the light gets in.
Post Reply