Sign in to follow this  

Generic Quaternion Camera Class

Recommended Posts

Guys, I'm pulling out my hair cuase this should be easy, but I can't figure out why in the world my camera class is not working, here's the code for the rotation:
void Camera::Rotate(float angle,float x,float y,float z)
	Quaternionf temp, quat_view, result;

	temp.x = x * sin(angle/2);
	temp.y = y * sin(angle/2);
	temp.z = z * sin(angle/2);
	temp.w = cos(angle/2);

	quat_view.x = m_LookAt.X();
	quat_view.y = m_LookAt.Y();
	quat_view.z = m_LookAt.Z();
	quat_view.w = 0;

	Quaternionf preConj = temp * quat_view;

	result = preConj * temp;

	m_LookAt.X( result.x );
	m_LookAt.Y( result.y );
	m_LookAt.Z( result.z );

Here's how my game initializes the camera:

And lastly, I'm just trying to get the rotation working, so during update I'm calling this;

It just jiggles the camera, but no real movement??? Any ideas??? Thanks in advance Jeff.

Share this post

Link to post
Share on other sites
Are you sure the quaternion multiplication and conjugation functions are implemented correctly, and that the Quaternionf.Conjugate() method alters the quaternion in place instead of returning a value?

Share this post

Link to post
Share on other sites
Is m_lookAt the target point for the camera (as the code suggests), or is it a view direction? If it's the former, then rotating it as you're doing is almost certainly not going to give you the results you're looking for.

Also, my usual mini-rant: The use of quaternions here is not only pointless, but actually serves to obfuscate what would otherwise be a fairly straightforward operation (in fact, eliminating the quaternions would be a good first step toward figuring out what the real problem is). Furthermore, the whole 'rotate the look-at point/vector' approach to camera control is equally pointless and obfuscated (IMO, at least). Whatever camera control scheme you're after (FPS, 6DOF, orbital, etc.), there is almost certainly a better way to go about it.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this