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

[SOLVED] gluLookAt oddities

This topic is 3901 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:
//Mine

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

	Vector3 normalUp = up;
	normalUp.Normalize();

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

	Matrix M;
	M.MakeIdentity();

	M.Set(0,0,s[0]);
	M.Set(0,1,s[1]);
	M.Set(0,2,s[2]);
	M.Set(1,0,u[0]);
	M.Set(1,1,u[1]);
	M.Set(1,2,u[2]);
	M.Set(2,0,-f[0]);
	M.Set(2,1,-f[1]);
	M.Set(2,2,-f[2]);

	Matrix T;
	T.MakeTranslate(-eye.X(),-eye.Y(),-eye.Z());

	*this = M * T;
}

// MESA
void GLAPIENTRY
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;

    normalize(forward);

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

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

    __gluMakeIdentityf(&m[0][0]);
    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];

    glMultMatrixf(&m[0][0]);
    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
Advertisement
Quote:
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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!