m4
Index
Type Aliases
Variables
Functions
- addVectors
- axisRotate
- axisRotation
- compose
- copy
- cross
- decompose
- distance
- distanceSq
- dot
- frustum
- identity
- inverse
- length
- lookAt
- multiply
- normalize
- orthographic
- perspective
- scale
- scaling
- subtractVectors
- transformDirection
- transformNormal
- transformPoint
- transformVector
- translate
- translation
- transpose
- xRotate
- xRotation
- yRotate
- yRotation
- zRotate
- zRotation
Type Aliases
Mat4
A [4, 4] matrix represented as a flattened length-16 array
Vec3
A length-3 vector
Vec4
A length-4 vector
Variables
constsetDefaultType
Do not touch
Functions
addVectors
Parameters
vec1: Float32Array
vec2: Float32Array
optionaldst: Float32Array
Returns m4.Vec3
axisRotate
Modifies the given 4-by-4 matrix by rotation around the given axis by the given angle.
Parameters
m: Float32Array
The matrix.
axis: Float32Array
The axis about which to rotate.
angleInRadians: number
The angle by which to rotate (in radians).
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
m once modified.
axisRotation
Creates a 4-by-4 matrix which rotates around the given axis by the given angle.
Parameters
axis: Float32Array
The axis about which to rotate.
angleInRadians: number
The angle by which to rotate (in radians).
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
A matrix which rotates angle radians around the axis.
compose
Parameters
m: Float32Array
a: number
b: number
optionaldst: Float32Array
Returns m4.Mat4
copy
Copies a matrix.
Parameters
m: Float32Array
The matrix.
optionaldst: Float32Array
The matrix.
Returns m4.Mat4
A copy of m.
cross
Computes the cross product of two vectors; assumes both vectors have three entries.
Parameters
a: Float32Array
Operand vector.
b: Float32Array
Operand vector.
optionaldst: Float32Array
vector to hold result. If not new one is created..
Returns m4.Vec3
The vector a cross b.
decompose
Parameters
a: Float32Array
b: Float32Array
c: Float32Array
dst: Float32Array
Returns m4.Mat4
distance
Parameters
vec1: Float32Array
vec2: Float32Array
Returns number
distanceSq
Parameters
vec1: Float32Array
vec2: Float32Array
Returns number
dot
Computes the dot product of two vectors; assumes both vectors have three entries.
Parameters
a: Float32Array
Operand vector.
b: Float32Array
Operand vector.
Returns number
dot product
frustum
Computes a 4-by-4 perspective transformation matrix given the left, right, top, bottom, near and far clipping planes. The arguments define a frustum extending in the negative z direction. The arguments near and far are the distances to the near and far clipping planes. Note that near and far are not z coordinates, but rather they are distances along the negative z-axis. The matrix generated sends the viewing frustum to the unit box. We assume a unit box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z dimension.
Parameters
left: number
The x coordinate of the left plane of the box.
right: number
The x coordinate of the right plane of the box.
bottom: number
The y coordinate of the bottom plane of the box.
top: number
The y coordinate of the right plane of the box.
near: number
The negative z coordinate of the near plane of the box.
far: number
The negative z coordinate of the far plane of the box.
optionaldst: Float32Array
Output matrix.
Returns m4.Mat4
The perspective projection matrix.
identity
Creates an n-by-n identity matrix.
Parameters
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns number
An n-by-n identity matrix.
inverse
Computes the inverse of a 4-by-4 matrix.
Parameters
m: Float32Array
The matrix.
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
The inverse of m.
length
Computes the length of vector
Parameters
v: Float32Array
vector.
Returns number
length of vector.
lookAt
Computes a 4-by-4 look-at transformation.
This is a matrix which positions the camera itself. If you want a view matrix (a matrix which moves things in front of the camera) take the inverse of this.
Parameters
eye: Float32Array
The position of the eye.
target: Float32Array
The position meant to be viewed.
up: Float32Array
A vector pointing up.
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
The look-at matrix.
multiply
Multiplies two 4-by-4 matrices; assumes that the given matrices are 4-by-4; assumes matrix entries are accessed in [row][column] fashion.
Parameters
a: Float32Array
The matrix on the left.
b: Float32Array
The matrix on the right.
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
The matrix product of a and b.
normalize
Divides a vector by its Euclidean length and returns the quotient.
Parameters
a: Float32Array
The vector.
optionaldst: Float32Array
vector to hold result. If not new one is created..
Returns m4.Vec3
The normalized vector.
orthographic
Parameters
left: number
right: number
bottom: number
top: number
near: number
far: number
optionaldst: Float32Array
Returns m4.Mat4
perspective
Computes a 4-by-4 perspective transformation matrix given the angular height of the frustum, the aspect ratio, and the near and far clipping planes. The arguments define a frustum extending in the negative z direction. The given angle is the vertical angle of the frustum, and the horizontal angle is determined to produce the given aspect ratio. The arguments near and far are the distances to the near and far clipping planes. Note that near and far are not z coordinates, but rather they are distances along the negative z-axis. The matrix generated sends the viewing frustum to the unit box. We assume a unit box extending from -1 to 1 in the x and y dimensions and from 0 to 1 in the z dimension.
Parameters
fieldOfViewYInRadians: number
The camera angle from top to bottom (in radians).
aspect: number
The aspect ratio width / height.
zNear: number
The depth (negative z coordinate) of the near clipping plane.
zFar: number
The depth (negative z coordinate) of the far clipping plane.
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
The perspective matrix.
scale
Modifies the given 4-by-4 matrix, scaling in each dimension by an amount given by the corresponding entry in the given vector; assumes the vector has three entries.
Parameters
m: Float32Array
The matrix to be modified.
x: number
X component of the vector by which to scale
y: number
Y component of the vector by which to scale
z: number
Z component of the vector by which to scale
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
m once modified.
scaling
Creates a 4-by-4 matrix which scales in each dimension by an amount given by the corresponding entry in the given vector; assumes the vector has three entries.
Parameters
x: number
X component of the vector by which to scale
y: number
Y component of the vector by which to scale
z: number
Z component of the vector by which to scale
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
The scaling matrix.
subtractVectors
Parameters
vec1: Float32Array
vec2: Float32Array
optionaldst: Float32Array
Returns m4.Vec3
transformDirection
Takes a 4-by-4 matrix and a vector with 3 entries, interprets the vector as a direction, transforms that direction by the matrix, and returns the result; assumes the transformation of 3-dimensional space represented by the matrix is parallel-preserving, i.e. any combination of rotation, scaling and translation, but not a perspective distortion. Returns a vector with 3 entries.
Parameters
m: Float32Array
The matrix.
v: Float32Array
The direction.
optionaldst: Float32Array
optional Vec3 to store result
Returns m4.Vec3
dst or new Vec3 if not provided
transformNormal
Takes a 4-by-4 matrix m and a vector v with 3 entries, interprets the vector as a normal to a surface, and computes a vector which is normal upon transforming that surface by the matrix. The effect of this function is the same as transforming v (as a direction) by the inverse-transpose of m. This function assumes the transformation of 3-dimensional space represented by the matrix is parallel-preserving, i.e. any combination of rotation, scaling and translation, but not a perspective distortion. Returns a vector with 3 entries.
Parameters
m: Float32Array
The matrix.
v: Float32Array
The normal.
optionaldst: Float32Array
The direction.
Returns m4.Vec3
The transformed direction.
transformPoint
Takes a 4-by-4 matrix and a vector with 3 entries, interprets the vector as a point, transforms that point by the matrix, and returns the result as a vector with 3 entries.
Parameters
m: Float32Array
The matrix.
v: Float32Array
The point.
optionaldst: Float32Array
optional vec3 to store result
Returns m4.Vec3
dst or new vec3 if not provided
transformVector
Parameters
a: Float32Array
b: Float32Array
optionaldst: Float32Array
Returns m4.Vec4
translate
Modifies the given 4-by-4 matrix by translation by the given vector v.
Parameters
m: Float32Array
The matrix.
x: number
X component of the vector by which to translate
y: number
Y component of the vector by which to translate
z: number
Z component of the vector by which to translate
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
m once modified.
translation
Creates a 4-by-4 matrix which translates by the given vector v.
Parameters
x: number
X component of the vector by which to translate
y: number
Y component of the vector by which to translate
z: number
Z component of the vector by which to translate
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
The translation matrix.
transpose
Takes the transpose of a matrix.
Parameters
m: Float32Array
The matrix.
optionaldst: Float32Array
matrix to hold result. If none new one is created..
Returns m4.Mat4
The transpose of m.
xRotate
Parameters
m: Float32Array
angleInRadians: number
optionaldst: Float32Array
Returns m4.Mat4
xRotation
Parameters
angleInRadians: number
optionaldst: Float32Array
Returns m4.Mat4
yRotate
Parameters
m: Float32Array
angleInRadians: number
optionaldst: Float32Array
Returns m4.Mat4
yRotation
Parameters
angleInRadians: number
optionaldst: Float32Array
Returns m4.Mat4
zRotate
Parameters
m: Float32Array
angleInRadians: number
optionaldst: Float32Array
Returns m4.Mat4
zRotation
Parameters
angleInRadians: number
optionaldst: Float32Array
Returns m4.Mat4
Copyright 2014, Gregg Tavares. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Gregg Tavares. nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.