Reputation: 513
Given I have three transform properties rotateX(20deg)
rotateY(30deg)
and rotateZ(50deg)
, is it possible to calculate matrix3d(...)
?
In this example matrix3d
would be:
matrix3d(0.5568,-0.77,0.50,0,0.77,0.6016,0.34,0,-0.5,-0.34,0.8178,0,0,0,0,1);
Upvotes: 0
Views: 616
Reputation: 346
Here is good resolve for your problems with matrix3D: https://gist.github.com/f5io/7466669
var str = matrix3d(0.5568,-0.77,0.50,0,0.77,0.6016,0.34,0,-0.5,-0.34,0.8178,0,0,0,0,1),
out = create();
function deg2rad(deg) {
return deg * (Math.PI / 180);
}
function create() {
var out, args = Array.prototype.slice.call(arguments);
if (args.length > 0 && args.length < 16) throw 'Invalid arguments supplied!';
if (args.length === 0) {
out = new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);
} else {
out = new Float32Array(args);
}
return out;
}
function fromTransform (str) {
var r = str.match(/([\d.-]+(?!\w))+/g);
return new Array([
r[0], r[1], r[2], r[3],
r[4], r[5], r[6], r[7],
r[8], r[9], r[10], r[11],
r[12], r[13], r[14], r[15]
]);
}
function rotate(out, deg) {
var rad = deg2rad(deg),
cos = Math.cos(rad),
sin = Math.sin(rad);
out[0] = cos;
out[1] = sin;
out[4] = -sin;
out[5] = cos;
}
function rotateX(out, deg) {
var rad = deg2rad(deg),
cos = Math.cos(rad),
sin = Math.sin(rad);
out[5] = cos;
out[6] = sin;
out[9] = -sin;
out[10] = cos;
}
function rotateY(out, deg) {
var rad = deg2rad(deg),
cos = Math.cos(rad),
sin = Math.sin(rad);
out[0] = cos;
out[2] = sin;
out[8] = -sin;
out[10] = cos;
}
function rotateZ(out, deg) {
Matrix3D.rotate(out, deg);
}
Here you can read more about 3D to better understand: https://developer.apple.com/library/safari/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Using2Dand3DTransforms/Using2Dand3DTransforms.html#//apple_ref/doc/uid/TP40008032-CH15-SW16
Upvotes: 2