Jump to content
  • Advertisement
Sign in to follow this  
rumeshkumar

gluLookAt() with translate and rotate

This topic is 4884 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 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 this post


Link to post
Share on other sites
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
}


Share this post


Link to post
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 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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!