LookAt function for Quake 3 camera example

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
daarkron
Gnoblar
Posts: 16
Joined: Fri Nov 01, 2013 12:00 pm
Location: Switzerland

LookAt function for Quake 3 camera example

Post by daarkron »

Hello everyone,

I'm trying to implement the function lookAt for this camera version : http://www.ogre3d.org/tikiwiki/tiki-ind ... era+system.

Anyone has an idea how to do it ?

Thanks in advance
daarkron
Gnoblar
Posts: 16
Joined: Fri Nov 01, 2013 12:00 pm
Location: Switzerland

Re: LookAt function for Quake 3 camera example

Post by daarkron »

My first try was :

Code: Select all

void FreeCamera::lookAt(const Vector3& vec)
{
	Vector3 from = getDirectionVector();
	Vector3 to = vec - getPosition();
	Quaternion q = from.getRotationTo(to);

	cameraYawNode->yaw(q.getYaw());
	cameraPitchNode->pitch(q.getPitch());
}

const Vector3 FreeCamera::getDirectionVector()
{
	return cameraYawNode->getOrientation()
	            * cameraPitchNode->getOrientation()
	            * cameraRollNode->getOrientation()
	            * ogreCamera->getDirection();
}
But it doesn't work fine because getRotationTo has multiple return possibilities... So it's not a one shot move like Ogre::Camera::lookAt does.
mdoug
Gnoblar
Posts: 4
Joined: Sat Oct 19, 2013 11:15 pm

Re: LookAt function for Quake 3 camera example

Post by mdoug »

Sorry, I'm a little confused at what the problem is here, and to be perfectly honest i couldn't tell you what a quaternion is at this point though I'm sure I knew at some point, but assuming all your camera rotations are around the axis (axises? man, maths are hard), you can easily project the point onto the ground plane by just ignoring the Y coordinate (i.e., V3(p.x, 0.0f, p.z)), and then look at that point for the yaw node. Then you can get the pitch angle with a little trig, with Y value as the opposite, and the distance between the camera and the original point as the hypotenuse, and taking the sin of that gets you the pitch angle.

As to roll, I never really remember any rolling in quake 3 to be honest, so I'm not so sure what that is there for. Maybe for giving feel to the walking by having it tilt back and forth? Not sure what effect you'd be going for with that one I guess.

This is probably not that efficient, but since there's only one camera it should be good enough. There probably is a way to do it with quaternions that's more efficient, but assuming there's just one camera, I don't really think it would be much of a problem. And as I feel like I'm missing something in all this, sorry if none of this helps.
Post Reply