Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Need Help Understanding Camera Class

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

I've done some research on rotation transformation matrices and looked at some people's implementations of an OpenGL Camera class. Their code was nice and all however, I'm trying to understand this so I can write the camera class myself without needing to look at their code. I can't figure out some things, though: Take this part of the Camera3B class from Apron Tutorials, which creates a FPS style camera:
[source lang"cpp"]
void CCamera::Rotate_View(float speed)
1.   tVector3 vVector = mView - mPos; // Get view vector

2.   mView.z += sin(speed)*vVector.x + cos(speed)*vVector.z);
3.   mView.x += cos(speed)*vVector.x - sin(speed)*vVector.z);

Why is the view vector recalculated on Line 1? Now there are two view vectors and this confused me. I understand on Line2 and Line3 that they're multiplying it by the [Ry] transpose matrix. I guess if you answer the first question I can deduce why they multiply the recalculated vVector components of X and Z instead of the mView components of X and Z. Also, this is confusing:

void CCamera::Strafe_Camera(float speed)
1.   tVector3 vVector = mView - mPos;
2.   tVector3 vOrthoVector; // Orthogonal view for view vector

3.   vVector.x = -vVector.z;
4.   vVector.z = vVector.x

5.   mPos.x += vOrthoVector.x*speed;
6.   mPos.z += vOrthoVector.z*speed;
7.   mView.x += vOrthoVector.x*speed
8.   mView.z += vOrthoVector.z*speed;


Why is an orthoganal vector calculated on Line2? This doesn't seem necessary since you can just update the mPos.X value for Strafing, right? Or does this produce incorrect results that just "look" correct? I just thought about it while looking for typos that they take an Orthogonal view because of the camera is rotating so they need to switch the views... This sounds wrong because of the possibility the Camera hasn't rotated at all. I figured because it's an orthoganl (perpendicular) that they had to switch the axis on Line3 and Line4. Line5 to Line8 should become clear after explaining why they calculated the OrthoVector.

Share this post

Link to post
Share on other sites
I decided to draw it out and that made everything much more clear for the first part:

Now, when you when you calculate the new m_View you add relative to its current position: vVector*speed, which determines its new position. Because you're just multiplying a scalar value, the object should move in a straight line.

You couldn't have just used m_View*speed because this wouldn't be relative to the location of the camera! For instance if the camera was located at ( 1, 0, 0 ) if you hadn't of subtracted you can see how it wouldn't have been relative to the camera's location.

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!