Jump to content
  • Advertisement
Sign in to follow this  
tppramod

3D Transformations into Single Matrix

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i am a beginner in 3D graphics and have learned about various matrix like rotation in X,Y & Z axis, scaling, translation, identity etc. I have also read that these various transformations can be put into a SINGLE MATRIX, which i don't know how to do it? Which one is ideal - doing each transformation one by one and draw to the screen or to convert all the transformations into one matrix and then do the drawing part. i have gone through many tutorials but not getting a clear understanding on this. Can anyone help. Thanks & Regards, Pramod

Share this post


Link to post
Share on other sites
Advertisement
Combining the transformations for one object into a single matrix is more optimal, because most device can transform the object's vertices for you using this single matrix.

Given three independent transformations, say Tt, Tr and Ts (you may say a translation, a rotation and a scaling matrix) you can combine them using matrix multiplication:

Tw = Ts * Tr * Tt

The obtained matrix Tw is usually called the world matrix for that object. This example assumed 4x4 transformation matrices in all cases. You should be able to find out how matrix multiplication works.

Greetz,

Illco

Matrix Multiplication
Matrix Math

Share this post


Link to post
Share on other sites
Rotation/scaling, etc, would normaly require 3x3 matrix. However, by using 4x4 matrix (which is normaly used by 3D APIs and hardware), you can create single matrix with multiple transformation. If you have for example rotation and tranlation, and wish to create one matrix, you just have to multiply these two matrices (matrix concatenatation).

R = rotation matrix
T = translation matrix

C = R*T

C - single matrix with all transformations

Order of multiplication IS important. Transformation by matrix from the left is perfomed first, then matrices to right. In above example, vertices (objects)
will be first rotated in and after then they will be translated.
Then just use C matrix for drawing part (single draw).

It is well explained in "Transforms" topic, "Concatenating Matrices" section in DirectX SDK docs.

Share this post


Link to post
Share on other sites
Here i have got the Matrix multiplication code:

void multiply(float a[4][4],float b[4][4], float c[4][4] ){
int i,j,k;
for( i=0; i<4; i++ ){
for( j=0; j<4; j++ ){
c[j] = 0;
for( k=0; k<4; k++ ){
c[j] += a[k] * b[k][j]
}
}
}
}
multiplies the 4×4 matrices A × B to produce C

But for example look at this Rotation matrix on X axis:
1 0 0 0 <- x' = x
0 cos (Ø) -sin (Ø) 0 <- y' = (cos Ø) * y - (sin Ø) * z
0 sin (Ø) cos (Ø) 0 <- z' = (sin Ø) * y + (cos Ø) * z
0 0 0 1 <- w = 1

here i have calculated the new values of x,y,z in x', y', z' as per the above formula. Now how can i use the matrix multiplication using the above C code since the rotated values are in x,y,z,w!!!?

Share this post


Link to post
Share on other sites
Actually, you can just skip the w. It's only there to make it possible to multiply with the matrix from what I understand. Have you seen this article? In the end of that article is an example of multiplying a matrix with a vertex.

Share this post


Link to post
Share on other sites
You need to multiply matrices, not matrix with point. Only when you get FINAL transformation matrix, multiply point (x,y,z,w) with it to get final transforem point (x',y',z',w').

P = (x,y,z,1) - untransformed point/vertex
A = 4x4 translation matrix
B = 4x4 rotation matrix

C = A*B
P' = P*C

Ok?
btw: you also need matrix*vector code, not just matrix*matrix code...

Share this post


Link to post
Share on other sites
it is somewhat clear now. In every tutorial i have seen that the examples are shown for multiplying between two matrices let say Matrix A * Matrix B and the results in Matrix C. This part is OK. But how do i multiply if i have 4 matrices let say for X-Axis Rotation, Y-Axis Rotation, Scaling and Translation.
The following code will only multiply two matrices at a time. How can this code be modified to take multiple matrix multiplications.

void multiply(float a[4][4],float b[4][4], float c[4][4])
{
int i,j,k;
for( i=0; i<4; i++ )
{
for( j=0; j<4; j++ )
{
c[j] = 0;
for( k=0; k<4; k++ )
{
c[j] += a[k] * b[k][j]
}
}
}
}

Share this post


Link to post
Share on other sites
Don`t change multiplication code, multiply multiple times instead [wink]
float a[4][4];
float b[4][4];
float c[4][4];
float d[4][4];
float e[4][4];
float t1[4][4];
float t2[4][4];


....
//e = a*b*c*d;
//t1=a*b
multiply(a,b,t1);
//t2=a*b*c
multiply(t1,c,t2);
//e=a*b*c*d
multiply(t2,d,e);

something like that...
Why do you write this code yourself??? Use some library...

Share this post


Link to post
Share on other sites
thanks bulma. now i clearly understood the concept and its application.

In the last reply u have said that the matrix * vector code is also required. Is it for making the faces (QUAD) of vertices? Any help on that.

[Edited by - tppramod on June 24, 2005 12:10:51 AM]

Share this post


Link to post
Share on other sites
now i have understood Matrix * Matrix Code but what is this new stuff MATRIX * VECTOR CODE. Anybody there to help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!