Euler Angles Beyond 90 degrees from Matrix
I looked around all over the place to find out how to extract euler angles from a matrix, and I found it. Yippeee right? Nope, I'm dealing with sort of a more unique problem. Apparently, and this makes sense, you can only extract angles that are limited to 0 and 89 degrees. Here is the problem I am posed with:
1. Rotate a matrix around it's axes 360 degrees
2. Extract x rotation from matrix
I end up with 0 degrees. I need it to give me 360 degrees.
I am writing a plugin for AfterEffects that will export animations to LightWave. If I have a AfterEffects layer rotating around it's axes 4 times, then I need to be able to convert that rotation from xyz order (AfterEffects) to yxz order (LightWave).
Actually, all these numbers are in radians in my source code, but I am calling them degrees here for simplicity.
Any help would be appreciated. Thank you.
But 0 degrees is 360 degrees. A matrix rotated (odd terminology, but ok) 0 degrees, and a matrix rotated 360 degrees look exactly the same.
I just ran some more tests, and it looks like I can get a number aproximatly between -1.57 to 1.57, which ends up being 180 degrees. I still need it to give me a larger range than that, if it is even possible.
The variables r0, r1, and r2 was my attempt at determining how many times a full rotation occurred, and then I was adding it to the rotations after they were converted to a different order.
Here's my source code (updated to reflect what does work -- but not to the degree I need it to work, pun not intended :)):
[Edited by - WhatEver on August 26, 2008 6:59:00 PM]
The variables r0, r1, and r2 was my attempt at determining how many times a full rotation occurred, and then I was adding it to the rotations after they were converted to a different order.
Here's my source code (updated to reflect what does work -- but not to the degree I need it to work, pun not intended :)):
CMNvoid aeAnglesToLwAngles() { CMNKeyIterator i0, i1, i2; CMNKey *k0, *k1, *k2; CMNint r0, r1, r2; EulerAngles outAngs, inAngs; HMatrix R; k0 = Channels[3].getFirstKey( i0 ); k1 = Channels[4].getFirstKey( i1 ); k2 = Channels[5].getFirstKey( i2 ); while( k0 || k1 || k2 ) { inAngs.x = inAngs.y = inAngs.z = 0.0f; inAngs.w = EulOrdXYZr; r0 = r1 = r2 = 0; if(k0) { inAngs.x = k0->Value; r0 = k0->Value / CMN_PI; } if(k1) { inAngs.y = k1->Value; r1 = k1->Value / CMN_PI; } if(k2) { inAngs.z = k2->Value; r2 = k2->Value / CMN_PI; } Eul_ToHMatrix(inAngs, R); outAngs = Eul_FromHMatrix(R, EulOrdYXZr); //if(k0) { k0->Value = outAngs.y + (r0 * CMN_PI); } //if(k1) { k1->Value = outAngs.x + (r1 * CMN_PI); } if(k2) { k2->Value = outAngs.z + (r2 * CMN_PI); } if(k0) { k0->Value = outAngs.y; } if(k1) { k1->Value = outAngs.x; } //if(k2) { k2->Value = outAngs.z; } if(k0) { k0 = Channels[3].getNextKey( i0 ); } if(k1) { k1 = Channels[4].getNextKey( i1 ); } if(k2) { k2 = Channels[5].getNextKey( i2 ); } } }
[Edited by - WhatEver on August 26, 2008 6:59:00 PM]
Mike, maybe that was a bad example. Let's say I rotate 385 degrees. I don't want to retrieve a value that is restricted to a number that falls between 0 and 90 degrees, I want it to return 385 degrees.
Angle information above 360 degrees will be lost in translation to a matrix. It would be impossible to extract it.
That makes total sense, but here is my theory.
If I have the variable that rotated the matrix, I know the exact rotation of the matrix. So what I am essentially trying to do is convert from xyz rotation to yxz rotation and since I currently have the angles from the xyz rotation, shouldn't I be able to use the xyz rotations to modify the yxz rotations in conjunction with the matrix?
If I have the variable that rotated the matrix, I know the exact rotation of the matrix. So what I am essentially trying to do is convert from xyz rotation to yxz rotation and since I currently have the angles from the xyz rotation, shouldn't I be able to use the xyz rotations to modify the yxz rotations in conjunction with the matrix?
Quote:Original post by WhatEverMy question would be, why do you need to do this? Is there a reason that the output needs to fall in a certain range (e.g. 370 degrees rather than 10 degrees)?
That makes total sense, but here is my theory.
If I have the variable that rotated the matrix, I know the exact rotation of the matrix. So what I am essentially trying to do is convert from xyz rotation to yxz rotation and since I currently have the angles from the xyz rotation, shouldn't I be able to use the xyz rotations to modify the yxz rotations in conjunction with the matrix?
Consider that even if you build a matrix from an Euler-angle triple, and then extract the Euler angles in the same order, you may not get the same angles back (depending on the algorithm used). However, this is usually not a problem, because multiple Euler-angle triples can map to the same orientation (due to aliasing).
My guess is that the information you're trying to retrieve will most likely be lost in the conversion. I also suspect that it's not worth trying to get the exact angles back (unless there's something about your situation that I'm not understanding - which may very well be the case).
edit:
Key frames can contain values beyond the range of 0-360 degrees, so I need to preserve degrees that are beyond the 0-360 degree limit.
I'm trying to export key frames from AfterEffects to Lightwave, the only problem is that AfterEffects rotates in xyz order, and LightWave rotates in yxz order. The only method that I am aware of that will convert from one order of angles to another is a two part process.
These are the steps I am taking to convert from xyz order to yxz order
1. rotate a matrix in x, y and z order
2. extract the angles in y, x and z order
But when I do this, I lose any angle that goes outside of the 0 - 180 degree range.
So is it not possible? Am I using the wrong method for converting keyframes from one rotation system to another?
I'm beginning to think it is not possible. Because like you said, I lose that rotation value once the conversion has been made.
Key frames can contain values beyond the range of 0-360 degrees, so I need to preserve degrees that are beyond the 0-360 degree limit.
I'm trying to export key frames from AfterEffects to Lightwave, the only problem is that AfterEffects rotates in xyz order, and LightWave rotates in yxz order. The only method that I am aware of that will convert from one order of angles to another is a two part process.
These are the steps I am taking to convert from xyz order to yxz order
1. rotate a matrix in x, y and z order
2. extract the angles in y, x and z order
But when I do this, I lose any angle that goes outside of the 0 - 180 degree range.
So is it not possible? Am I using the wrong method for converting keyframes from one rotation system to another?
I'm beginning to think it is not possible. Because like you said, I lose that rotation value once the conversion has been made.
If you're trying to duplicate an animation in After Effects in LightWave, one option would be instead of dumping just keyframes, grab the rotations from every frame from After Effects. If you have every frame then you don't need to worry about sign reversals in the key frame interpolations.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement