Possible Bug in gluLookAt

I was trying to use gluLookAt and the view was incorrectly oriented, especially the Up direction. However, the Up direction vector was correct defined. File version of the GLU32.DLL is 5.1.2600.5512 (xpsp.080413-0845).

I replaced the gluLookAt with my own version that was created based on the documentation http://www.opengl.org/documentation/specs/man_pages/hardcopy/GL/html/glu/lookat.html and the view started to operate correctly.

typedef union {
	double data[3];               
	struct { double x, y, z; };  

void mygluLookAt(VECTOR3 _Eye, VECTOR3 _Center, VECTOR3 _Up)
	VECTOR3 _c   = unit(_Center - _Eye);
	VECTOR3 _s   = unit(crossp(_c, _Up));
	VECTOR3 _u   = unit(crossp(_s, _c));

	double M[16];

	M[0]  = _s.x;
	M[4]  = _s.y;
	M[8]  = _s.z;
	M[12] = 0.0;
	M[1]  = _u.x;
	M[5]  = _u.y;
	M[9]  = _u.z;
	M[13] = 0.0;

	M[2]  = -(_c.x);
	M[6]  = -(_c.y);
	M[10] = -(_c.z);
	M[14] = 0.0;

	M[3] = 0.0;
	M[7] = 0.0;
	M[11]= 0.0;
	M[15]= 1.0;

	glTranslated(-_Eye.x, -_Eye.y, -_Eye.z);

The problem with gluLookAt, what ever it is, doesn’t appear very easily. In a certains locations of the eye, (mostly in a near top-down conditions within 10deg), the view will start turning away from the defined Up direction. This kind of failure could easily happen when the up vector is almost equal with the “sight” vector. I checked the angle between “sight” and up vectors and it was always 90deg.

I suppose someone should double check the original code of the GLU32.DLL

I doubt that people at MS will look into it. Who is using GLU anyway besides demo writers and beginners?

Well, it’d still be nice to have working code, especially if you’re a beginner. :slight_smile: