FPS camera problem

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
ebe
Posts: 4
Joined: Sun Nov 02, 2008 10:02 pm

FPS camera problem

Post by ebe »

Hi everyone!


I'm trying attache a node to the camera,

it almost works but only when i move camera,
forward to backward or right to left...

when i rotate cam cube doesn't do anything

is a simply way to make it work with rotation?


my code:

Code: Select all

cam=device->getSceneManager()->
addCameraSceneNodeFPS(0,120,400,-1,keyMap,8,true,10.0f);

scene::IMeshSceneNode *cube= device->getSceneManager()->addCubeSceneNode
(5,device->getSceneManager()->getActiveCamera(),-1,core::vector3df(0,0,100));
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

In Irrlicht, a camera scene node's rotation (setRotation() / getRotation()) is independent of its look-at direction (setTarget()).

This allows for more flexibility, but is (initially) confusing and somewhat non-intuitive.

If you call this every time round your main loop, it will update the FPS camera's scene node rotation to match its look at position.

Code: Select all

cam->setRotation((cam->getTarget() - cam->getAbsolutePosition()).getHorizontalAngle());
Last edited by rogerborg on Mon Nov 03, 2008 3:14 pm, edited 1 time in total.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

rogerborg wrote:In Irrlicht, a camera scene node's rotation (setRotation() / getRotation()) is not the same as its look-at direction (setTarget()).

This allows for more flexibility, but is confusing and non-intuitive.

If you call this every time round your main loop, it will update the FPS camera's scene node rotation to match its look at position.

Code: Select all

cam->setRotation((cam->getTarget() - cam->getAbsolutePosition()).getHorizontalAngle());
but this doesn't matter if the camera is the parent of the node (what it is in this case)... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Oh, you're right; the FPS camera does match its rotation to its target, so it shouldn't be necessary to do anything.

ebe, can you explain what you expect to see happening, and what you actually see happening? The code that you've posted looks fine, if you want the cube to stay in front of the camera at all times, and always facing away from the camera.
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
ebe
Posts: 4
Joined: Sun Nov 02, 2008 10:02 pm

Post by ebe »

yes i want to place object in front of camera , but it didn't work with parenting...

when i rotate my camera for example for 180 degree i dont see a cube because it's on opposite site , it'smy problem

but your code solved my problem
thank's rogerborg :D
Acki
Posts: 3496
Joined: Tue Jun 29, 2004 12:04 am
Location: Nobody's Place (Venlo NL)
Contact:

Post by Acki »

ebe wrote:yes i want to place object in front of camera , but it didn't work with parenting...

when i rotate my camera for example for 180 degree i dont see a cube because it's on opposite site , it'smy problem
it should work as long as the parent/child relationship is correct... ;)
while(!asleep) sheep++;
IrrExtensions:Image
http://abusoft.g0dsoft.com
try Stendhal a MORPG written in Java
Post Reply