Jump to content
  • Advertisement
Sign in to follow this  
Stephen R

[SOLVED] gluLookAt oddities

This topic is 3987 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 trying to implement gluLookAt myself, out of a silly desire not to use GLU. I took the formula in the documentation and implemented it using my own matrix and vector classes and it works... kinda. It behaves in a completely sane way, and I'd be perfectly happy with it if it wasn't clearly a little bit more zoomed out than result of using gluLootAt. I've gone over the source in MESA and I can't find a single difference between my implementation and theirs... I'm on windows and wondering if MS distributes the source for their implementation (if it is even their implementation?) I couldn't find any info in my searches. My source and the MESA source:

void Matrix::MakeLookAt(const Vector3& eye, const Vector3& center, const Vector3& up) {
	Vector3 f = center - eye;

	Vector3 normalUp = up;

	Vector3 s = f.CrossProduct(up);
	Vector3 u = s.CrossProduct(f);

	Matrix M;


	Matrix T;

	*this = M * T;

gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez, GLdouble centerx,
	  GLdouble centery, GLdouble centerz, GLdouble upx, GLdouble upy,
	  GLdouble upz)
    float forward[3], side[3], up[3];
    GLfloat m[4][4];

    forward[0] = centerx - eyex;
    forward[1] = centery - eyey;
    forward[2] = centerz - eyez;

    up[0] = upx;
    up[1] = upy;
    up[2] = upz;


    /* Side = forward x up */
    cross(forward, up, side);

    /* Recompute up as: up = side x forward */
    cross(side, forward, up);

    m[0][0] = side[0];
    m[1][0] = side[1];
    m[2][0] = side[2];

    m[0][1] = up[0];
    m[1][1] = up[1];
    m[2][1] = up[2];

    m[0][2] = -forward[0];
    m[1][2] = -forward[1];
    m[2][2] = -forward[2];

    glTranslated(-eyex, -eyey, -eyez);

Thanks a million. SOLUTION: Apparently the vectors that fill the first two rows of the matrix have to be normalized for it to behave exactly like glu32. [Edited by - Stephen R on January 15, 2008 6:29:26 PM]

Share this post

Link to post
Share on other sites
Original post by Stephen R
I'm trying to implement gluLookAt myself, out of a silly desire not to use GLUT.

gluLookAt is not a part of GLUT, glu stands for gl utility library. You just need to link against glu32.lib to use it.

Share this post

Link to post
Share on other sites
Ok, true. Bad terminology on my part. I'll edit the OP. And I know that's all I have to do, that's how I'm testing it. I'm taking the exact same situation and changing nothing but glMultMatrix(my_matrix) vs. gluLookAt(...) with the same parameters used for both. But my question remains [smile]

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!