eye vector

I need to extract the eye vector from opengl but im not sure how to get it. Which matrix is it in and which part of the matrix. I need to get the vector so i can compute the half vector for the specular part of my lighting in my vertex program.

-SirKnight

Brave SirKnight,

The eye vector is the vector that goes from the vertex to the eye. This is the difference of the eye position and the vertex position.

eye_vector = eye_position - vertex_position

For eye space, this calculation is simple, because the eye_position is defined to be (0,0,0). The eye vector is then simply the negative eye space vertex position.

Of course, you will probably need to normalize that vector before using it (depending on how you intend to use it).

Hope this helps -
Cass

1 Like

You can also get it in object space out of the modelview matrix. Since the default view location is (0,0,1) then in object space the camera is at the transposed modelview matrix (usually) times this vector, which is:

(m[2], m[6], m[10])

– Zeno

Actually, the default view location is (0,0,0).

Ok i see. So what if you use gluLookAt to move the “camera” like for a fps game. Then how would i get the eye_position?

Also Zeno you said that the ‘camera’ is in the transposed modelview at (m[2],m[6],m[10]) so in the nontransposed modelveiw would that be the same thing as (m[8],m[9],m[10]) ?

-SirKnight

[This message has been edited by SirKnight (edited 06-11-2001).]

Sorry, Cass is right of course. The default camera position is 0,0,0. What I should have said is that the default direction that the camera looks is (0,0,-1), so maybe I didn’t even give you the information you wanted. It’s monday morning after all

Sirknight -

Oops, the way I said that was a bit misleading. If m is the normal, non-transposed modelview matrix, then m[2], m[6], m[10] is what you want. When I chose those elements, I had taken the transpose in my head already.

Sorry about the confusion.

– Zeno

Ok i was trying this out and i came up with some wierd results. I tried this by modifying the nVidia LitQuad example. Now what i did was load the modelview matrix in a float array called m. And in the part that loads the view vector into constant register 8 is where i put the m[2],m[6],m[10]. Now i also changed the light direction to 0,0,-1 instead of what they had which made the light point at the quad at an agngle to the left. The function that put that into reg 8 looked like this:
glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 8, m[2], m[6], m[10], 1.0f );

Ok when i put those values from the modelview matrix i extracted when the quad was about pointing about 45 degrees from the right and left side of the origin (which was the center of the quad) it would act wierd. What happened was when the quad was facing to the right at about 45 degrees, the light would just ‘pop’ on. It wouldnt gradually come on like its supposed to. Then the light would be ok untill the quad was facing to the left at about 45 degrees, then it would just ‘pop’ off. Again instead of gradually going dim to black.

BUT, when i did this:
glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 8, 0.0f, 0.0f, m[10], 1.0f );

It worked like its supposed to. The light didnt pop on and off and it graudually came on and off. Now when i did this:
glProgramParameter4fNV( GL_VERTEX_PROGRAM_NV, 8, m[8], m[9], m[10], 1.0f );

It worked fine. So what i want to know is, why did this happen when i used m[2],m[6],m[10]. And why did it work fine when i put in m[8],m[9],m10]. What is in m[2],m[6] AND m[8],m[9]?

-SirKnight

Any one know? I would really like to understand all of this stuff better.

-SirKnight

Never tried extrating the viewing matrices from OGL…intressting koncept thou id like to know if its possible.

Personaly i use a software camera and just supply gluLookAt with the values from it instead of like you trying to use OGL to do those calculations for you.

Let us know if it works out

//Andreas

[This message has been edited by Andreas (edited 06-13-2001).]

You know i was thinking abut doing the same thing. Im working on a camera system (FPS style) and of course ill be using gluLookAt and i was thinking, well ill just use those values from my camera system instead of extracting the matrix data like i did in the example above. This i think will be a better idea since calling glGetFloatf( GL_MODELVIEW_MATRIX, m ); (I think thats right ) on every frame is slow and will lower the framerate. Plus i was not getting the results i wanted or i thought i should get.

One thing i would like to find is what the modelview matrix ‘looks’ like. I cant seem to find any info about that anywhere.

-SirKnight

Check the OpenGL Red Book.

Matrices are stored in column major order in OpenGL. That is:

0 4 8 12
1 5 9 13
2 6 10 14
3 7 11 15

Thanks -
Cass

Hmm i didnt know the red book talked about that. Well thats good. Also cass, i noticed in your profile that under location it said Austin, Tx. Is there a division of nVidia in Austin? I goto college in Austin, Tx and that would be cool if there was an nvidia division there.

-SirKnight