# gluLookAt() with translate and rotate

This topic is 5058 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
Quote:
 Original post by rumeshkumarI,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}

##### Share on other sites
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.

##### Share on other sites
Thanks guys... its starting to make sense now... Guess I was confused with the rotations required to move the camera accordingly.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633294
• Total Posts
3011241
• ### Who's Online (See full list)

There are no registered users currently online

×