move forwards with FPS cam

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
wEEp
Posts: 70
Joined: Thu Nov 27, 2008 7:55 am

move forwards with FPS cam

Post by wEEp »

Hey folks,

I want to programm a FPS camera which u can move around. I got this src from the tut:

Code: Select all


//NODE = the cameranode (scenecamera....)
 const f32 MOVEMENT_SPEED = 5.f;

        while(device->run())
        {
                // Work out a frame delta time.
                const u32 now = device->getTimer()->getTime();
                const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
                then = now;

                core::vector3df nodePosition = node->getPosition();

                if(receiver.IsKeyDown(irr::KEY_KEY_W))
                        nodePosition.Y += MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_S))
                        nodePosition.Y -= MOVEMENT_SPEED * frameDeltaTime;

                if(receiver.IsKeyDown(irr::KEY_KEY_A))
                        nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
                else if(receiver.IsKeyDown(irr::KEY_KEY_D))
                        nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;

                node->setPosition(nodePosition); 

                driver->beginScene(true, true, video::SColor(255,113,113,133));

....
I declared then a node as camera node. When i now press "W" the camare moves to the top and not straight forward. Do u have an idea how to make it that the camera moves forward? I tested alot etc. but i dont get the solution.

THANKS
Sylence
Posts: 725
Joined: Sat Mar 03, 2007 9:01 pm
Location: Germany
Contact:

Post by Sylence »

It moves upwards because the Y axis is for up and down.

You have to change the X axis.

Then if you have a node that is somehow rotated you have to rotate the movement according to the nodes rotation. I bet there are snippets for this somewhere in the forums.
Software documentation is like sex. If it's good you want more. If it's bad it's better than nothing.
wEEp
Posts: 70
Joined: Thu Nov 27, 2008 7:55 am

Post by wEEp »

ye why it moves to the top is clear but i dont have an idea how to change it...im playing abit around :)

THanks for ur help!

edit:// Im such an idiot...-.-

nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime;

Sorry...i just had 3hrs of sleep the last 2 days ^_^
wEEp
Posts: 70
Joined: Thu Nov 27, 2008 7:55 am

Post by wEEp »

Sorry...i've got aother problem

Code: Select all

const f32 MOVEMENT_SPEED = 500.f;

	while(device->run())
	if (device->isWindowActive())
	{
		const u32 now = device->getTimer()->getTime();
		const f32 frameDeltaTime = (f32)(now - then) / 1000.f; // Time in seconds
		then = now;

		/* Check if keys W, S, A or D are being held down, and move the
		sphere node around respectively. */
		core::vector3df nodePosition = camera->getPosition();

		if(receiver.IsKeyDown(irr::KEY_KEY_W))
			nodePosition.Z += MOVEMENT_SPEED * frameDeltaTime;
		else if(receiver.IsKeyDown(irr::KEY_KEY_S))
			nodePosition.Z -= MOVEMENT_SPEED * frameDeltaTime;

		if(receiver.IsKeyDown(irr::KEY_KEY_A))
			nodePosition.X -= MOVEMENT_SPEED * frameDeltaTime;
		else if(receiver.IsKeyDown(irr::KEY_KEY_D))
			nodePosition.X += MOVEMENT_SPEED * frameDeltaTime;

		camera->setPosition(nodePosition);
How can i make that he goes there where my camera looks at not just the Z axis.

When i press W the camera just goes to one side but i want that the camera goes there where i look at.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Why are you not just using the built in FPS camera?

If you're hell bent on making your own just look at the FPS camera source to get the idea of how to do it.
Image Image Image
wEEp
Posts: 70
Joined: Thu Nov 27, 2008 7:55 am

Post by wEEp »

how can i do it with ur solution? Can u give me some examples?
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

Go back and look at the source code for the tutorials. Nearly every one of them uses the FPS camera. The demo shows how to use a keyboard map if you want to assign different keys to the camera movement actions.

Travis
wEEp
Posts: 70
Joined: Thu Nov 27, 2008 7:55 am

Post by wEEp »

Yes, but i want to move the camera arond the map.

I looked alrdy in the demo but i couldn't find how it moves the camera around.
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

It's just all setup for you... You create an FPS camera with the scenemanager (smgr->addCameraSceneNodeFPS()) and then when you press the arrow keys it moves the camera, when you move the mouse it rotates the camera... simple as that, it's all handled within Irrlicht.

As vitek says the Demo example shows you how you can assign different keys to the movement of the FPS camera, search the example for SKeyMap and it should be clear.
Image Image Image
wEEp
Posts: 70
Joined: Thu Nov 27, 2008 7:55 am

Post by wEEp »

JP wrote:It's just all setup for you... You create an FPS camera with the scenemanager (smgr->addCameraSceneNodeFPS()) and then when you press the arrow keys it moves the camera, when you move the mouse it rotates the camera... simple as that, it's all handled within Irrlicht.
OMG i didn't know that..im so sorry :(

and i looked in the demo and i searched for "KEY_KEY_W" this is why i couldn't find it.
edit://

I got it now...thanks for all ur help!!!
Post Reply