Move camera on a plane - weird rotation

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
Dr_Asik
Posts: 18
Joined: Wed Jun 02, 2010 2:15 am

Move camera on a plane - weird rotation

Post by Dr_Asik »

I'm trying to implement a camera that moves on a horizontal plane, with the arrow keys of the keyboard. I figured that if I move the camera's position and target by the same amount, it should do the trick.

Well it sort of does, but the camera seems to tilt slightly around its forward axis. When I move right it banks on one side, when I move left it banks on the other. This seems imprecise too, when I move back to where I originally was I may still have some amount of rotation.

Here's my function's code::

Code: Select all

void MoveCamera(int x, int y)
{
	float delta = 10.0f;
	vector3df& currentPosition = m_activeCamera->getAbsolutePosition();
	vector3df currentTarget = m_activeCamera->getTarget();
	currentPosition.X += x;
	currentPosition.Y += y;
	currentTarget.X += x;
	currentTarget.Y += y;
	m_activeCamera->setPosition(currentPosition);
	m_activeCamera->setTarget(currentTarget);
}
What am I doing wrong?
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Try adding camera->updateAbsolutePosition() afterwards.

You could also make the camera a child of an empty scenenode and move this empty node instead of the camera. Sometimes it makes things easier, especially if it comes to rotation.
Never take advice from someone who likes to give advice, so take my advice and don't take it.
Post Reply