• Create Account

Banner advertising on our site currently available from just \$5!

# 3D Perspective Projection (w)

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

1 reply to this topic

### #1adam17  Members   -  Reputation: 227

Like
0Likes
Like

Posted 07 October 2012 - 10:01 PM

I'm working on an assignment for my graphics class and I've encountered a problem. Basically I have a set of coordinates in World space and I have to transform them into Screen space and display them. I have to manually build all of the matrices and do the transformations by myself (no opengl or d3d). I have the following 3 matrices
• Xsp (proj to screen transform)
• Xpi (image to projection transform)
• Xiw (world to image transform)
I'm rendering to a 256x256 frame buffer, so my Xsp matrix looks like this:
128	 0	 0	 128
0	 -128	 0	 128
0	 0	 1	 0
0	 0	 0	 1


My Xpi matrix has m[3][2] set to tan(fov / 2) where my fov = 35. (In the matrix .32 was just rounded for easier viewing)
1	 0	 0	 0
0	 1	 0	 0
0	 0	 1	 0
0	 0	 .32	 0


Lastly my Xiw matrix is just the inverse of my camera transform. The camera is at 0,0,-15, looking at 0,0,0 with an up-vector of 0,1,0
1	 0	 0	 0
0	 1	 0	 0
0	 0	 1	 15
0	 0	 0	 1


Using just these three matrices I can multiply them against a coordinate and get it transformed into screen space just fine. The catch is when I want them to be perspective correct. I've tried figuring out what 'w' is, but I cannot find a solid definition of how to calculate it. Some places are saying that the final Z value is used to divide X and Y by, but it doesn't look right. Some places are saying the W coord that is calculated by multiplying the matrix with the coordinate (assuming 1.0 for the 4th coord) is the W to divide by. I can't seem to get either method to work.

My question is what is W and how is it calculated?

Thank you so much in advance!

### #2Tournicoti  Prime Members   -  Reputation: 697

Like
0Likes
Like

Posted 07 October 2012 - 11:26 PM

Hello

With homogeneous coordinates, there are four components to represent a 3d vertex or a 3d vector :

• if w != 0 , ( x , y , z , w ) represents the vertex ( x/w , y/w , z/w )
• if w = 0 , it represents all the vectors colinear to the vector ( x , y , z ).   [ i.e. : a * ( x , y , z ) , a in lR*  ]

So for a vertex ( x , y , z ) transformed into ( x' , y' , z' ) with Transform :

• ( X , Y , Z , W ) = ( x , y , z , 1 ) * Transform
• ( x' , y' , z' ) = ( X , Y , Z ) / W

NB :
For the vertices, the w component is usually initially set to 1 so that the w division is not needed in rotations, translations, scalings, and any combination of them.
With this assumption, the w division is necessary only when Transform is (or 'contains') a projection matrix.

Nico

Edited by Tournicoti, 11 March 2013 - 03:45 AM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS