# 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.

## 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 direction.normalize(); std::cout<<" after point of focus ("<<pointOfFocus.x<<","<<pointOfFocus.y<<","<<pointOfFocus.z<<")"<<std::endl; }

void Camera:: Render() { gluLookAt( position.x, position.y, position.z, pointOfFocus.x, pointOfFocus.y, pointOfFocus.z, up.x, up.y, up.z); }

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634090
• Total Posts
3015432
×