Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reverse-engineer a webkit matrix3d transform

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? :-)

like image 804
Matt H. Avatar asked May 15 '12 00:05

Matt H.


People also ask

What is the matrix3d () transform function?

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.

How to use 3D transformation with CSS transform?

With the CSS transform property you can use the following 3D transformation methods: 1 rotateX () 2 rotateY () 3 rotateZ () More ...

What is the inverse of a transformation matrix?

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.

How do I apply a 3D transform to an element?

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.


1 Answers

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

like image 195
Ruan Caiman Avatar answered Sep 29 '22 01:09

Ruan Caiman