Game Development Reference
In-Depth Information
Matrices
Matrices are primarily used to describe the relationship between two coordinate
spaces in 3D mathematics. They do this by defining a computation to transform
vectors from one coordinate space to another, for example, object space to world
space or world space to view/camera space.
Some useful matrix operations are:
var mat=mat3.create() //Creates a new identity mat3
var out=mat3.create() //Creates a new identity mat3
mat3.identity(out) //Set a mat3 to the identity matrix
var result=mat3.determinant(mat) //Calculates the determinant of a
mat3
mat3.invert(out, mat) //Inverts a mat3
mat3.transpose(out, mat) //Transpose the values of a mat3
Understanding transformations
You will encounter the word "transformation" in all computer graphics topics. This
word is mostly used to denote change in the object's state. We can apply scaling,
rotation, sheer, or translation transformations to change the state of an object. We
can apply a combination of the preceding transformations to change the state of the
object. The combinations are generally classified as linear or affine transformations.
Classifying into linear and affine transformations
Linear transformations are the most-used transformations in 3D games. Linear
transformations such as scaling, rotation, and sheer will be used throughout your
game development career. These transformations are transformations that preserve
state, if applied in any order. So, if we scale an object and then rotate it, or first rotate
it and then scale it, the end result would be the same. So, transformation is linear, if it
preserves the basic operations of addition and multiplication by a scalar.
Some useful functions for linear transformation are:
var a=mat3.create();
var out=mat3.create();
var rad=1.4; //in Radians
var v=vec2.fromValues(2,2);
mat3.rotate(out, a, rad); //Rotates "a" mat3 by the given angle
and puts data in out.
mat3.scale(out, a, v) //Scales the mat3 by the dimensions in the
given vec2
 
Search WWH ::




Custom Search