DeadlyDan 123 Report post Posted September 15, 2008 Hi there, in my project i want to rotate around a local-axis. I've been spending quite a lot of time trying to figure out how i can convert the following angles: X, Y, Z: 0, 0, 90 Along the orientation of the current angles of my object. Which is already rotated along is local axis. Simply setting it to the above changes it according to world angles, which isn't relative to the objects orientation. If anyone can help it is greatly appreciated, i need to set the exact current rotation and still maintain the objects current orientation. Thanks, Dan 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted September 15, 2008 The following method actually rotates around the global equivalent of the chosen local axis.To rotate around an "arbitrary" axis you can use the axis/angle representation of rotations. This can easily be converted into a quaternion or rotation matrix, whatever you use to handle rotations.To get the correct axis you have to transform the local axis (e.g. [0 0 1] for the z axis) by the same rotation that has caused the current orientation of the model. If you have the belonging local-to-global transformation matrix at hand, then the transformation mentioned above simply picks the belonging row (if using row vectors) or column (if using column vectors), resp., from the basis of the matrix. 0 Share this post Link to post Share on other sites
DeadlyDan 123 Report post Posted September 15, 2008 Hi, thanks for your very informative answer, i'm having a bit of trouble understanding it, could you perhaps show me in pseudo code?Thanks,Dan 0 Share this post Link to post Share on other sites
haegarr 7374 Report post Posted September 15, 2008 Pseudo code is a bit problematic, because of the various possibilities.Assumeing you have a transformation matrix at hand that is used as local-to-global transformation. Then the matrix desribes how the local co-ordinate frame is to be rotated and translated so that it is located in the world as desired (we ignore scaling here since it (a) makes the things more complex and (b) is seldom used). Looking at the matrix, you'll see a 3x3 sub-matrix, a position vector, and a 0 vector. If you use column vectors then the layout may look like[ rxx ryx rzx tx ][ rxy ryy rzy ty ][ rxz ryz rzz tz ][ 0 0 0 1 ](e.g. OpenGL), and if you use row vectors then the layout may look like[ rxx rxy rxz 0 ][ ryx ryy ryz 0 ][ rzx rzy rzz 0 ][ tx ty tz 1 ](e.g. D3D). Other orders are possible, too. You haven't told us which version you use.If you want to rotate around an axis that is e.g. [0 0 1] in the local space, then the same axis given in global space isM * [0 0 1 0]^{T}for column vectors, resp.[0 0 1 0] * Mfor row vectors, where M is to be substituted with the matching matrix from above. If you really perform the multiplication, you will see that[rzx rzy rzz] for local zis the result for the given local axis (namely z). Similarly, you get[rxx rxy rxz] for local x[ryx ryy ryz] for local ySo the said 3x3 sub-matrix gives the global space equivalents of the local co-ordinate axes. You can pick out which axis you want and use it furthur for the axis/angle rotation.For the coherences of the various rotation representations see e.g. here, and especially for conversion from axis/angle to matrix see e.g. here (you only need the part in-between "which can be expanded out to give the terms of the matrix components" and "This can be written as the sum of 3 matricies"). I hope those source is correct, but normally I've heard only good things about "euclideanspace". 0 Share this post Link to post Share on other sites