vertex matrix problem
hi GDNet,
if i have vertex of object stored in this matrix:
{50,0,0,0},
{0,50,0,0},
{0,0,50,0},
{0,0,0,1} ; x=50, y=50, z=50
and then translate this with this matrix(translate by x for 20):
{1,0,0,0},
{0,1,0,0},
{0,0,1,0},
{20,0,0,1}
then i get this matrix:
m =
{50,0,0,0},
{0,50,0,0},
{0,0,50,0},
{20,0,0,1}
so to actual use this i must sum up m[0][0] and m[3][0]
is this the right way?
I am a little confused about what you are trying to do. Normally you don''t need to store a vertex in a matrix, just a vector. So, you could say that your vertex has a location of
[ 50, 50, 50, 1 ].
Your first matrix is more like a scaling matrix that would increase an objects dimensions by a factor of 50 on all three axes.
Then to translate the vertex, you would multiply it by your matrix. m = vertex vector, N = your translation matrix
new location = m * N = [ 70 50 50 1 ]
[ 50, 50, 50, 1 ].
Your first matrix is more like a scaling matrix that would increase an objects dimensions by a factor of 50 on all three axes.
Then to translate the vertex, you would multiply it by your matrix. m = vertex vector, N = your translation matrix
new location = m * N = [ 70 50 50 1 ]
A vertex is not a 4x4 matrix, it is a 4x1 matrix (also known as a "vector"). The multiplication of a 4x4 matrix with a vertex is another vertex -- the transformed vertex.
So you should be writing your vertices as {x, y, z, 1} and not in the matrix format you have. So, for your example, it would be { 50, 50, 50, 1 }.
Go to your favorite college/bookstore/library/friend/sample code and look for "linear algebra" which will talk about the process for multiplying matrices and vectors. For your sample matrix (that translates x by 20), the results of multiplying that by the vertex {50, 50, 50, 1} is {70, 50, 50, 1} -- exactly what you would expect.
---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!
So you should be writing your vertices as {x, y, z, 1} and not in the matrix format you have. So, for your example, it would be { 50, 50, 50, 1 }.
Go to your favorite college/bookstore/library/friend/sample code and look for "linear algebra" which will talk about the process for multiplying matrices and vectors. For your sample matrix (that translates x by 20), the results of multiplying that by the vertex {50, 50, 50, 1} is {70, 50, 50, 1} -- exactly what you would expect.
---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!
thank you for reply, so if i have vertex and i want it first to translate it and then rotate i can do something like:
v..vertex
TM..translation matrix
RM..rotation matrix
NM..new matrix
new v = v*tm*rm
if i have 100 vertices and i must do all the same tranformation on them i can do first NM=TM*RM and then for all the vertices i do v(all)*NM
that is cool and it even makes it faster because it doesnt need so much multiplication,
can you correct me if i am wrong
bye
v..vertex
TM..translation matrix
RM..rotation matrix
NM..new matrix
new v = v*tm*rm
if i have 100 vertices and i must do all the same tranformation on them i can do first NM=TM*RM and then for all the vertices i do v(all)*NM
that is cool and it even makes it faster because it doesnt need so much multiplication,
can you correct me if i am wrong
bye
The NM matrix that you create is sometimes ( always ? ) called a transform matrix. What you need to be careful about is that
TM * RM != RM * TM
in most cases. You can even build up nice a transform matrix by using multiple RM''s and TM''s. For example, you could have TM1, RM1, RM2, and use these to get:
NM = RM1 * TM1 * RM2
TM * RM != RM * TM
in most cases. You can even build up nice a transform matrix by using multiple RM''s and TM''s. For example, you could have TM1, RM1, RM2, and use these to get:
NM = RM1 * TM1 * RM2
thank you again for additional information, but lets consider one more situation...
if i get it right with camera if we have some object at z = 200 and we say that camera is at z = 50 then object_world_coordinates - 50, then in some sense we get as that object is 150 units from us.
so...
WC..world coordinates(if i get this right these newer move if they are stable..like walls, houses)
VC..view coordinates...there are world coordinates but transformed by camera matrix
CM..camera matrix
VC=WC*CM (in CM we translate,rotate in negative direction)
(WC consist of x,y,z,xr,yr,zr)
then in some program
loopingaround{
we_press_up->we update CM z coordinate
/*..like z=10
(CM={1,0,0,0}
{0,1,0,0}
{0,0,1,0}
{z,0,0,1}) */
VC=WC*CM;
}
ok is this correct, sorry for bother i know there is all in books but why not use this forum as great learning tool of the future
bye!
if i get it right with camera if we have some object at z = 200 and we say that camera is at z = 50 then object_world_coordinates - 50, then in some sense we get as that object is 150 units from us.
so...
WC..world coordinates(if i get this right these newer move if they are stable..like walls, houses)
VC..view coordinates...there are world coordinates but transformed by camera matrix
CM..camera matrix
VC=WC*CM (in CM we translate,rotate in negative direction)
(WC consist of x,y,z,xr,yr,zr)
then in some program
loopingaround{
we_press_up->we update CM z coordinate
/*..like z=10
(CM={1,0,0,0}
{0,1,0,0}
{0,0,1,0}
{z,0,0,1}) */
VC=WC*CM;
}
ok is this correct, sorry for bother i know there is all in books but why not use this forum as great learning tool of the future
bye!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement