# Matrix, I'm lost

This topic is 4490 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

[EDIT]My post renders correctly, single quotes are bad![/EDIT] Hi there, I have some questions about matrices. first I'm making a 3d engine in pure java, no jogl or similar APIs second my XYZ axis are oriented that way third the internal representation of a matrix should look like that Now which matrix is the right one??? I've seen them all. Then my camera matrix should like that(depending on the answer of the previous question). The 1/d would be 1/the distance between the camera and the front clipping plane the matrix of a point or vector should look like that but what sould I set W to? 1? After I multiply [Camera]*[Object Transform]*[Object's vertex] I get a column matrix like the one above, but do I have a 2D point now? are the X and Z values my 2D x and y coordinates (yeah I know the y axis is inverted on the computer screen). Does the Y and W have a meaning or it's just junk? [Edited by - Iarus on April 1, 2006 3:46:58 PM]

##### Share on other sites
Hi there,
I have some questions about matrices.

first I'm making a 3d engine in pure java, no jogl or similar APIs

second my XYZ axis are oriented that way

third the internal representation of a matrix should look like that

Now which matrix is the right one??? I've seen them all.

Then my camera matrix should like that(depending on the answer of the previous question). The 1/d would be 1/the distance between the camera and the front clipping plane

the matrix of a point or vector should look like that
but what sould I set W to? 1?

After I multiply [Camera]*[Object Transform]*[Object's vertex] I get a column matrix like the one above, but do I have a 2D point now? are the X and Z values my 2D x and y coordinates (yeah I know the y axis is inverted on the computer screen). Does the Y and W have a meaning or it's just junk?

FIXED for you!

##### Share on other sites
I assume your Y axis points into the screen.

First you should select one of the matrices:
    [ Xx   Yx   Zx   Tx ]         [ Xx   Xy   Xz   0 ](A) [ Xy   Yy   Zy   Ty ]  or (B) [ Yx   Yy   Yz   0 ]    [ Xz   Yz   Zz   Tz ]         [ Zx   Zy   Zz   0 ]    [  0    0    0    1 ]         [ Tx   Ty   Tz   1 ]

according to whether you will be considering vectors as 3x1 (A) or 1x3 matrices. They transform differently. T stands for "translation"

Your view matrix should be the *inverse* of the respective (A) or (B) matrix from above. The X,Y,Z will be the camera's axes and T will be its position in global coordinates.
Be careful, after inverting it, the translation part {Tx, Ty, Tz} will not -simply- be the negative of the translation in the original matrix. This only holds when you switch from an arbitrary basis to the regular orthonormal one {1,0,0}, {0,1,0}, {0,0,1}.
Each of the Tx, Ty, Tz in the inverse matrix, will be the negative dot product of the camera's position with each camera axis vector.

As for what W you should use to transform your 4d vectors, you should know that such a vector (with homogeneous components) only represents an actual point in space (a coordinate), when its W==1.
This is very important, because after transforming a coordinate vector by a homogeneous matrix, you should divide all its components by its W, in order to make its W equal to 1 again. Only then it will represent the transformed coordinate.
Similarly, a 4d homogenous vector only represents a direction when its W==0. These come from the study of homogeneous coordinates; if you feel like knowing more about why this holds, say so. I don't know if you care about the underlying maths.

Quote:
 After I multiply [Camera]*[Object Transform]*[Object's vertex] I get a column matrix like the one above, but do I have a 2D point now? are the X and Z values my 2D x and y coordinates (yeah I know the y axis is inverted on the computer screen). Does the Y and W have a meaning or it's just junk?

(If you want this order of multiplication you'll have to go for the (A) form of matrices, as mentioned above.)
Now the vertex will be expressed in camera space. You'll have to further apply a projection matrix, in order to turn it into normalized screen space coordinates. Divide by its new W and lose the Y component. Multiply each of the X,Z with one half, then add half and multiply with the viewport's dimensions in pixels.
This is the point you want on your monitor. Clipping is also performed before that final step, you may want to consider that.

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 13
• 38
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631714
• Total Posts
3001861
×