Advertisement Jump to content
Sign in to follow this  
theJuniorOne

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
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);
}


Thanks in advance

Share this post


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

  • Advertisement
×

Important Information

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

GameDev.net 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!