Next: Quaternions, Previous: Rectangles, Up: Math [Contents][Index]
The (chickadee math matrix)
module provides an interface for
working with the most common type of matrices in game development: 4x4
transformation matrices.
Another Note About Performance
Much like the vector API, the matrix API is commonly used in performance critical code paths. In order to reduce the amount of garbage generated and improve matrix multiplication performance, there are many procedures that perform in-place modifications of matrix objects.
Return a new 3x3 initialized with the given 9 values in column-major format.
Return a new 3x3 matrix with all values initialized to 0.
Return a new 3x3 identity matrix. Any matrix multiplied by the identity matrix yields the original matrix. This procedure is equivalent to the following code:
(make-matrix3 1 0 0 0 1 0 0 0 1)
Return #t
if obj is a 3x3 matrix.
Return #t
if m1 is the same matrix as m2.
Return a new 3x3 matrix that is a copy of matrix.
Return a new 3x3 matrix containing the product of multiplying all of the given matrices.
Note: Remember that matrix multiplication is not commutative!
Return a new 3x3 matrix that represents a translation by v, a 2D vector.
Return a new 3x3 matrix that represents a scaling along the x and y axes by the scaling factor s, a number or 2D vector.
Return a new 3x3 matrix that represents a rotation by angle radians.
Return a new 2D vector that is v as transformed by the 3x3 matrix matrix.
Return the inverse of matrix.
The following procedures perform in-place, destructive updates to 3x3 matrix objects:
Copy the contents of matrix src to dest.
Modify matrix in-place to contain the identity matrix.
Multiply the 3x3 matrix a by the 3x3 matrix b and store the result in the 3x3 matrix dest.
Modify matrix in-place to contain a translation by v, a 2D vector.
Modify matrix in-place to contain a scaling along the x and y axes by the scaling factor s, a number or 2D vector.
Modify matrix in-place to contain a rotation by angle radians.
Modify the 2D vector v in-place to contain v as transformed by the 3x3 matrix matrix.
Compute the inverse of matrix and store the results in target.
Return a new 4x4 matrix initialized with the given 16 values in column-major format.
Return a new 4x4 matrix with all values initialized to 0.
Return a new 4x4 identity matrix. Any matrix multiplied by the identity matrix yields the original matrix. This procedure is equivalent to the following code:
(make-matrix4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1)
Return #t
if obj is a 4x4 matrix.
Return #t
if m1 is the same matrix as m2.
Return a new 4x4 matrix that is a copy of matrix.
Return a new 4x4 matrix containing the product of multiplying all of the given matrices.
Note: Remember that matrix multiplication is not commutative!
Return the inverse of matrix.
A matrix multiplied by its inverse is the identity matrix, thought not always exactly due to the nature of floating point numbers.
Return a new 4x4 matrix that represents an orthographic (2D) projection for the horizontal clipping plane top and bottom, the vertical clipping plane top and bottom, and the depth clipping plane near and far.
Return a new 4x4 matrix that represents a perspective (3D) projection with a field of vision of fov radians, an aspect ratio of aspect-ratio, and a depth clipping plane defined by near and far.
Return a new 4x4 matrix that represents a translation by x, a 2D vector, a 3D vector, or a rectangle (in which case the bottom-left corner of the rectangle is used).
Return a new 4x4 matrix that represents a scaling along the X, Y, and Z axes by the scaling factor s, a real number.
Return a new 4x4 matrix that represents a rotation about an arbitrary axis defined by the quaternion q.
Return a new 4x4 matrix that represents a rotation about the Z axis by theta radians.
The following procedures perform in-place, destructive updates to 4x4 matrix objects:
Copy the contents of matrix src to dest.
Modify matrix in-place to contain the identity matrix.
Multiply the 4x4 matrix a by the 4x4 matrix b and store the result in the 4x4 matrix dest.
Compute the inverse of matrix and store the result in target.
Modify matrix in-place to contain a translation by x, a 2D vector, a 3D vector, or a rectangle (in which case the bottom-left corner of the rectangle is used).
Modify matrix in-place to contain a scaling along the X, Y, and Z axes by the scaling factor s, a real number.
Modify matrix in-place to contain a rotation about an arbitrary axis defined by the quaternion q.
Modify matrix in-place to contain a rotation about the Z axis by theta radians.
Modify matrix in-place to contain the transformation described by position, a 2D vector or rectangle, rotation, a scalar representing a rotation about the Z axis, scale, a 2D vector, and shear, a 2D vector. The transformation happens with respect to origin, a 2D vector. If an argument is not provided, that particular transformation will not be included in the result.
Modify the 2D vector v in-place by multiplying it by the 4x4 matrix matrix.
Next: Quaternions, Previous: Rectangles, Up: Math [Contents][Index]