Advertisement Jump to content
Sign in to follow this  

OpenGL Camera Rotation problems

This topic is 2490 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

Hey so I have spent the past weekend trying to get my Camera to rotate in opengl, using quaternions. From what I understand the Math appears to be correct but when it runs, the camera just rotates to apparently wherever it feels like. Anyways here is the code hopefully some one can help me out here.

void Camera:: RotateCamera(double Angle, double _x, double _y, double _z)
std::cout<<" before point of focus ("<<pointOfFocus.x<<","<<pointOfFocus.y<<","<<pointOfFocus.z<<")"<<std::endl;
//create a quaternion given the angle and vector
Quaternion4f temp,temp2, Dist, result;
//get both sides of the rotation quaternion
temp.FromAxis(Vector3f(_x,_y,_z), Angle);
temp2 = temp.getConjugate();
//make the quaternion out of the direction vector
Dist = Quaternion4f(0,direction.x,direction.y,direction.z);
//rotate the DIST quaternion by temp
result = (temp * Dist) * temp2;
//set the new direction to be the result
direction.set(result.x, result.y, result.z);
//solve for new point of focus
pointOfFocus = direction + position;
//normalize the direction
std::cout<<" after point of focus ("<<pointOfFocus.x<<","<<pointOfFocus.y<<","<<pointOfFocus.z<<")"<<std::endl;

void Camera:: Render()

Thanks in advance

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!