I've got a cube element being rotated and translated in a 3d space.
I want to find out just the rotateY portion of this transform at a given time. Is this possible?
I have:
var cube = document.getElementById("cube");
var transform = getComputedStyle(cube).webkitTransform;
//the value of transform is:
// matrix3d(-1, 0, 0.00000000000000012246467991473532, 0,
// 0, 1, 0, 0,
// -0.00000000000000012246467991473532, 0, -1, 0,
// 0, 0, 0, 1)
Help? :-)
The matrix3d () transform function is available on the following: Safari 4.0.3 and later running on Mac OS X version 10.6 and later. iOS 2.0 and later. Google Chrome 12.0 and later. Specifies a perspective projection matrix. Where depth equals the distance, in pixels, of the z=0 plane from the viewer.
With the CSS transform property you can use the following 3D transformation methods: 1 rotateX () 2 rotateY () 3 rotateZ () More ...
If your transformation matrix is a rotation matrix then you can simplify the problem by taking advantage of the fact that the inverse of a rotation matrix is the transpose of that matrix. If your transformation matrix represents a rotation followed by a translation, then treat the components separately.
3D transforms are applied via the same -webkit-transform property as 2D transforms. For example, here’s how to rotate an element about the Y (vertical) axis: Move the element in x, y and z, and just move the element in z. Positive z is towards the viewer. Unlike x and y, the z value cannot be a percentage.
If your object is only being rotated about Y, then yes, the rotation is simple to calculate - it's the arccos of Matrix elements 1,1 or 3,3 or the arsin of -(element 3,1) or arcsin of element 1,3. In your specific example, it's about 180 degrees. If the rotations are about more than just the y axis, then you have to start tracking previous rotations and it can get messier.
Your translation will just be the bottom row of the output matrix, 0,0,0 in this case.
See examples on http://www.inversereality.org/tutorials/graphics%20programming/3dwmatrices.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With