Re: Matrix4x4 proposal

On 14/01/2012, at 2:49 AM, Johannes Behr wrote:

> Before going into more details: Was there a good reason for just a single matrix interface and not a minimalistic but useful set of base types (e.g. Vec3, Vec4, Matrix4x4 or even Quaternion) which would be really helpful for various math related operations (e.g composition/decomposition)? We (especially Timm) thought about something similar for the dec3d group: http://www.w3.org/community/declarative3d/wiki/Base_Types

I considered this. My main concern is fear of polluting the global JS namespace with generic classes that might be better developed by the official ECMAScript committee. Adding interfaces to the DOM when they are clearly related to the Web and Web documents is ok, but I think we need to show caution adding 6 interfaces that have broader use. I believe this is why the WebGL group discussed the *Array classes with ECMA.

I would prefer to have the base types as you suggest, but I'm not sure how to proceed. Maybe I'm being overly cautious.

Dean


> 
> best regards
> johannes
> 
>> [Apologies if this mail comes out badly formatted - I'm using a crappy web mail app]
>> 
>> This is picking up from Igor's proposal [1] and completes my action (given at the W3C TP) to propose a more "native" matrix class.
>> 
>> Open questions:
>> 
>> - should include ortho() and perspective() functions? (suggestion: YES)
>> - should include a matrix decomposition method? (suggestion: YES)
>> - should include a lookAt() method? (suggestion: PROBABLY, requires vectors or multiple parameters)
>> - ok to remove skew? (suggestion: I HOPE SO)
>> 
>> 
>> // -----------------------------------------------------------------------
>> // CONSTRUCTORS
>> // -----------------------------------------------------------------------
>> 
>> [
>>    // Creates an identity matrix
>>    Constructor(),
>> 
>>    // Creates a new matrix from the value passed in (which is CSS transform string with
>>    // matrix() or matrix3d() - not other functions).
>>    Constructor(in DOMString string),
>> 
>>    // Creates a new matrix from the Float32Array value passed in (length of 6 for a 2d matrix, or 16 for a 4x4 matrix).
>>    Constructor(in Float32array array),
>> 
>>    // Creates a new matrix identical to the passed matrix.
>>    Constructor(in Matrix4x4 matrix),
>> 
>>    // Creates a new matrix from the array of 6 or 16 values passed in
>>    Constructor(in sequence<float> array)
>> ]
>> 
>> interface Matrix4x4 {
>> 
>>    // These attributes are simple aliases for certain elements of the 4x4 matrix
>>    attribute double a; // alias for m11
>>    attribute double b; // alias for m12
>>    attribute double c; // alias for m21
>>    attribute double d; // alias for m22
>>    attribute double e; // alias for m41
>>    attribute double f; // alias for m42
>> 
>>    attribute double m11;
>>    attribute double m12;
>>    attribute double m13;
>>    attribute double m14;
>>    attribute double m21;
>>    attribute double m22;
>>    attribute double m23;
>>    attribute double m24;
>>    attribute double m31;
>>    attribute double m32;
>>    attribute double m33;
>>    attribute double m34;
>>    attribute double m41;
>>    attribute double m42;
>>    attribute double m43;
>>    attribute double m44;
>> 
>>    // -----------------------------------------------------------------------
>>    // TRANSFORMATION FUNCTIONS
>>    // -----------------------------------------------------------------------
>> 
>>    // Multiply itself by a otherMatrix, on the right (this = this * otherMatrix)
>>    void multiply(in Matrix4x4 otherMatrix);
>> 
>>    // Multiply this matrix by otherMatrix, on the right (result = this * otherMatrix)
>>    [Immutable] Matrix4x4 multipliedBy(in Matrix4x4 otherMatrix);
>> 
>>    // Multiply itself by a otherMatrix, on the left (this = otherMatrix * this)
>>    void leftMultiply(in Matrix4x4 otherMatrix);
>> 
>>    // Invert this matrix. Throw an exception if the matrix is not invertible
>>    void invert() raises (DOMException)
>> 
>>    // Return the inverse of this matrix. Throw an exception if the matrix is not invertible
>>    [Immutable] Matrix4x4 inverseMatrix() raises (DOMException);
>> 
>>    // Translate this matrix in place using the passed values.
>>    // Undefined or NaN parameters will use a value of 0. This allows the 3D form to used for 2D operations.
>>    void translate(in double x,
>>                   in double y,
>>                   in double z);
>> 
>>    // Return a new matrix that is this matrix translated by the passed values.
>>    // Undefined or NaN parameters will use a value of 0. This allows the 3D form to used for 2D operations
>>    [Immutable] Matrix4x4 translatedBy(in double x,
>>                                       in double y,
>>                                       in double z);
>> 
>>    // Scale this matrix in place using the passed values.
>>    // Passing undefined or NaN for scaleY uses the value of scaleX.
>>    // Passing undefined or NaN for scaleZ uses the value 1.0.
>>    void scale(in double scaleX,
>>               in double scaleY,
>>               in double scaleZ);
>> 
>>    // Return a new matrix that is this matrix scaled by the passed values.
>>    // Passing undefined or NaN for scaleY uses the value of scaleX.
>>    // Passing undefined or NaN for scaleZ uses the value 1.0.
>>    [Immutable] Matrix4x4 scaledBy(in double scaleX,
>>                                   in double scaleY,
>>                                   in double scaleZ);
>> 
>>    // Rotate this matrix in place using the passed values. Each parameter defines
>>    // an angle of rotation around the (corresponding) X, Y or Z axes.
>>    // Passing undefined or NaN for rotY and rotZ instead rotates around the Z axis
>>    // (i.e. rotX = 0, rotY = 0, rotZ = <input rotX>)
>>    // Input values are in radians.
>>    void rotate(in double rotX,
>>                in double rotY,
>>                in double rotZ);
>> 
>>    // Return a new matrix that is this matrix rotated by the passed values. Each parameter
>>    // defines an angle of rotation around the (corresponding) X, Y or Z axes.
>>    // Passing undefined or NaN for rotY and rotZ instead rotates around the Z axis
>>    // (i.e. rotX = 0, rotY = 0, rotZ = <input rotX>)
>>    // Input values are in radians.
>>    [Immutable] Matrix4x4 rotatedBy(in double rotX,
>>                                    in double rotY,
>>                                    in double rotZ);
>> 
>>    // Rotate this matrix in place using the passed values. The x, y and z values
>>    // define a vector about which the matrix is rotated.
>>    // The value of angle is in radians.
>>    void rotateAxisAngle(in double x,
>>                         in double y,
>>                         in double z,
>>                         in double angle);
>> 
>>    // Return a new matrix that is this matrix rotated using the passed values. The x, y and z values
>>    // define a vector about which the matrix is rotated.
>>    // The value of angle is in radians.
>>    [Immutable] Matrix4x4 rotatedByAxisAngle(in double x,
>>                                             in double y,
>>                                             in double z,
>>                                             in double angle);
>> 
>>    // -----------------------------------------------------------------------
>>    // CONVERSION FUNCTIONS
>>    // -----------------------------------------------------------------------
>> 
>>    // Copy the matrix elements into a Float32Array
>>    // Throws an exception if the input is invalid (e.g. wrong length, etc).
>>    void copyIntoFloat32Array(inout Float32Array array) raises (DOMException);
>> 
>>    // return a Float32Array (length 16) with the values [m11, m12, ...]
>>    Float32Array toFloat32Array();
>> 
>>    // Returns a string that is in the format of a CSS transform.
>>    // (e.g. "matrix3d(m11, m12, ...)")
>>    DOMString toString();
>> };
>> 
>> 
>> 
>> 
>> [1] http://lists.w3.org/Archives/Public/public-webapps/2011OctDec/0376.html
> 
> --
> Dr. Johannes Behr
> Abteilungsleiter Visual Computing System Technologies
> Fraunhofer-Institut für Graphische Datenverarbeitung IGD
> Fraunhoferstr. 5  |  64283 Darmstadt  |  Germany
> Tel +49 6151 155-510  |  Fax +49 6151 155-196
> johannes.behr@igd.fraunhofer.de  |  www.igd.fraunhofer.de
> 

Received on Monday, 16 January 2012 22:26:07 UTC