Sign in to follow this  

gluLookAt alternative

This topic is 3371 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

Is there an gluLookAt alternative? I dont want to move the object in order to simulate camera movement. Or ... if I am using glTranslate, is there a way to RESET the objects coordinates so where the object is moved is now 0,0,0?

Share this post


Link to post
Share on other sites
Quote:
Original post by McCoder
Or ... if I am using glTranslate, is there a way to RESET the objects coordinates so where the object is moved is now 0,0,0?


Use glGetFloatv() and then glTranslatef(), like this:


// untested
float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
glTranslatef(-matrix[12], -matrix[13], -matrix[14]); // x - x = 0




[Edited by - polymorphed on September 19, 2008 2:06:39 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by polymorphed
Quote:
Original post by McCoder
Or ... if I am using glTranslate, is there a way to RESET the objects coordinates so where the object is moved is now 0,0,0?


Use glGetFloatv() and then glTranslatef(), like this:

*** Source Snippet Removed ***



Thanks, I cant understand your code though. I declare a 4x4 matrix, empty. I retrieve the info of the current modelview matrix ... and then what? I can't understand why 13, 14, 15. So it's element 13, 14, 15 as x, y, z, but why with minus?

Share this post


Link to post
Share on other sites
The previous method won't work well if you're planning on doing some rotation as well though [smile].
Here's a better method:


float matrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
matrix[12] = 0;
matrix[13] = 0;
matrix[14] = 0;
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(matrix);


Share this post


Link to post
Share on other sites
Ah, makes sense, I did not know that when you translate you actually add to the matrix. Good thing to keep in mind, also, must brush up on my matrix math. So OpenGL uses the 13, 14, 15 element in a matrix for x coord stuff?

Share this post


Link to post
Share on other sites
Well it actually doesn't add to it, that was the wrong way to put it, sorry.
What really happens is a matrix multiplication.
When you call glTranslatef(x, y, z), a temporary matrix is constructed, which looks like this:


1, 0, 0, x
0, 1, 0, y
0, 0, 1, z
0, 0, 0, 1



This matrix is then multiplied with the current matrix (modelview matrix, for example). This allows for the current orientation (stored in the upper left 3x3 quadrant of the matrix) to affect the translation.

And yes, since OpenGL stores its matrices in column-major order, when you map the matrix from 2D to 1D, it'll look like this:


A, B, C, D
E, F, G, H --> A, E, I, M, B, F, J, N, C, G, K, O, D, H, L, P
I, J, K, L
M, N, O, P



D, H and L is the translation component.

Share this post


Link to post
Share on other sites

This topic is 3371 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this