Game Development Reference
In-Depth Information
_m42 = m._m42;
_m43 = m._m43;
}
public Matrix(Vector x, Vector y, Vector z, Vector o)
{
_m11 = x.X; _m12 = x.Y; _m13 = x.Z;
_m21 = y.X; _m22 = y.Y; _m23 = y.Z;
_m31 = z.X; _m32 = z.Y; _m33 = z.Z;
_m41 = o.X; _m42 = o.Y; _m43 = o.Z;
}
This code adds a constant identity matrix and a number of constructors.
The default constructor initializes the members to the identity matrix by passing
the identity matrix to a copy constructor. The second constructor is the copy
constructor. A copy constructor is a constructor that is called with one parameter,
which is the same type as the object being constructed. The copy constructor co-
pies all its member data so that the created object is exactly the same. The final
constructor takes in a vector for each axis and one vector for the origin.
Matrix-Matrix and Vector-Matrix Multiplication
The most important methods of the Matrix class are its multiplication meth-
ods; these are used to combine matrices and transform on vertex positions.
Matrix multiplication can only be performed if the width of the first matrix
equals the height of the second. Matrix-matrix and vector-matrix multiplication
is performed using the same algorithm.
Here is the definition.
C i ; k ΒΌ A i ; j B j ; k
C is the result from the multiplication, i is the length of the rows in matrix A ,
and k is the length of the columns in matrix B . The j is the number of possible
summations of i and k . In matrix multiplication, different-shaped matrices can
result from the original shapes of the matrices that are multiplied. Again, don't
worry if the math all seems a little intimidating; knowing how and when to use a
matrix is the most important lesson to take away.
The width of our matrix equals its height if we remember to include the final
column of [0, 0, 0, 1]. Therefore, using the multiplication definition, the code for
the matrix-matrix multiplication is as follows:
 
Search WWH ::




Custom Search