# OpenGL Modelview Matrix Intuition

Would, you mind answering a question? :D…

Question( It has been eating away at my brain for DAAYYYS!)

``````equation 1: [http://knol.google.com/k/-/-/2lijysgth48w1/zafhtk/formule15.png](http://knol.google.com/k/-/-/2lijysgth48w1/zafhtk/formule15.png)

equation 2: [http://knol.google.com/k/-/-/2lijysgth48w1/zafhtk/formule16.png](http://knol.google.com/k/-/-/2lijysgth48w1/zafhtk/formule16.png)

I get how both equations relate to each other somewhat...
I just don't understand where the zeros come from iin the end of the model-view matrix

This guy attempts to derive the model view matrix...and i somewhat get it, but LOOK, UP, and RIGHT vectors have three components...([http://knol.google.com/k/matrices-for-3d-applications-view-transformation#](http://knol.google.com/k/matrices-for-3d-applications-view-transformation#))
However they all have a fourth one that is a zero...That gets me confused...

Is it added because point/vector Eye has four components(x,y,z,w)...and and the other ones only have three?

Do all the other vectors just get an extra zero to fit with the vector/point Eye?
Is that allowed?

Or is it just the identity matrix filled in with the specified data?
Is that allowed?

What is really going on in there? I am so confused...
8-|

[b]SO, the overall question is how exactly, how did the first equation go into matrix form? Could it please be given in a step by step process...LOOK, UP, and RIGHT vectors all have three components but EYE vector has four(x,y,z,w)...Oh and what are the three zeros for at the end? [/b]``````

Yes. That operation is a 3D rotation followed by a 3D translation. If you only needed to encode the 3D rotation in a matrix, then you’d only need a 3x3 matrix and 3D positions (x,y,z). But to encode a 3D translation, you need a 4th component to play with. Therefore, we use (x,y,z,1) for the point, and then put some translates in the last row of that matrix to multiply by that 1. That lets us add that translation in.

Using matrix multiplication to write out the individual components of the result vector, and you’ll see what I mean.

That last column (0,0,0,1) is just there so that the result of doing the matrix mult with that last column results in a 4th position component of “1”, just like the position’s 4th component. That’s it. 4D pos * 4x4 matrix = 4D pos.

So [x] = x*[rightx] + y*[upx] + z[lookx] + [Eye.x]
[y] x*[righty] y*[upy] z[looky] [Eye.y]
[z] x*[rightz] y*[upz] z[lookz] [Eye.z]
[w] [Eye.w]
Is that written correctly?
You might not be able to see it, but i am basically taking the right coordinate and multiplying it by the correct vector.(The site took way my spaces )

LOOK, RIGHT, and UP vectors are only for translation, they create the coordinate grid that the coordinate will be multiplied by. I get that much. I don’t quite understand homogeneous coordinates, but i no that they are there in the Eye coordinate and the main coordinate…all coordinates.

However, i don’t get how to do the mathematics to get the new matrix…
Could you plz show me how to get the equation into matrix?

I now no the intuition, but how does some one, such as myself go about actually creating that matrix from the first equation, if that were the only thing that we knew, and we did not no how the final matrix would look. How would someone go about to get the same outcome in matrix form, transposed or not?

Yep, you got it.

LOOK, RIGHT, and UP vectors are only for translation,

No, for “rotation”. These rotate the coordinate frame. Eye.xyz “translates” that rotated frame into position in WORLD space.

I don’t quite understand homogeneous coordinates,

Think of them as a “trick”, not something deep. If I add a row to the matrix and dictate that it will always be multiplied by a 1 and then added in, I’m essentially adding that row in unadulterated.

Could you plz show me how to get the equation into matrix?
I now no the intuition, but how does some one, such as myself go about actually creating that matrix from the first equation, if that were the only thing that we knew

They’re the same equation. Matrices are just a shorthand for writing a set of linear equations without the variable names. You just did exactly what you asked about right here:

``````
[x] = x*[rightx] + y*[upx] + z[lookx] + [Eye.x]
[y] x*[righty] y*[upy] z[looky] [Eye.y]
[z] x*[rightz] y*[upz] z[lookz] [Eye.z]
[w] [Eye.w]

``````

You took the vector form, and expanded it to component form (one equation per component in the target vector). Now mentally mask out the variables (x*, y*, z*) and (presto!) you’ve got the values in your matrix!

Yes, thanks…I get it!
Oh, and i ment rotation instead of translation :whistle:

I decided to think of it as a system of equations

``````[x] = x*[rightx] + y*[upx] + z[lookx] + [Eye.x]
[y] = x*[righty] + y*[upy] + z[looky] + [Eye.y]
[z] = x*[rightz] + y*[upz] + z[lookz] + [Eye.z]
[w] = 0          + 0       + 0        + Eye.w(1)
``````

So, what is happening to every coordinate, is that they are being multiplied by their part of every vector and then shifted over by their specific part of Eye.

then i can turn that system of equations into a matrix like:

``````[x] = [x] * [Right][ Up ][Look][Eye.x]
[y]   [y]   [Right][ Up ][Look][Eye.y]
[z]   [z]   [Right][ Up ][Look][Eye.z]
[w]   [w]   [  0  ][ 0  ][ 0  ][Eye.w]
``````

by pulling out all the variable in one equation in a vector and lining up the rest in a matrix form…

So the isolated matrix is the Modelview Matrix!
and the last row must always stay [0001], right

Thus the Modelview Matrix has three vectors and a location in space. This could all be represented or inscribed into a matrix. The components of the coordinate vector are then multiplied and altered by the Modelview Matrix. Coordinate vectors are always altered by the Modelview matrix: it could be the identity or a custom made one. Each component of the coordinate vector has its own equation, which will take into account the position and orientation of the coordinate in ‘world space’.

Is this all correct? And is there anything I am missing?

Yes, you got it!

Neat, I did all the necessary tests and it worked out just fine!

My last question, so OpenGL does this calculation in what part of the GPU? And does OpenGL treats the coordinates as matrices, or is that just a way for us to explain what is really going on in OpenGL?

My last question, so OpenGL does this calculation in what part of the GPU?

Well, while we don’t know for absolute sure without dissassembling the driver or getting info from the folks that wrote it what is “really” going on under-the-covers with a particular GPU…

Conventional wisdom nowadays says that modifications to built-in matrices (glRotate, glTranslate, etc.) are all done on the CPU, and the resultant matrix uploaded to the GPU as a shader uniform input as required. And transformation vertex positions (or whatever) by the built-in matrix happens on the GPU in a shader.

And does OpenGL treats the coordinates as matrices, or is that just a way for us to explain what is really going on in OpenGL?

We don’t know what a vendor has chosen to do under-the-covers. But the abstraction presented by OpenGL is that coordinates are vectors.

Thanks a bunch

No problem!