Jump to content
  • Advertisement
Sign in to follow this  
PhilSmith

Finding rotation from a 3x3 (2D) matrix

This topic is 2566 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys,

I'm currently trying to use the raw data from flash's .xfl files to create animation key frames and accurately display the animations on the screen using Unity.

Why I want to do this:

I have a very large number of animations created in flash and therefore using standard sprite-sheets is not an option due to the very large file size that would be generated by doing so. Therefore I've opted to use the transformations found within the exported flash file to move individual components of the character (e.g. arms/legs/body/head).

The file format exports an XML file containing the animation keyframes however, it contains a 3x3 matrix and a transformation point. While this is not an issue for most game engines, Unity does not have any kind of access to matrices as far as I know (only ones available are read-only).

The matrix comes in the format:

| a b tx |
| c d ty |
| 0 0 1 |

There's no scaling involved so a,b,c,d are purely rotation values, however the problem comes where I can't for the life of me reverse the rotation matrix to find the original rotation value.

Sure I can use Acos/ASin to get values in a certain range, however some of the animation pieces frequently use the whole range of values 0-359 and therefore reversing the cos/sin calculations results in values that don't match each other.

I'm not all that hot on mathematical functions and the likes, and was hoping someone could help me out with this problem?


On a side note: has anyone got a suggestion for going about this better? Everything's a bit experimental at the moment. The animations are done in flash and unless 100% necessary, it needs to stay that way (I can't really tell my artist to do it all over again in a different program). Has anyone attempted this before? Are there any programs out there to do this?

Share this post


Link to post
Share on other sites
Advertisement
Unless i'm mistaken, flash actually uses a matrix:

| a c tx |
| b d ty |
| 0 0 1 |

:P

anyways, with no skewing (scaling is unimportant) you can use atan2 to find the rotation in the entire (0-2pi) range: atan2(b,a)

Share this post


Link to post
Share on other sites
Thanks for the correction tongue.gif

I've been at this for over 6 hours now, my brains a bit frazzled!

Thanks for the help as well, the rotation values are working as they should, now just to get the translation/pivot working better laugh.gif

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!