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

## Recommended Posts

Hi, i'm trying do vertex transformation without opengl standard commands: Assume we have the polygon: glTexCoord2f(1.0f, 1.0f); glVertex3f ( 5, 5 , 0 ); glTexCoord2f(0.0f, 1.0f); glVertex3f ( 5, 10, 0 ); glTexCoord2f(1.0f, 0.0f); glVertex3f (10, 10, 0 ); glTexCoord2f(0.0f, 0.0f); glVertex3f (10, 5 , 0 ); now i want to represent it on 4x4 matrix so i did: 5 5 10 10 5 10 10 5 A = 0 0 0 0 0 0 0 0 so as i figured out, the transform matrix is: 1 0 0 x B = 0 1 0 y 0 0 1 z 0 0 0 1 If i'm doing D = B*A i suppose to get for each vector (column) on A the transformed coords. now if i'm draw: glTexCoord2f(1.0f, 1.0f); glVertex3f ( D[0][0], D[1][0] , D[2][0] ); glTexCoord2f(0.0f, 1.0f); glVertex3f ( D[0][1], D[1][1] , D[2][1] ); glTexCoord2f(1.0f, 0.0f); glVertex3f ( D[0][2], D[1][2] , D[2][2] ); glTexCoord2f(0.0f, 0.0f); glVertex3f ( D[0][3], D[1][3] , D[2][3] ); i don't get the desire results what am i missing?

##### Share on other sites
You are completely missing the translation component of the matrix. That matrix is not a 3d linear transformation, but an affine one, so you need to multiply the matrix with (x y z 1) - you are currently doing (x y z 0). In other words your glVertex calls should more like this..

glVertex3f ( D[0][0] + D[0][3], D[1][0] + D[1][3], D[2][0] + D[2][3]);

##### Share on other sites
so you saying that i need to do:
5 5 10 10
5 10 10 5
0 0 0 0
1 1 1 1

and then:
glVertex3f ( D[0][0] + D[0][3], D[1][0] + D[1][3], D[2][0] + D[2][3]);

???

i there another way doing it?

tnx

##### Share on other sites
No, you'd just shove 1's into the last row of A, do your matrix mult, and then draw the columns like before.

##### Share on other sites
i have tried to do:
glVertex3f ( D[0][0] + D[0][3], D[1][0] + D[1][3], D[2][0] + D[2][3]);
but it does not works. so i opened matrix calculator and typed the numbers.

Matrix Multiplication

Results page

Input matrix A:

1.000 0.000 0.000 0.000
0.000 1.000 0.000 20.000
0.000 0.000 1.000 0.000
0.000 0.000 0.000 1.000

Input matrix B:

5.000 5.000 10.000 10.000
5.000 10.000 10.000 5.000
0.000 0.000 0.000 0.000
1.000 1.000 1.000 1.000

Matrix product A*B

5.000 5.000 10.000 10.000
25.000 30.000 30.000 25.000
0.000 0.000 0.000 0.000
1.000 1.000 1.000 1.000

so as you can see each column of A*B is gets the Y transform.
so my problem was that i forgot the 1's at the end of each column.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
633715
• Total Posts
3013497
×