I read a bunch of articles/tutorials about them but didnt understand it fully. So...

1) I put in a position and a projection matrix

2) Complex math

3) I get position as scaled right and x and y divided by its z???

What i dont get is where the x and y are divided by z. Is it even done in the projection matrix?

Explain please O_e

**0**

# Can someone explain projection matrices?

Started by Waterlimon, Sep 10 2011 06:44 AM

8 replies to this topic

Sponsor:

###
#2
Crossbones+ - Reputation: **9729**

Posted 10 September 2011 - 07:11 AM

Every time I see people answering questions like this I see them throwing out a bunch of mathematical proofs that would only explain the concept to someone who had enough mathematical skill to never misunderstand the problem in the first place.

So I will explain in the most simplistic and imagery-based way possible.

When you look at your city, buildings farther away look smaller. As it turns out, any building the same size as another, but twice as far away, will be half the size.

Since Z is the distance away from you, the size of the building is a function of Z.

That is, if the Z value is doubled, the building is twice as far away from you. So to make it twice as small you need to divide by Z.

A projection matrix is designed specifically to facilitate this type of translation.

L. Spiro

So I will explain in the most simplistic and imagery-based way possible.

When you look at your city, buildings farther away look smaller. As it turns out, any building the same size as another, but twice as far away, will be half the size.

Since Z is the distance away from you, the size of the building is a function of Z.

That is, if the Z value is doubled, the building is twice as far away from you. So to make it twice as small you need to divide by Z.

A projection matrix is designed specifically to facilitate this type of translation.

L. Spiro

It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011

I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013

I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”

L. Spiro Engine: http://lspiroengine.com

L. Spiro Engine Forums: http://lspiroengine.com/forums

I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013

I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”

L. Spiro Engine: http://lspiroengine.com

L. Spiro Engine Forums: http://lspiroengine.com/forums

###
#3
Members - Reputation: **768**

Posted 10 September 2011 - 07:17 AM

Ever noticed that they are using 4x4 matrices, even though you'd actually just need vectors from R3. They are using 4x4 matrices because they are using homogeneous coordinates. Homogeneous coordinates are basically vectors from R(x+1) where the last component is a scalar factor of the actual Rx vector.

Example:

v1 element of R3

v2 element of R4

v1 = v2 / v2.w

v2 = c * v1

So they simply use the w-component to be able to use the division x/z and y/z.

The division of x/z and y/z can be figured out by using the intercept theorem.

Example:

v1 element of R3

v2 element of R4

v1 = v2 / v2.w

v2 = c * v1

So they simply use the w-component to be able to use the division x/z and y/z.

The division of x/z and y/z can be figured out by using the intercept theorem.

###
#4
Crossbones+ - Reputation: **2108**

Posted 10 September 2011 - 07:21 AM

No what i want to know is what causes the x and y to be divided by z in the projection matrix? I already know the result, but where in the computaton is the division done?

The lack of awesome free resource gathering building sandbox games capable of running an user made 8 bit computer in the world disturbs me.

###
#5
Moderators - Reputation: **7406**

Posted 10 September 2011 - 07:21 AM

The division by Z is performed after the projection matrix. The step is usually called perspective division, where you normalize your 3-dimensional homogeneous vector to a 3-dimensional vector by dividing the vector by the homogeneous component (the fourth W-component) of the vector. Basically, the depth is mapped onto the W-component with the projection matrix, and the division by Z is performed in the perspective division stage.

###
#6
Members - Reputation: **1254**

Posted 10 September 2011 - 07:25 AM

Honestly, it sounds like you just need to sit down and learn Linear Algebra.

Matrix multiplication is just a mathematical mechanism like normal addition or multiplication or division. You just have to learn how to perform it.

Linear Algebra tutorial. I don't know if this tutorial is any good but it was the first hit on google:

http://blog.wolfire....elopers-part-1/

Matrix Multiplication

http://en.wikipedia...._multiplication

Projection Matrix construction

http://www.songho.ca...tionmatrix.html

-me

Matrix multiplication is just a mathematical mechanism like normal addition or multiplication or division. You just have to learn how to perform it.

Linear Algebra tutorial. I don't know if this tutorial is any good but it was the first hit on google:

http://blog.wolfire....elopers-part-1/

Matrix Multiplication

http://en.wikipedia...._multiplication

Projection Matrix construction

http://www.songho.ca...tionmatrix.html

-me

###
#7
Crossbones+ - Reputation: **2108**

Posted 10 September 2011 - 07:41 AM

I can follow the math somehow, but i just cant see where the w becomes z...

So what were doing is multiplying a 4 component vector by a 4x4 matrix and then dividing the x y and z of the vector by w?

How does the z of the vector get to the w of it? When multiplying the matrix and vector its all like w and parts of the matrix.

Is the z put to w manually, or is the z somehow moved into the matrix in some point or what?

So what were doing is multiplying a 4 component vector by a 4x4 matrix and then dividing the x y and z of the vector by w?

How does the z of the vector get to the w of it? When multiplying the matrix and vector its all like w and parts of the matrix.

Is the z put to w manually, or is the z somehow moved into the matrix in some point or what?

The lack of awesome free resource gathering building sandbox games capable of running an user made 8 bit computer in the world disturbs me.

###
#8
Moderators - Reputation: **7406**

Posted 10 September 2011 - 07:57 AM

I will give you an example with OpenGL's matrices. Check out the matrix generated by glFrusutm for example: clicky. Look at the bottom row, which is the relevant part of the matrix since it exclusively decides the content of the W-component.

[0, 0, -1, 0] * [x, y, z, w]

So, just by multiplying a column vector by that matrix, you can see that the W-component of the resulting vector is the negative Z-component of the input vector. It's standard matrix multiplication.

[0, 0, -1, 0] * [x, y, z, w]

^{T}= 0*x + 0*y - 1*z + 0*w = -zSo, just by multiplying a column vector by that matrix, you can see that the W-component of the resulting vector is the negative Z-component of the input vector. It's standard matrix multiplication.

###
#9
Crossbones+ - Reputation: **2108**

Posted 10 September 2011 - 08:08 AM

Now i get it, thanks... I think i was confused by the other operand being just a vector... i was doing it w=0*w + 0*w blah blah or something similiar.

The lack of awesome free resource gathering building sandbox games capable of running an user made 8 bit computer in the world disturbs me.