Sign in to follow this  

Generic Quaternion Camera Class

This topic is 3775 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;
	temp.Conjugate();

	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:
	m_Camera.Position(50.0f,600.0f,-300.0f);
	m_Camera.LookAt(50.0f,0.0f,0.0f);
	m_Camera.Up(0.0f,1.0f,0.0f);
	m_Camera.Far(3000.0f);
	m_Camera.Near(1.0f);
	m_Camera.Aspect(3.14f/4.0f);
	m_Camera.FOV(800.0f/600.0f);


And lastly, I'm just trying to get the rotation working, so during update I'm calling this;
m_Camera.Rotate(0.1f,0.0f,1.0f,0.0f);

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

This topic is 3775 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.

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