#### Archived

This topic is now archived and is closed to further replies.

# Rotation Matrix, By Hand

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

## Recommended Posts

lets say I got a class: class Matrix_class { float Matrix[4][4]; void TranslationMatrix(float x,float y,float z); void RotationMatrix(float Xa, float Ya,float Za); } Ive already written the TranslationMatrix() function(yes, I know, its simple, but Im still happy), but I need a little help with the rotation. The function should set Matrix, to a Rotation Matrix that takes in acount the Angles, Xa,Ya,Za. Thanks for the help(and I searched for similear posts, but never found one where they did it by hand). later,

##### Share on other sites
And what about a MatrixMultiply() function, that would be compatible with OpenGL''s Matrices, anyone?

##### Share on other sites
Witchlord, I know you know the answer!

##### Share on other sites
There's a lot of sin's cos's & some theta's & some phi's

in 2D i believe its
[ [cos(theta), 0]
[0, -sin(theta)] ]
though I may have every-which-thing reversed
Draw a picture, you do know trig right?

I cant seem to find my cg book at the moment, otherwise I'd have the 3D answer ...

Edited by - Magmai Kai Holmlor on June 24, 2000 12:02:04 AM

##### Share on other sites
I dont know enough trig to figure it out. Ill probaly be learning what I need this year in school(only a Freshmen, in Highschool). Ill try to figure it out, but if you could give me the full equation that would really help, thanks,

##### Share on other sites
I have just figured out, its impossible for me, I dont understand cos, sin, enough, could someone at least help with that(I know 90% of the people on this board understand that). Thanks for any help you can give me

##### Share on other sites
No trig eh? I suppose that means no linear algebra either?
I hope you like math

Here are the three Rotation matricies:

Rx
[1, 0, 0, 0]
[0, cos(theta), sin(theta), 0]
[0, -sin(theta), -cos(theta), 0]
[0, 0, 0, 1]

Ry
[cos(theta), 0, -sin(theta), 0]
[0, 1, 0, 0]
[-sin(theta), 0, cos(theta), 0]
[0, 0, 0, 1]

Rz
[cos(È), sin(È), 0, 0]
[-sin(È), cos(È), 0, 0]
[0, 0, 1, 0]
[0, 0, 0, 1]

the È's are about the respective axi

Do you know how to multiple matricies? hehe well atually, do you have a TI-92? Cause you (nor I) will not doing that by hand!

heheh it didnt take those Θ's very well did it? those are thetas...

Edited by - Magmai Kai Holmlor on June 25, 2000 1:23:10 AM

##### Share on other sites
The second before you wrote that I copied it out of a book I found, But it wouldnt work because I didnt convert it to degrees, STUPID ME, I just did Ya=Ya*(PI/180), and HAHA, It works, Im so happy. Now, would you write a function to multiply to 4x4 Matricies. Thanks for posting too.

##### Share on other sites
Ok here we go:
(You know, there''s a reason why you don''t do this yourself )

Rotate(a, b, c):

[cos(b)*cos(c), cos(b)*sin(c), -sin(b), 0]

[-cos(a)*sin(c)-sin(a)*sin(b)*cos(c), cos(a)*cos(c)-sin(a)*sin(b)*sin(c), sin(a)*cos(b), 0]

[cos(a)*sin(b)*cos(c)+sin(a)*sin(c), cos(a)*sin(b)*sin(c)-sin(a)*cos(c), -cos(a)*cos(b), 0]

[0, 0, 0, 1]

note that is is only one possible solution - there are many (all produce the same result, more or less)

##### Share on other sites
well damn it, you couldn''t posted that few minutes earlier and saved me all that typing! ;-P

... a 4x4 multipler?

oh god... matrix math is hard
Do you know the row & column rules?

M1[nxb] * M2[bxm]
the b''s gotta be the same - but i guess you''re just gonna mult 4x4''s arent ya?

i is the row, j is the col

M3 = M1 * M2
M3[i,j] = Sum(M1[row i] * M2[col j])

for(int i=0;i<4;i++)
{
float sum =0;
for(int j=0;j<4;j++)
{
sum += M1[i,j] * M2[j,i]
}
M3[i,j] = sum;
}

1. 1
2. 2
3. 3
Rutin
21
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 10
• ### Forum Statistics

• Total Topics
633653
• Total Posts
3013149
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!