I'm using this script that claims to implement matrix3d operation as described in the spec, however the script is missing matrix perspective operations, so I "cooked" something I'm not sure is either accurate or correct.
// the perspective matrix to multiply with
CSSMatrix.Perspective = function(x, y, z){
var m = new CSSMatrix();
m.m13 = x;
m.m23 = y;
m.m33 = z;
return m;
};
and the method to use this matrix
// myMatrix.perspective(x,y,z); to apply a perspective matrix
CSSMatrix.prototype.perspective = function(x, y, z){
if (y == null) y = 0;
if (z == null) z = 0;
return CSSMatrix.multiply(this, CSSMatrix.Perspective(x, y, z));
};
My question is, if y
and z
are undefined
, what values should be used? Is it gonna be like rotate where x
is used for all other axis, or 0 (zero) as in the above code?
I'm also not sure if CSSMatrix.Perspective
matrix is properly written as described in the spec and implemented into the CSSMatrix
prototype.
UPDATE: I've found another implementation of the perspective functions (see below) and created a fiddle to demonstrate it's not working as well.
CSSMatrix.prototype.perspective = function(d){
return CSSMatrix.multiply(this, CSSMatrix.Perspective(d));
};
CSSMatrix.Perspective = function(d){
var m = new CSSMatrix();
m.m43 = -1/d;
return m;
};
Why the two values are different please?
Thank you for any reply.