gluLookAt() with translate and rotate

Started by
2 comments, last by rumeshkumar 19 years, 3 months ago
I,ve been trying to look around for an implementation similar to gluLookAt() that has been done completely with translates and rotates (which I am pretty sure can be done). I do realise gluLookAt() makes life easier but it also limits the amount of control one has over the camera. I have done a simple but working implementation similar to gluLookAt() using matrices but am still lost trying to pull it off using just rotations and translates. Any help will be appreciated. Thanks a lot.
Advertisement
Quote:Original post by rumeshkumar
I,ve been trying to look around for an implementation similar to gluLookAt() that has been done completely with translates and rotates (which I am pretty sure can be done). I do realise gluLookAt() makes life easier but it also limits the amount of control one has over the camera. I have done a simple but working implementation similar to gluLookAt() using matrices but am still lost trying to pull it off using just rotations and translates. Any help will be appreciated. Thanks a lot.


Heres a small example :

// A camera at { 5.0f, 1.0f, 5.0f }GLfloat g_mCamera[16] = { 1.0f, 0.0f, 0.0f, 5.0f,                          0.0f, 1.0f, 0.0f, 1.0f,                          0.0f, 0.0f, 1.0f, 5.0f,                          0.0f, 0.0f, 0.0f, 1.0f ) ;GLvoid Render( ){   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;   glLoadIdentity( ) ;   // Sets up a camera with the above specified matrix, 'g_mCamera'   glMultMatrixf( g_mCamera ) ;  // Multiplies your camera matrix with the identity matrix    // Draw stuff    // swap buffers}
---http://www.michaelbolton.comI constantly dream about Michael Bolton.
The simplest solution is to perform a 'base change'...

Matrix ComputeViewMatrix(const Vector& look,                          const Vector& up,                          const Vector& view_position){  Vector j = up;  Vector k = -look  Vector i = j ^ k;    Matrix M = Matrix::IDENTITY;   // rotation part  M.SetCol(0, i);  // copy i in [0x0] [0x4] [0x8]   M.SetCol(1, j);  // copy j in [0x1] [0x5] [0x9]  M.SetCol(2, k);  // copy k in [0x2] [0x6] [0xA]  // translation part  Vector t = M * (-view_position);  M.SetRow(3, t ); // copy t in [0xC] [0xD] [0xE]   return(M);}


Not that by default OpenGL uses an identity...this means that you are looking toward -z.
If you use look = -z, up = y, pos = 0 you get the identity matrix.
Thanks guys... its starting to make sense now... Guess I was confused with the rotations required to move the camera accordingly.

This topic is closed to new replies.

Advertisement