3D Matrices

Started by
5 comments, last by HyprLogik 23 years, 10 months ago
Hi, I''m trying to figure out this matrix transformation stuff. Say I have a rotation matrix, then multiply it by a translation matrix. Do I multiply the resulting matrix to my point? Say I had the translation matrix: / 1 0 0 0 / / 0 1 0 0 / / 0 0 1 0 / / 8 2 5 1 / and the point [9 5 0 1] (x=9, y=5, z=0). Do I simply multiply the two? I tried this (by taking the dot product of each row with the point, resulting with another 4x4 matrix) and came out with some funky-ass matrix. Could someone please tell me how to do this stuff? Thanks. |-|A[k3R$Z R \/\/|-|AT |V|Ak3 t|-|3 \/\/0R|_D g0 R0|_||\|D!!
|-|A[k3R$Z R //|-|AT |V|Ak3 t|-|3 //0R|_D g0 R0|_|||D!!
Advertisement
The above matrix will translate a point by (8, 2, 5).

Multiply your point by the matrix to get your translated point. You'll probably retain the contents of the original point (this is the model description in object space) and create a new point that is the translated point.
            If your matrix is row major order then M[4][4] = M<i>[j] means i indexes your row, and j indexes your column.This would mean:M[0][0] = 1; M[0][1] = 0;M[0][2] = 0;M[0][3] = 8; Notice: we just indexed your first column.To transform your point, which in this case is translating it we do this:PNew[0] = Dot4(P, M[0]); PNew[1] = Dot4{P, M[1]);PNew[2] = Dot4(P, M[2]);PNew[3] = Dot4{P, M[3]);Dot4 would be a 4 dimensional dot product.For example: PNew[3] = P[0] * M[3][0] * P[1] * M[3][1] + P[2] * M[3][2] + P[3] * M[3][3];        


If you multiply your above matrix with another matrix (say a matrix which rotates the point around an axis) then you get a new matrix which represents rotation then translation. Reverse the order of the multiplication and you reverse the order to translation then rotation. There is a difference!

Articulated structures and complex systems are easily described by a stack of matrices.

Imagine the solar system:
The Sun rotates around the center of the galaxy.
The Earth rotates around the Sun.
The Moon rotates around the Earth.
A Spacecraft rotates around the Moon.
Comples, yes, but easy with matries.

Create the identity matrix I.

Create a matrix which translates the Sun from its object space to where it resides relative to the center of the galaxy.
Call this TS.
Multiply TS with I and store the result on top of I in a stack.
Create a matrix which rotates the Sun relative to its oriention in object space.
Call this matrix RS.
Multiply RS with TS and overwrite TS.
Draw the Sun with this matrix.

Create a matrix which translates the Earth from its object space to where it resides relative to the center of the Sun.
Call this TE.
Multiply TE with the top of the stack and store the result in a new location on the top of the stack.
Create a matrix which rotates the Earth relative to its oriention in object space.
Call this matrix RE.
Multiply RE with the top of the stack and overwrite the top of the stack.
Draw the Earth with this matrix.

Create a matrix which translates the Moon from its object space to where it resides relative to the center of the Earth.
Call this TM.
Multiply TM with the top of the stack and store the result in a new location on the top of the stack.
Create a matrix which rotates the Moon relative to its oriention in object space.
Call this matrix RM.
Multiply RM with the top of the stack and overwrite the top of the stack.
Draw the Moon with this matrix.

Create a matrix which translates the spacecraft from its object space to where it resides relative to the center of the Moon.
Call this TSp.
Multiply TSp with the top of the stack and store the result in a new location on the top of the stack.
Create a matrix which rotates the spacecraft relative to its oriention in object space.
Call this matrix RSp.
Multiply RSp with the top of the stack and overwrite the top of the stack.
Draw the spacecraft with this matrix.

I have made some minor errors or typos above but that is the spirit of transofrmations. If I have made an error, please let me know so I may correct it.



Edited by - bishop_pass on June 22, 2000 1:51:12 PM

Edited by - bishop_pass on June 22, 2000 1:52:28 PM

Edited by - bishop_pass on June 22, 2000 2:39:17 PM
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.
You should try to read witchlord''s tutorial on www.witchlord.com.

------------------------
Captured Reality
Damn! First we''re talking about matrix math, now we''re talking about landing someone on the moon?

Just kidding...
Thanks for your responses. What happens if I simply add 8 to 9, 2 to 5, and 5 to 0? Wouldn''t this work? This transforms the vertex to 17, 7, 5, right? This way, I wouldn''t have to worry about dot products and stuff (although I DO understand them)

Any remarks on this suggestion?

Thanks again.

|-|A[k3R$Z R \/\/|-|AT |V|Ak3 t|-|3 \/\/0R|_D g0 R0|_||\|D!!
|-|A[k3R$Z R //|-|AT |V|Ak3 t|-|3 //0R|_D g0 R0|_|||D!!
Yep, if you know the amount necessary to be translated, then you can just add to each x,y, and z coordinate. However, if you want to start concatenating matrices and saving them for later (instead of re-multiplying every game frame), you''ll probably want to store your translations in a matrix.
Yes, you could just add these values to translate your point. But the real reasons for matrices is to make things SIMPLE, not more complex.

How can you describe the position of the last joint of the fourth finger of a villain''s left hand as he chases you across the top of a freight train? The only reasonable way is with matrices.

As I tried to point out above, with matrices, we need only think about that last joint of the fourth finger in terms of where it is relative to its parent, which would be the second to last joint of the fourth finger of the left hand of that hypothetical villain.
_______________________________
"To understand the horse you'll find that you're going to be working on yourself. The horse will give you the answers and he will question you to see if you are sure or not."
- Ray Hunt, in Think Harmony With Horses
ALU - SHRDLU - WORDNET - CYC - SWALE - AM - CD - J.M. - K.S. | CAA - BCHA - AQHA - APHA - R.H. - T.D. | 395 - SPS - GORDIE - SCMA - R.M. - G.R. - V.C. - C.F.

This topic is closed to new replies.

Advertisement