A mat4 represents a 4x4 matrix which can be used to store transformations. You can construct a mat4 in several ways:
# all components are set to zero
M = mat4()
[ 0.0000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 0.0000]
# identity matrix
M = mat4(1.0)
[ 1.0000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 1.0000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 1.0000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 1.0000]
# The elements on the diagonal are set to 2.5
M = mat4(2.5)
[ 2.5000, 0.0000, 0.0000, 0.0000]
[ 0.0000, 2.5000, 0.0000, 0.0000]
[ 0.0000, 0.0000, 2.5000, 0.0000]
[ 0.0000, 0.0000, 0.0000, 2.5000]
# All elements are explicitly set (values must be given in row-major order)
M = mat4(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p)
M = mat4([a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p])
[ a, b, c, d ]
[ e, f, g, h ]
[ i, j, k, l ]
[ m, n, o, p ]
# Create a copy of matrix N (which also has to be a mat4)
M = mat4(N)
# Specify the 4 columns of the matrix (as vec4's or sequences with 4 elements)
M = mat4(a,b,c,d)
[ a[0], b[0], c[0], d[0] ]
[ a[1], b[1], c[1], d[1] ]
[ a[2], b[2], c[2], d[2] ]
[ a[3], b[3], c[3], d[3] ]
# All elements are explicitly set and are stored inside a string
M = mat4("1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16")
[ 1.0000, 2.0000, 3.0000, 4.0000]
[ 5.0000, 6.0000, 7.0000, 8.0000]
[ 9.0000, 10.0000, 11.0000, 12.0000]
[ 13.0000, 14.0000, 15.0000, 16.0000]
Mathematical operations
The mathematical operators are supported with the following combination of types:
mat4 = mat4 + mat4 mat4 = mat4 - mat4 mat4 = mat4 * mat4 vec4 = mat4 * vec4 vec4 = vec4 * mat4 vec3 = mat4 * vec3 # missing coordinate in vec3 is implicitly set to 1.0 vec3 = vec3 * mat4 # missing coordinate in vec3 is implicitly set to 1.0 mat4 = float * mat4 mat4 = mat4 * float mat4 = mat4 / float mat4 = mat4 % float # each component mat4 = -mat4 vec4 = mat4[i] # get or set column i (as vec4) float = mat4[i,j] # get or set element in row i and column j
Additionally, you can compare matrices with == and !=.
Methods
| index) |
| index, value) |
| index) |
| index, value) |
| ) |
| value) |
| rowmajor=False) |
True, you will get the list in row-major order.
| ) |
| ) |
| ) |
| ) |
| t) |
This is a static method.
| s) |
This is a static method.
| angle, axis) |
| t) |
| s) |
| angle, axis) |
| left, right, bottom, top, near, far) |
Note: If you want to use this transformation in RenderMan, keep in mind that the RenderMan camera is looking in the positive z direction whereas the OpenGL camera is looking in the negative direction.
| fovy, aspect, near, far) |
| left, right, bottom, top, near, far) |
| pos, target, up=(0,0,1)) |
You can use this transformation to position objects in the scene that have to be oriented towards a particular point. Or you can use it to position the camera in the virtual world. In this case you have to take the inverse of this transformation as viewport transformation (to convert world space coordinates into camera space coordinates).
This is a static method.
| ) |
| ) |
| ) |
| m3) |