09.03Getting rotation properties from Matrix3D transform – Flash AS3, Augmented Reality, PV3D
First off, I am no mathematician. I’ve been doing a lot of Augmented Reality in Flash AS3 lately and there is one hurdle I’ve overcome that may be useful to document for some of you out there. How do you get the rotation properties of a 3D Object after the Matrix3D Transform has been applied to it in PaperVision? The problem is that if you have an object rotated in 3D space, those properties get overwritten once the Matrix3D Transform gets applied to it. All rotation values return as zero. I found this sliver of information on the Adobe ActionScript 3.0 Language Reference:
“Display objects cache their axis rotation properties to have separate rotation for each axis and to manage the different combinations of rotations. When a method of a Matrix3D object is called to transform a display object, the rotation cache of the object is invalidated.”
Of course there’s no documentation on how to get the rotation information in degrees for after the fact. That would be too easy. I couldn’t find any straightforward info from the PaperVision docs either. I’ll save you the story of pain and suffering on how I figured it out, but the solution is to use the matrix2euler() function in the org.papervision3d.core.math.Matrix3D package. What the hell is a Euler? I have no idea. Why hadn’t anyone explained how and why one should use it? I have no clue. Here is what I do know:
- you need to pass the transform property of a DisplayObject into the matrix2euler function after the Matrix3D transform has been applied to it.
- The matrix2euler() function returns a Number3D object storing its rotationX, rotationY, rotationZ properties deceivingly in the Number3D’s x,y, and z properties. rotationX = x, rotationY = y, rotationZ = z (I figured this out on my own at 3am the morning my project was due)
Here’s how your code should somewhat look like:
var rotationObj:Number3D = Matrix3D.matrix2euler(myDisplayObject.transform);
trace(rotationObj.x);// Whatever the current rotation on the X axis is.
If I have time in the future I’ll put up an actual example of it’s use. In the meantime, here is a graphic I made that explains what the rotations look like when converted to Eulers:



Leave a Reply
You must be logged in to post a comment.