Jump to content
  • Advertisement
Sign in to follow this  
alejandro

Applying Look At matrix

This topic is 2537 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'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)

quickimage.gif

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);
[/quote]

Any ideas on how to fix the translation?

Share this post


Link to post
Share on other sites
Advertisement
I'm not 100% sure, but it looks like you're applying the eye transform twice. glm::lookAt() should already include the eye transform.

Share this post


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

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!