Jump to content
  • Advertisement
Sign in to follow this  

OpenGL GluLookAt clone - unexpected behaviour

This topic is 2358 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 replicate the behaviour of GluLookAt, using the information at http://www.opengl.or...l/gluLookAt.xml however my camera doesn't properly track the focus point.

This is the code I've written to calculate a matrix from the camera's attributes:

void MatrixFromLookatCam(camera_follow_t *camera, mat4x4_t matrix)
vec3_t lookDir;
vec3_t s, u;
vec3subtract(lookDir, camera->point, camera->origin);
vec3Normalise(lookDir, lookDir);
vec3Normalise(camera->up, camera->up);
vec3CrossProduct(s, lookDir, camera->up);
vec3Normalise(s, s);
vec3CrossProduct(u, s, lookDir);
vec3Normalise(u, u);

matrix[0] = s[0];
matrix[1] = u[0];
matrix[2] = -lookDir[0];
matrix[4] = s[1];
matrix[5] = u[1];
matrix[6] = -lookDir[1];
matrix[8] = s[2];
matrix[9] = u[2];
matrix[10] = -lookDir[2];
matrix[12] = -camera->origin[0];
matrix[13] = -camera->origin[1];
matrix[14] = -camera->origin[2];

At the rendering stage I'm multiplying the modelview matrix by this new matrix, then reverting it to the identity matrix at the end of the render.

To illustrate the problem:
When the focus point is moved from it's starting position ([0,0,0]) the camera doesn't follow it precisely. The focus point is indicated by the bottom-left corner of the red square.

Share this post

Link to post
Share on other sites
From a glance, I can't spot anything obviously wrong in the code. If you need more reference, you can try e.g. cross-checking against float3x3::LookAt in MathGeoLib.

Share this post

Link to post
Share on other sites
For debugging, I would take a snapshot when you press a key, and draw the up,right,forward vectors and then move backwards and see where they are actually pointing. Of course scale those vectors so they go out far enough to see if it is hitting the red dot or anything else.

Are you calling

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!