Advertisement

Matrix Rotations...once again...

Started by February 13, 2003 06:14 AM
5 comments, last by Drag0n 22 years ago
Hi! So far so good. I have a class called Movable. You can set the position and the direction. And you're also able to set the rotations, for all rotation axes seperately. Now, I would like convert the transformation given by the direction to rotations I can save in the axes' rotation values. I know how to calculate the angle between identity and the new direction, and I also know how to get the axis that rotation is rotated about (correct me if I'm wrong: that would be the cross product). That would give me 1 angle and 1 axis. What I would like to get is 3 angles, corresponding to the three coordinate axes, respectively. And then I would like to class one function that will rotate my matrix so I get the transformation the direction would have given me. Does anyone know how to solve this problem? And do you understand what my problem is, anyways? Thx, Drag0n "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook [edited by - Drag0n on February 13, 2003 9:22:15 AM]
-----------------------------"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook"...nobody ever accused English pronounciation and spelling of being logical." -- Bjarne Stroustrup"...the war on terror is going badly because, if you where to compare it to WWII, it's like America being attacked by Japan, and responding by invading Brazil." -- Michalson
Assuming your direction is a unit vector then it is the cosines of the angles with the axes. I think for what you want though you need an up vector. You are short an angle because a direction doesn''t tell you an orientation. Any rotation about the direction is still the same direction. It makes a world of differance or a differant world rendered to the screen, but it is still the same direction.
Keys to success: Ability, ambition and opportunity.
Advertisement
Yeah, you''re right. I forgot that one. So I need an up vector. Also no problem. But I still want to build the transformation matrix new every frame from the angles rather than do someting like LookAt().

Drag0n
-----------------------------"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook"...nobody ever accused English pronounciation and spelling of being logical." -- Bjarne Stroustrup"...the war on terror is going badly because, if you where to compare it to WWII, it's like America being attacked by Japan, and responding by invading Brazil." -- Michalson
Ok, I think I see. Assuming rotation about x then y then z axes with rz, ry and rz being the angles of rotation. (xx,xy,xz) is the direction of the objects x axis in world coordinates and (yx,yy,yz) for the y axis. Then rz = atan2(xy,xx) and ry=atan2(xz, sqrt(xx*xx + xy*xy)). Now cz=cos(rz), cy=sin(ry), sz=sin(rz) and sy=sin(ry) then rx=atan2(yz*cy - yx*cy*cz - yy*sy*sz, yy*cz - yx*sz). The last one might be a bit off. If you apply the reverse rotations to a set of orthogonal unit vectors in the reverse order it should move them back to the standard basis vectors, i.e. (1,0,0), (0,1,0) and (0,0,1).

Ok, I have somewhat of a simplification for the last part. rx = atan2(yz*(xx*xx + xy*xy) - xz*(xx*yx + xy*yy), |X|*(xx*yy - xy*yx)) where X=(xx,xy,xz) and |X| is the magnitude of X. Since |X| should be one that eliminates the square root. Still a lot of multiplications, but saves four trig functions. One more multiplication to save four trig functions seems a favorable trade off.

I'm not absolutely sure it is an equivalent. How I got it was changing all the sin(atan2()) and cos(atan2()) to rational expressions using the parameters. I then divided the y parameter by the x parameter and put it all over a common denominator and simplified. I just can't be sure that the signs are correct in all cases. I did compare the two in all quadrants and it gave the same result. Far from a definite proof, but at least reasonable.



[edited by - LilBudyWizer on February 14, 2003 2:40:19 AM]

[edited by - LilBudyWizer on February 14, 2003 2:40:51 AM]
Keys to success: Ability, ambition and opportunity.
Thanks allot!
Merci Beaucoup!
Dankeschön!
???????!

Drag0n
-----------------------------"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook"...nobody ever accused English pronounciation and spelling of being logical." -- Bjarne Stroustrup"...the war on terror is going badly because, if you where to compare it to WWII, it's like America being attacked by Japan, and responding by invading Brazil." -- Michalson
Ooops...it couldn''t display the russian thing...
-----------------------------"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning..." -- Rich Cook"...nobody ever accused English pronounciation and spelling of being logical." -- Bjarne Stroustrup"...the war on terror is going badly because, if you where to compare it to WWII, it's like America being attacked by Japan, and responding by invading Brazil." -- Michalson
Advertisement
quote:
Original post by Drag0n
Ooops...it couldn''t display the russian thing...


Do You know russian?
C++ RULEZ!!! :)

This topic is closed to new replies.

Advertisement