Game Development Reference
In-Depth Information
let's add another matrix that will scale it. The scale matrix will be combined with
the rotation matrix by multiplying them. Modify the existing code in the con-
structor so it looks like the code here:
Matrix m = new Matrix();
m.SetRotate(new Vector(0, 0, 1),Math.PI/5);
Matrix mScale = new Matrix();
mScale.SetScale(new Vector(2.0, 2.0, 0.0));
m *= mScale;
for (int i = 0; i < _faceSprite.VertexPositions.Length; i++ )
{
_faceSprite.VertexPositions[i] *= m;
}
This code creates a scale matrix that scales the X and Y axis by 2. This is com-
bined with the rotation matrix by multiplying them together and assigning the
result to the matrix m . This new combined m matrix is then applied to the face
sprite, scaling and rotating it. The order of matrix multiplication is important;
multiplying matrix a by matrix b is not guaranteed to have the same result as
matrix b by matrix a . Play around with different matrices to get a good idea of
how they work together.
The final code snippet will demonstrate the inverse matrix. The inverse matrix
reverses a matrix operation. If rotate-scale matrix was multiplied by its inverse
matrix, then the result would be the identity matrix. The identity matrix will not
have any effect on the sprite when it is applied to it.
Matrix m = new Matrix();
m.SetRotate(new Vector(0, 0, 1),Math.PI/5);
Matrix mScale = new Matrix();
mScale.SetScale(new Vector(2.0, 2.0, 2.0));
m *= mScale;
Vector scale = m.GetScale();
m *= m.Inverse();
for (int i = 0; i < _faceSprite.VertexPositions.Length; i++ )
Search WWH ::




Custom Search