View Full Version : Matrix rotation?
Cactus Dan 03142004, 05:24 PM Howdy,
How do I calculate the rotation of a matrix around one of its local axes by a given angle?
For example:
I have a function that will return an object's matrix. Then I have an angle (theta) that I've calculated and want the matrix to rotate around its current local Y axis by theta.
http://home.earthlink.net/~cactusdanl/Rotate.jpg
I'm using my software's scripting language that seems to only have a function to set an object's rotation in HPB world coordinates.
Thanks in advance for any help.
Adios,
Cactus Dan


dead_eye
03142004, 07:55 PM
Let's say you have an object at (10,10,10) with normalized local axes:
[0 1 0]
[1 0 0]
[0 0 1]
which is equivalent to the object being rotated by 90 degrees (the
x and y axes were swapped).
Now let's say you want to rotate about the object xaxis, but it's
really rotatation about the world's yaxis.
Here's what ya do.
Transform your object to the origin by with a translation matrix T:
T = [1 0 0 10]
[0 1 0 10]
[0 0 1 10]
[0 0 0 1].
Then map your axes. You want to map points along your object's xaxis
to points to the world's yaxis and your object's yaxis to the world's
xaxis. Just make an orthogonal matrix of your local axes, M.
M = [0 1 0 0]
[1 0 0 0]
[0 0 1 0]
[0 0 0 1]
What does it do? Well it maps points from the local xaxis to points
in the world's yaxis. OpenGL uses this same technique for it's function
gluLookAt to map your camera's coordinate system to OpenGL's camera coordinate
system (which is at (0,0,0) and looking down the z axis).
[0 1 0 0] [0] [5] (multiplying M by (0,5,0) = (5,0,0)... it maps
[1 0 0 0] [5] = [0] (points in they yaxis to points in the xaxis.
[0 0 1 0] [0] [0] (also note M is a rotation matrix about the zaxis).
[0 0 0 1] [1] [1]
Now that you have your local system mapped to the world's sytem, apply
your rotation matrix, R. Then apply inverse transformations of M and T.
Concatenated Matrix = T*M*R*M*(1)*T(1)
Cactus Dan
03152004, 04:39 AM
Howdy,
Thanks for the reply.
Although, I'm not sure I fully understand your answer.
It sounds like you move the object to the origin, rotate it, then move it back with the rotation?
Anyway, I did some research in the SDK and found some more matrix functions that set individual rotations around x, y and z axes. I also found one that returns the product of matrixA and matrixB. The result is matrixB expressed in matrixA's parent system.
So, my solution is to get the objects matrixA, create matrixB in memory (at the origin), rotate it around the Y axis, then express it in matrixA's parent system and set the new matrix to the object. It works.
It sounds like that might be what you were describing in your answer. I just got lucky and found those functions to make it easier for me to figure out.
Thanks again.
Adios,
Cactus Dan
Geespot
03152004, 11:12 AM
Cactus Dan, im guessing this is coffee?
Have a look at this function, Matrix::SetRotAxis(axis,angle)
It allows you to rotate a Matrix on the axis by angle, heres an example
main(doc,op)
{
var angle=2;
var axis = vector(1,0,0);
var m = op>GetMg();
m>SetRotAxis(axis,Radians(angle));
op>SetMg(op>GetMg()>GetMulM(m));
}
If this isn't for coffee, then totally ignore this reply :)
Cactus Dan
03162004, 01:21 AM
Howdy,
Originally posted by Geespot
Cactus Dan, im guessing this is coffee?
Yep, it is COFFEE that I'm using.
Thanks for the tip. Your routine seems to work a little easier.
Adios,
Cactus Dan
CGTalk Moderation
01172006, 05:00 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.