Question

I have defined a matrix that contains the position and orientation of the camera similar to the GL_MODELVIEW matrix:

GL_MODELVIEW matrix

(m3 = 0; m7 = 0; m11 = 0; m15 = 1)

I'm trying to load this data into the ModelViewMatrix. I'm thinking in this two possibilites:

  • Using the function glLoadTransposeMatrixf():

If I use this solution I'm obtaining the correct position and orientation. The problem is that I need to use the second solution because I'm modifying the Left/Up/Forward/Translation vectors on my code to modify the view.

  • Using the function gluLookAt():

      gluLookAt(Translation->X,
                Translation->Y,
                Translation->Z,
                Translation->X-Forward->X,
                Translation->Y-Forward->Y,
                Translation->Z-Forward->Z,
                Up->X,
                Up->Y,
                Up->Z);
    

My problem is that the GL_MODELVIEW matrix that I'm obtaining with that is different from the other case. Specifically, the Translation vector is wrong, but the Left/Up/Forward vectors are correct.

I'm really confused with that. Can someone explain if there are differences between this two options and what I'm doing wrong, please?

Obtained results:

I'm using a matrix M like this:

M = (Lx   Upx   Fwx   tx)
    (Ly   Upy   Fwy   ty)
    (LZ   Upz   Fwz   tz)
    (0     0     0    1 )
 

With the first method i'm obtaining the correct GL_MODELVIEW matrix:

N = (Lx   Upx   Fwx   tx)
    (Ly   Upy   Fwy   ty)
    (Lz   Upz   Fwz   tz)
    (0     0     0    1 )

but with the second method i'm obtaining the next GL_MODELVIEW matrix:

N = (Lx   Upx   Fwx   tx')
    (Ly   Upy   Fwy   ty')
    (Lz   Upz   Fwz   tz')
    (0     0     0    1 )

Note that tx'!=tx, ty'!=ty, tz'!=tz. This is very confusing...

Was it helpful?

Solution

There are differences between the two options. Let's call your matrix M. What does M actually do? It does not transform from world space to eye space, but exactly the inverse. Think about it. You assume your camera is at point "translation". Let's assume the rest of M is identity, so a point exactly at the camera location should be translated to the origin. But it will end up at translation.xyz+translation.xyz, so actually, your camera is at the point -translation.xyz.

If your first method actually gives the "correct" results, you seem to have something else wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top