View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Applying Look At matrix

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1Alejandro  Members

Posted 29 December 2011 - 04:19 PM

I'm developing a camera class on OpenGL in C++, I want to see the position and rotation that the camera has when using gluLookAt(), for this I'm using glm::lookAt() function, it retrieves a matrix 4x4 and then I multiply the current stack matrix with the one that was retrieve, and then I translate the camera to the position.

So my code looks like this

void camera::drawDebug()
{
glm::mat4 res = glm::lookAt(eye, target, up);
glMultMatrixf(&res[0][0]);
glTranslatef(-eye.x, -eye.y, -eye.z);
glutWireCube(1.5);
}


with this code I get the following image, considering that the red cube is at the center(0, 0, 0), and the wire cube is the camera, eye is (0, 5, 5), target is (0, 0, 0), up is (0, 1, 0)

As you can see it appears that the rotation is applied correctly but the translation is not correct. I'm doing -eye translation because of what it says on the documentation of glulookat.

...gluLookAt is equivalent to glMultMatrixf(M); glTranslated (-eyex, -eyey, -eyez);

Any ideas on how to fix the translation?

### #2SiCrane  Moderators

Posted 29 December 2011 - 04:27 PM

I'm not 100% sure, but it looks like you're applying the eye transform twice. glm::lookAt() should already include the eye transform.

### #3Alejandro  Members

Posted 29 December 2011 - 05:01 PM

I try it, still not there, it looks similar to previous result.

### #4Alejandro  Members

Posted 29 December 2011 - 09:41 PM

Solved, if I inverse the matrix I get the results that I expected, at the end the code is like the following

void camera::drawDebug()
{
glm::mat4 res = glm::lookAt(eye, target, up);
res = glm::inverse(res);
glMultMatrixf(&res[0][0]);
glTranslatef(-eye.x, -eye.y, -eye.z);
glutWireCube(1.5);
}


Don't know exactly why this works.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.