Jump to content
  • Advertisement
Sign in to follow this  
xiaowei

OpenGL OpenGL gluLookAt camera

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

Hello, i have a problem with gluLookAt. I have camera class and so far it works. i can move forward backwards left right and rotate in x and y direction. But I dont know, how to rotate around a certain point. LEt's Say I want to rotate around point 0,0,0. My camera's position is at 0,0,10. I tried to solve this problem but i still have problems. They occure when i rotate around y then around z. X works fine. But Y and Z dont. When I rotate Z after Y,X rotation my Cube rotates a bit left, and then it turns over and rotates right. So it swing left and right. So, i really cant mix rotations. My Idea was to save the distance (vector) from the point where i want to rotate around and camera position.Then i rotate the camera vectors and then move the camera position to the point where i want to rotate around. Finally i build a vector from current camera position to rotatet view vector and then move the camera back along this new normalized vector times the magnitude of the saved distance vector. guys i hope you could follow me. :(
void CCamera::RotateX(float fArg)
{
        // set rotation matrix
	m_mRotationMatrix.SetXRotationMatrix(fArgument);	
        // rotate camera vectors
	m_vViewVector = (m_mRotationMatrix * m_vViewVector).Normalize();	
	m_vUpVector   = (m_mRotationMatrix * m_vUpVector).Normalize();

	// set camera to origin
	m_vPosition.SetAll(0.0f, 0.0f, 0.0f);

	// compute direction vector from Null position to view vector
	Vector3f vDirection = m_vViewVector - m_vPosition;
	
	// translate cameraposition in direction-vector direction
	m_vPosition = m_vPosition + (vDirection * -vDistance.Magnitude());
}
When i start the programm and want to y-rotate it works. then i close the program and restart. Now rotating x axis works fine too. Same procedure with z axis. But if mix rotations it dosnt work fine. Does anyone has an idea how to fix this problem ? greetings, xiaowei

Share this post


Link to post
Share on other sites
Advertisement
http://en.wikipedia.org/wiki/Gimbal_lock

u should be able to google further info + solutions

Share this post


Link to post
Share on other sites
Hello, thanks for your reply.
Well i thought again about my problem. Maybe it is caused because when i rotate around x,y,z together i actually rotate around abitrary axes. So I should compute the rotation axes before a rotation. For example x rotation i compute a rotaion axis that is the vector from camera position to view point.

That could be possilbe as well, right ?

greetings,
xiaowei

Share this post


Link to post
Share on other sites
>>Hello, thanks for your reply.

dont thank me, just look up about gimbal lock, theres lots of info on the internet about it + possible solutions
eg
http://www.sjbaker.org/steve/omniv/eulers_are_evil.html

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!