Rotation around a world axis ( rotation two axis )
by Tom Lenz · in Torque Game Engine · 02/05/2009 (7:55 pm) · 5 replies
I am currently working on a project where the player rotates an object along two axis ( the x and the y ). Using matrix multiplication I have been able to rotate the object around both axis separately. However, if I try to rotate along both axis at the same time ( or one after the other ), the second rotation is no longer along the original axis ( the world axis ). I have tried using quaternions but I have been getting the same results. I have been doing the calculations by hand and they are coming out right, but it still seems that Torque doesn't want to apply the rotations around the world axis ( or at the same time ). I have created a video of what I mean hopefully that will help explain.
The one on the left is what I want to happen. The rotation always happening around the original axis ( world axis ). The one on the right is what is happening.
In case your wondering the reason this needs to be fixed is that after the player has rotated the shape around one axis the controls flip for the other axis.
Here is the code that I am using, hope it helps
$xRotation is the degree of rotation on the x axis
$yRotation is the degree of rotation on the y axis
Thanks in advanced
The one on the left is what I want to happen. The rotation always happening around the original axis ( world axis ). The one on the right is what is happening.
In case your wondering the reason this needs to be fixed is that after the player has rotated the shape around one axis the controls flip for the other axis.
Here is the code that I am using, hope it helps
$xRotation is the degree of rotation on the x axis
$yRotation is the degree of rotation on the y axis
%thetaX = mDegToRad($xRotation); %thetaY = mDegToRad($yRotation); %xRot = "1 0 0" SPC %thetaX; %yRot = "0 1 0" SPC %thetaY; %matrixX = "0 0 0" SPC %xRot; %matrixY = "0 0 0" SPC %yRot; %productXY = MatrixMultiply(%matrixX, %matrixY); %currentTransform = fuzz.getTransform(); %transform = getWords(%currentTransform, 0, 2) SPC getWords(%productXY, 3, 6); fuzz.setTransform(%transform);
Thanks in advanced
About the author
#2
02/15/2009 (10:15 am)
I think you simply have your rotations out of order. MatrixMultiply(X, Y) is applying an X rotation to your Y rotation matrix. What I guess you're looking for is to apply Y rotation to your X rotation matrix. Think of it as MatrixMultiply(rotatOR, rotatEE). Try MatrixMultiply(Y, X) instead.
#3
02/16/2009 (1:17 pm)
I went ahead and tried what you suggested, simply switching the way the matrix are multiplied. The result was the same. Any thing else?
#4
Directly from my console, I tested:
Note the axis of rotation has an inverted Z. The results still may not be what you're looking for, but it will be different.
Does your log show any script errors that might prevent it from compiling?
02/17/2009 (8:00 am)
Are you sure the result was the same? Directly from my console, I tested:
==>$xrot = "1 0 0 1"; ==>$yrot = "0 1 0 1"; ==>$xmat = "0 0 0" SPC $xrot; ==>$ymat = "0 0 0" SPC $yrot; ==>echo($xmat); 0 0 0 1 0 0 1 ==>echo($ymat); 0 0 0 0 1 0 1 ==>$result = MatrixMultiply($xmat, $ymat); ==>echo($result); 0 0 0 0.659603 0.659603 -0.360343 1.38344 ==>$result = MatrixMultiply($ymat, $xmat); ==>echo($result); 0 0 0 0.659603 0.659603 0.360343 1.38344
Note the axis of rotation has an inverted Z. The results still may not be what you're looking for, but it will be different.
Does your log show any script errors that might prevent it from compiling?
#5
02/17/2009 (8:36 am)
There are no script errors but it is essentially the same. All that has changed is the axis. Before the shape would always rotate around the world y axis and now it will always rotate around the world x axis. I get the same problem but the axis are switched. As far as the actual value it is the same as yours.
Torque Owner Tom Lenz