The C++ Matrix4x4 Class |
The Matrix4x4 class is used to represent transformations which can be applied to projective space points. A common special case is characterized by the bottom row of the matrix being (0,0,0,1). In this case, the transformation is an affine transformation. Read the description of the Matrix3x3 class. A 4x4 matrix storing an affine transformation is easily constructed by first creating a 3x3 matrix, and then using one of the constructors below to make the 4x4 representation from the 3x3 matrix and additional data.
Matrix3x3 M3x3(a, b, c, d, e, f, g, h, i); Matrix4x4 M4x4(M3x3); |
Matrix4x4 M4x4(a,b,0,c, d,e,0,f, 0,0,1,0, g,h,0,i); |
In the following, assume that instances of Matrix4x4 called M, N, A1, and A2 have been declared and initialized. Similarly, let us assume that P and Q have been defined as instances of class ProjPoint, R and S are instances of class AffPoint, and that u and v have been defined as instances of class AffVector.
ProjPoint X(R); ProjPoint Y = M * X; S = Y.aCoords();
In the following, assume that an instance of Matrix4x4 called M has been declared and initialized.
Matrix4x4 M(...); double m[16]; M.extract(m); glLoadMatrixd(m); | Matrix4x4 M(...); double m[16]; glLoadMatrixd(M.extract(m)); |
The matrix is unchanged if either i or j is outside the range 0..3.
The following constants are Matrix4x4 class variables that can be used in your programs.
See the description of the indicated class methods for instructions and examples on the use of these constants.
cin >> M; cout << "M = " << M << '\n';
Assuming the default conditions specified, if the input is:
13.2 -1.2 -0.334 1.0 1.9 21.5 97 2.1 1.2 18.2 0.32 3.2 1.1 8.7 1.2 0.3
then the output will be:
M = {{ 13.2 -1.2 -0.334 1} { 1.9 21.5 97 2.1} { 1.2 18.2 0.32 3.2} { 1.1 8.7 1.2 0.3}}
The methods inputFormat and outputFormat allow you to change these assumptions for the input and output operators, respectively. The ioFormat method is equivalent to invoking both inputFormat and outputFormat with the given parameters.
The valid values for "ioAspect" are listed in the "public constants" section above. Using these, we can format the preceding more reasonably as:
cin >> M; Matrix4x4::outputFormat(Matrix4x4::elementFieldWidth, 7); Matrix4x4::outputFormat(Matrix4x4::openMatrixDelimiter, "{\n"); Matrix4x4::outputFormat(Matrix4x4::rowSeparator, ",\n"); cout << "M = " << M << '\n';
If the input is the same as indicated above, the output will be:
M = { { 13.2 -1.2 -0.334 1}, { 1.9 21.5 97 2.1}, { 1.2 18.2 0.32 3.2}, { 1.1 8.7 1.2 0.3} }
Any character string can be specified for any of these formatting options (subject to a maximum length). For the "open" strings, a matching closing character string will be generated by matching each input character with an "inverse". If, for example, the string "(*\n" is specified as the openDelimiter, then "\n*)" is generated as the closing delimiter.
The input operator does not actually check for an exact match on delimiters and separators. Instead it knows the number of nonblank characters in each, and it simply skips that many nonblank characters on input.