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
larztheloser
Posts: 13
Joined: Thu Oct 08, 2009 8:58 pm
Location: New Zealand

Camera problem

Post by larztheloser »

Because I'm using windows to do my input I can't use the FPS or Maya camera classes.

What I've done is create a normal camera and made it float above a terrain. Then I made 4 global variables to store information about the camera's position: camx, camy, camz and camr (the last one being rotation). Then each frame I update the camera's position like so:

Code: Select all

camera->setPosition(core::vector3df(camx,camy,camz));
camera->setRotation(core::vector3df(0,camr,0));
It renders fine EXCEPT when camx, camy or camz are changing. What it does is focus on the last position the camera was in, until of course the camera stops moving. Turning the camera works fine. Moving and turning the camera, it turns right but the target of the camera is still wrong.

Any ideas as to why/how to fix this?
larztheloser
Posts: 13
Joined: Thu Oct 08, 2009 8:58 pm
Location: New Zealand

Post by larztheloser »

Sorry, I'll be even more descriptive of the problem.

Why does the camera tilt down when moving up, or up if moving down?
Why does the camera turn 180 degrees when moving forward?
Epi
Posts: 9
Joined: Wed Mar 04, 2009 4:27 am

Post by Epi »

maybe the camera is looking to its target, set by

Code: Select all

virtual void irr::scene::ICameraSceneNode::setTarget  	(  	const core::vector3df &   	 pos  	 )
larztheloser
Posts: 13
Joined: Thu Oct 08, 2009 8:58 pm
Location: New Zealand

Post by larztheloser »

I thought of that. But shouldn't that be handled by:

Code: Select all

cam->bindTargetAndRotation(true)
?
Thanks for trying!
larztheloser
Posts: 13
Joined: Thu Oct 08, 2009 8:58 pm
Location: New Zealand

Post by larztheloser »

Solved my own problem, I think.

For some reason, if you set the position, then render, then rotate, then update the absolute position, that works.

Can anybody tell me why? I'm confused - doesn't rendering the scene update the absolute position for me?
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Post by CuteAlien »

If you use setTarget then it still has the old position. Calling updateAbsolutePosition after the setPosition will fix that.
If you only use setRotation and not setTarget then I'm not sure what the problem is.

My own camera code also looks like this (including comments):

Code: Select all

    mIrrCamNode->setPosition( camPos );
    mIrrCamNode->updateAbsolutePosition();  // don't remove - see comment below
    // setTarget will set also the rotation.
    // This only works if setPosition and updateAbsolutePosition are called first
    mIrrCamNode->setTarget( targetPos );
    mIrrCamNode->updateAbsolutePosition();
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
larztheloser
Posts: 13
Joined: Thu Oct 08, 2009 8:58 pm
Location: New Zealand

Post by larztheloser »

Yeah - I'm only using setRotation.

Thanks for that code snippet though!
Post Reply