Matrix
I have a matrix from OpenGL (4x4 table of floats) and a point coordinates (x, y, z). I want to pass the point through the matrix - calculate for it world coordinates after transformations. What and how should I do it?
Say the OpenGL Matrix is M , the vertex before transformation is A and the vertex after transformation is B . The transformation is :
B = M x A
it is the result of a product between a Matrix (4x4) and a vector (4x1) :
Be careful of OpenGL matrix. Its rows and columns are transposed to the "standard" matrix representation, eg in OpenGL the 4 firsts elements represents the 1st column, not the 1st row.
The 4th vector coordinate (W) is the homogeneous coordinate.
I'll write later how to use it.
In this source example, A is world_vertex, B is local_vertex and M is matrix.
Usage of W coordinate
Any vertex V=[X Y Z W] is equivalent to a 3D vertex [X/W Y/W Z/W].
If the W coordinate is null, the vertex is infinite.
Because your original local vertex is in 3D, its the W coordinate is 1 :
local_vertex = {x y z 1};
When you compute the world coordinates, just divide each component by W to get its 3D coordinate.
Edited by - vincoof on January 24, 2002 1:24:53 PM
B = M x A
it is the result of a product between a Matrix (4x4) and a vector (4x1) :
|
Be careful of OpenGL matrix. Its rows and columns are transposed to the "standard" matrix representation, eg in OpenGL the 4 firsts elements represents the 1st column, not the 1st row.
The 4th vector coordinate (W) is the homogeneous coordinate.
I'll write later how to use it.
|
In this source example, A is world_vertex, B is local_vertex and M is matrix.
Usage of W coordinate
Any vertex V=[X Y Z W] is equivalent to a 3D vertex [X/W Y/W Z/W].
If the W coordinate is null, the vertex is infinite.
Because your original local vertex is in 3D, its the W coordinate is 1 :
local_vertex = {x y z 1};
When you compute the world coordinates, just divide each component by W to get its 3D coordinate.
Edited by - vincoof on January 24, 2002 1:24:53 PM
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement