# gluLookAt - Wrong Matrix

This topic is 3745 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

anyone know why you would get the wrong matrix for gluLookAt ? I really can't figure this one out. If you look at the jpg pasted below, the position is 0.0, 0.0, -10.0 instead of (-10.0, 0.0, 0.0) like it is suppose to be. Thanks http://stringa.runeagin.com/wrong.jpg

##### Share on other sites
Post the definition of your camera_transform structure.

##### Share on other sites
camera_transform is just a float[16] .

I am using NVIDIA's math library and it's just a mat4.

[source:lang=c++]struct DECLSPEC_NV_MATH mat4{    mat4();    mat4(const nv_scalar * array);    mat4(const mat4 & M);    mat4( const nv_scalar& f0,  const nv_scalar& f1,  const nv_scalar& f2,  const nv_scalar& f3,  		  const nv_scalar& f4,  const nv_scalar& f5,  const nv_scalar& f6,  const nv_scalar& f7,  		  const nv_scalar& f8,  const nv_scalar& f9,  const nv_scalar& f10, const nv_scalar& f11,  		  const nv_scalar& f12, const nv_scalar& f13, const nv_scalar& f14, const nv_scalar& f15 )  		  : a00( f0 ), a10( f1 ), a20( f2 ), a30( f3 ),  		    a01( f4 ), a11( f5 ), a21( f6 ), a31( f7 ),  		    a02( f8 ), a12( f9 ), a22( f10), a32( f11),			a03( f12), a13( f13), a23( f14), a33( f15) { }     const vec4 col(const int i) const    {        return vec4(&mat_array[i * 4]);    }        const vec4 operator[](const int& i) const    {        return vec4(mat_array, mat_array[i + 4], mat_array[i + 8], mat_array[i + 12]);    }       const nv_scalar& operator()(const int& i, const int& j) const    {        return mat_array[ j * 4 + i ];    }    nv_scalar& operator()(const int& i, const int& j)    {        return  mat_array[ j * 4 + i ];    }    void set_col(int i, const vec4 & v)    {        mat_array[i * 4] = v.x;        mat_array[i * 4 + 1] = v.y;        mat_array[i * 4 + 2] = v.z;        mat_array[i * 4 + 3] = v.w;    }    void set_row(int i, const vec4 & v)    {        mat_array = v.x;        mat_array[i + 4] = v.y;        mat_array[i + 8] = v.z;        mat_array[i + 12] = v.w;    }    mat3 & get_rot(mat3 & M) const;    quat & get_rot(quat & q) const;    void set_rot(const quat & q);    void set_rot(const mat3 & M);    void set_rot(const nv_scalar & theta, const vec3 & v);    void set_rot(const vec3 & u, const vec3 & v);	void set_scale(const vec3& s);	vec3& get_scale(vec3& s) const;    void set_translation(const vec3 & t);    vec3 & get_translation(vec3 & t) const;	mat4 operator*(const mat4&) const;    union {        struct {            nv_scalar a00, a10, a20, a30;   // standard names for components            nv_scalar a01, a11, a21, a31;   // standard names for components            nv_scalar a02, a12, a22, a32;   // standard names for components            nv_scalar a03, a13, a23, a33;   // standard names for components        };        struct {            nv_scalar _11, _12, _13, _14;   // standard names for components            nv_scalar _21, _22, _23, _24;   // standard names for components            nv_scalar _31, _32, _33, _34;   // standard names for components            nv_scalar _41, _42, _43, _44;   // standard names for components        };        union {            struct {                nv_scalar b00, b10, b20, p; // standard names for components                nv_scalar b01, b11, b21, q; // standard names for components                nv_scalar b02, b12, b22, r; // standard names for components                nv_scalar x, y, z, w;       // standard names for components            };        };        nv_scalar mat_array[16];     // array access    };};

##### Share on other sites
With the look eye position, target position, and up vector you define a co-ordinate frame that is rotate by -90° around y, so that a rotation matrix R
[ 0  0 -1  0 ][ 0  1  0  0 ][ 1  0  0  0 ][ 0  0  0  1 ]
is the result. You furthur define the eye point as origin, so a translation T
[ 1  0  0 -10 ][ 0  1  0  0  ][ 0  0  1  0  ][ 0  0  0  1  ]
comes to life. The product of both is multiplied with the identity matrix
I * R * T
so that the matrix
[ 0  0 -1  0  ][ 0  1  0  0  ][ 1  0  0 -10 ][ 0  0  0  1  ]
is the end result.

So the result seems me absolutely correct.

##### Share on other sites
It's not the wrong matrix. Thought of in post-multiplicative terms, it consists of a ninety degree rotation about the Y axis, followed by a ten unit translation along the negative Z axis. Thought of in pre-multiplicative terms, it consists of a ten unit translation along the negative X axis, followed by a ninety degree rotation about the Y axis, which is probably how you're thinking about it. Remember, view transformations like this invert the normal order of transformation. Think in terms of transforming the world, instead of the camera, and you'll see what I mean.

1. 1
Rutin
64
2. 2
3. 3
4. 4
5. 5

• 16
• 10
• 29
• 20
• 9
• ### Forum Statistics

• Total Topics
633414
• Total Posts
3011764
• ### Who's Online (See full list)

There are no registered users currently online

×