Jump to content
  • Advertisement
Sign in to follow this  
BlodBath

OpenGL OpenGL Camera Issues

This topic is 3492 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 written a couple other openGL camera's before, but for some reason this one is giving me trouble and I just can't see where the problem is.
class Camera  {
public:
   Camera(const Camera & cam)  {
      _transform = cam._transform;
   }

   Camera(Vector & position, Vector & lookAtPoint, Vector & up)  {
      Vector look = lookAtPoint - position;
      VectorMath::Normalize(look);

      Vector right = VectorMath::Cross(up, look);

      _transform.GetColumn(0) = right;
      _transform.GetColumn(1) = VectorMath::Cross(look, right);
      _transform.GetColumn(2) = look;
      _transform.GetColumn(3) = position;
      _normalize();

      _transform.InvertAffine();

   }

   void SetView() {
      glLoadMatrixf(_transform.ToGLMatrix());
   }

   void SetPosition(Vector & position)  {
      _transform[3] = position * -1.0f;
   }

   void Rotate(float amount, Vector & axis)  {
      float temp[16];
      glMatrixMode(GL_MODELVIEW);
	   glPushMatrix();

	   glLoadMatrixf(_transform.ToGLMatrix());
	   glRotatef(-amount, axis.x, axis.y, axis.z);

	   glGetFloatv(GL_MODELVIEW_MATRIX, temp);
      _transform.FromGLMatrix(temp);

	   glPopMatrix();
   }

   void Move(Vector & amount)  {
      _transform[3].x += -amount.x;
      _transform[3].y += -amount.y;
      _transform[3].z += -amount.z;
   }

   inline Vector GetPosition() {
      return _transform[3] * -1.0f;
   }

   inline Vector GetLook() {
      return _transform.GetRow(2);
   }

private:

   void _normalize()  {
      VectorMath::Normalize(_transform[0]);
      VectorMath::Normalize(_transform[1]);
      VectorMath::Normalize(_transform[2]);
   }

   Matrix _transform;
};


And in my rendering loop:
mainCam.SetView();

// For brevity the input handling code is omitted but certain 
// input calls the following functions
mainCam.Rotate(len * 0.5f, axis);
mainCam.Move(Vector(dx * 0.05f, -dy * 0.05f));


The problem is that rotations don't properly rotate the camera. When I call Rotate() it just rotates the objects around the origin rather than rotating the camera around it's local coordinates. I'm sure I just am having a mental block but I've been playing with it for a few hours and haven't made any progress.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by BlodBath
The problem is that rotations don't properly rotate the camera. When I call Rotate() it just rotates the objects around the origin rather than rotating the camera around it's local coordinates.


Well, when you say rotate about the origin, do you mean the origin of the scene (which you might be looking at), or do you mean the origin of the camera. Because the last thing is the exact same thing as rotating the camera around itself (in the opposite direction).

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!