# gluLookAt alternative

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

## 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 on other sites
Quote:
 Original post by McCoderOr ... 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:

// untestedfloat 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 on other sites
Quote:
Original post by polymorphed
Quote:
 Original post by McCoderOr ... 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 on other sites
Use other method.

[Edited by - polymorphed on September 19, 2008 2:30:37 PM]

##### 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 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 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, x0, 1, 0, y0, 0, 1, z0, 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.

1. 1
2. 2
3. 3
Rutin
22
4. 4
frob
18
5. 5

• 33
• 13
• 10
• 10
• 12
• ### Forum Statistics

• Total Topics
632569
• Total Posts
3007121

×