Jump to content
  • Advertisement
Sign in to follow this  

Generic Quaternion Camera Class

This topic is 4060 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!