Matrix
open class Matrix
kotlin.Any | |
↳ | android.opengl.Matrix |
Matrix math utilities. These methods operate on OpenGL ES format matrices and vectors stored in float arrays.
Matrices are 4 x 4 column-vector matrices stored in column-major order:
m[offset + 0] m[offset + 4] m[offset + 8] m[offset + 12] m[offset + 1] m[offset + 5] m[offset + 9] m[offset + 13] m[offset + 2] m[offset + 6] m[offset + 10] m[offset + 14] m[offset + 3] m[offset + 7] m[offset + 11] m[offset + 15]Vectors are 4 x 1 column vectors stored in order:
v[offset + 0] v[offset + 1] v[offset + 2] v[offset + 3]
Summary
Public constructors | |
---|---|
Matrix() |
Public methods | |
---|---|
open static Unit |
frustumM(m: FloatArray!, offset: Int, left: Float, right: Float, bottom: Float, top: Float, near: Float, far: Float) Defines a projection matrix in terms of six clip planes. |
open static Boolean |
invertM(mInv: FloatArray!, mInvOffset: Int, m: FloatArray!, mOffset: Int) Inverts a 4 x 4 matrix. |
open static Float |
Computes the length of a vector. |
open static Unit |
multiplyMM(result: FloatArray!, resultOffset: Int, lhs: FloatArray!, lhsOffset: Int, rhs: FloatArray!, rhsOffset: Int) Multiplies two 4x4 matrices together and stores the result in a third 4x4 matrix. |
open static Unit |
multiplyMV(resultVec: FloatArray!, resultVecOffset: Int, lhsMat: FloatArray!, lhsMatOffset: Int, rhsVec: FloatArray!, rhsVecOffset: Int) Multiplies a 4 element vector by a 4x4 matrix and stores the result in a 4-element column vector. |
open static Unit |
orthoM(m: FloatArray!, mOffset: Int, left: Float, right: Float, bottom: Float, top: Float, near: Float, far: Float) Computes an orthographic projection matrix. |
open static Unit |
perspectiveM(m: FloatArray!, offset: Int, fovy: Float, aspect: Float, zNear: Float, zFar: Float) Defines a projection matrix in terms of a field of view angle, an aspect ratio, and z clip planes. |
open static Unit |
rotateM(rm: FloatArray!, rmOffset: Int, m: FloatArray!, mOffset: Int, a: Float, x: Float, y: Float, z: Float) Rotates matrix m by angle a (in degrees) around the axis (x, y, z). |
open static Unit |
Rotates matrix m in place by angle a (in degrees) around the axis (x, y, z). |
open static Unit |
scaleM(sm: FloatArray!, smOffset: Int, m: FloatArray!, mOffset: Int, x: Float, y: Float, z: Float) Scales matrix m by x, y, and z, putting the result in sm. |
open static Unit |
Scales matrix m in place by sx, sy, and sz. |
open static Unit |
setIdentityM(sm: FloatArray!, smOffset: Int) Sets matrix m to the identity matrix. |
open static Unit |
setLookAtM(rm: FloatArray!, rmOffset: Int, eyeX: Float, eyeY: Float, eyeZ: Float, centerX: Float, centerY: Float, centerZ: Float, upX: Float, upY: Float, upZ: Float) Defines a viewing transformation in terms of an eye point, a center of view, and an up vector. |
open static Unit |
setRotateEulerM(rm: FloatArray!, rmOffset: Int, x: Float, y: Float, z: Float) Converts Euler angles to a rotation matrix. |
open static Unit |
setRotateEulerM2(rm: FloatArray, rmOffset: Int, x: Float, y: Float, z: Float) Converts Euler angles to a rotation matrix. |
open static Unit |
setRotateM(rm: FloatArray!, rmOffset: Int, a: Float, x: Float, y: Float, z: Float) Creates a matrix for rotation by angle a (in degrees) around the axis (x, y, z). |
open static Unit |
translateM(tm: FloatArray!, tmOffset: Int, m: FloatArray!, mOffset: Int, x: Float, y: Float, z: Float) Translates matrix m by x, y, and z, putting the result in tm. |
open static Unit |
translateM(m: FloatArray!, mOffset: Int, x: Float, y: Float, z: Float) Translates matrix m by x, y, and z in place. |
open static Unit |
transposeM(mTrans: FloatArray!, mTransOffset: Int, m: FloatArray!, mOffset: Int) Transposes a 4 x 4 matrix. |
Public constructors
Matrix
Matrix()
Deprecated: All methods are static, do not instantiate this class.
Public methods
frustumM
open static fun frustumM(
m: FloatArray!,
offset: Int,
left: Float,
right: Float,
bottom: Float,
top: Float,
near: Float,
far: Float
): Unit
Defines a projection matrix in terms of six clip planes.
Parameters | |
---|---|
m |
FloatArray!: the float array that holds the output perspective matrix |
offset |
Int: the offset into float array m where the perspective matrix data is written |
left |
Float: |
right |
Float: |
bottom |
Float: |
top |
Float: |
near |
Float: |
far |
Float: |
invertM
open static fun invertM(
mInv: FloatArray!,
mInvOffset: Int,
m: FloatArray!,
mOffset: Int
): Boolean
Inverts a 4 x 4 matrix.
mInv and m must not overlap.
Parameters | |
---|---|
mInv |
FloatArray!: the array that holds the output inverted matrix |
mInvOffset |
Int: an offset into mInv where the inverted matrix is stored. |
m |
FloatArray!: the input array |
mOffset |
Int: an offset into m where the input matrix is stored. |
Return | |
---|---|
Boolean |
true if the matrix could be inverted, false if it could not. |
length
open static fun length(
x: Float,
y: Float,
z: Float
): Float
Computes the length of a vector.
Parameters | |
---|---|
x |
Float: x coordinate of a vector |
y |
Float: y coordinate of a vector |
z |
Float: z coordinate of a vector |
Return | |
---|---|
Float |
the length of a vector |
multiplyMM
open static fun multiplyMM(
result: FloatArray!,
resultOffset: Int,
lhs: FloatArray!,
lhsOffset: Int,
rhs: FloatArray!,
rhsOffset: Int
): Unit
Multiplies two 4x4 matrices together and stores the result in a third 4x4 matrix. In matrix notation: result = lhs x rhs. Due to the way matrix multiplication works, the result matrix will have the same effect as first multiplying by the rhs matrix, then multiplying by the lhs matrix. This is the opposite of what you might expect.
The same float array may be passed for result, lhs, and/or rhs. This operation is expected to do the correct thing if the result elements overlap with either of the lhs or rhs elements.
Parameters | |
---|---|
result |
FloatArray!: The float array that holds the result. |
resultOffset |
Int: The offset into the result array where the result is stored. |
lhs |
FloatArray!: The float array that holds the left-hand-side matrix. |
lhsOffset |
Int: The offset into the lhs array where the lhs is stored |
rhs |
FloatArray!: The float array that holds the right-hand-side matrix. |
rhsOffset |
Int: The offset into the rhs array where the rhs is stored. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
under any of the following conditions: result, lhs, or rhs are null; resultOffset + 16 > result.length or lhsOffset + 16 > lhs.length or rhsOffset + 16 > rhs.length; resultOffset < 0 or lhsOffset < 0 or rhsOffset < 0 |
multiplyMV
open static fun multiplyMV(
resultVec: FloatArray!,
resultVecOffset: Int,
lhsMat: FloatArray!,
lhsMatOffset: Int,
rhsVec: FloatArray!,
rhsVecOffset: Int
): Unit
Multiplies a 4 element vector by a 4x4 matrix and stores the result in a 4-element column vector. In matrix notation: result = lhs x rhs
The same float array may be passed for resultVec, lhsMat, and/or rhsVec. This operation is expected to do the correct thing if the result elements overlap with either of the lhs or rhs elements.
Parameters | |
---|---|
resultVec |
FloatArray!: The float array that holds the result vector. |
resultVecOffset |
Int: The offset into the result array where the result vector is stored. |
lhsMat |
FloatArray!: The float array that holds the left-hand-side matrix. |
lhsMatOffset |
Int: The offset into the lhs array where the lhs is stored |
rhsVec |
FloatArray!: The float array that holds the right-hand-side vector. |
rhsVecOffset |
Int: The offset into the rhs vector where the rhs vector is stored. |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
under any of the following conditions: resultVec, lhsMat, or rhsVec are null; resultVecOffset + 4 > resultVec.length or lhsMatOffset + 16 > lhsMat.length or rhsVecOffset + 4 > rhsVec.length; resultVecOffset < 0 or lhsMatOffset < 0 or rhsVecOffset < 0 |
orthoM
open static fun orthoM(
m: FloatArray!,
mOffset: Int,
left: Float,
right: Float,
bottom: Float,
top: Float,
near: Float,
far: Float
): Unit
Computes an orthographic projection matrix.
Parameters | |
---|---|
m |
FloatArray!: returns the result |
mOffset |
Int: |
left |
Float: |
right |
Float: |
bottom |
Float: |
top |
Float: |
near |
Float: |
far |
Float: |
perspectiveM
open static fun perspectiveM(
m: FloatArray!,
offset: Int,
fovy: Float,
aspect: Float,
zNear: Float,
zFar: Float
): Unit
Defines a projection matrix in terms of a field of view angle, an aspect ratio, and z clip planes.
Parameters | |
---|---|
m |
FloatArray!: the float array that holds the perspective matrix |
offset |
Int: the offset into float array m where the perspective matrix data is written |
fovy |
Float: field of view in y direction, in degrees |
aspect |
Float: width to height aspect ratio of the viewport |
zNear |
Float: |
zFar |
Float: |
rotateM
open static fun rotateM(
rm: FloatArray!,
rmOffset: Int,
m: FloatArray!,
mOffset: Int,
a: Float,
x: Float,
y: Float,
z: Float
): Unit
Rotates matrix m by angle a (in degrees) around the axis (x, y, z).
m and rm must not overlap.
Parameters | |
---|---|
rm |
FloatArray!: returns the result |
rmOffset |
Int: index into rm where the result matrix starts |
m |
FloatArray!: source matrix |
mOffset |
Int: index into m where the source matrix starts |
a |
Float: angle to rotate in degrees |
x |
Float: X axis component |
y |
Float: Y axis component |
z |
Float: Z axis component |
rotateM
open static fun rotateM(
m: FloatArray!,
mOffset: Int,
a: Float,
x: Float,
y: Float,
z: Float
): Unit
Rotates matrix m in place by angle a (in degrees) around the axis (x, y, z).
Parameters | |
---|---|
m |
FloatArray!: source matrix |
mOffset |
Int: index into m where the matrix starts |
a |
Float: angle to rotate in degrees |
x |
Float: X axis component |
y |
Float: Y axis component |
z |
Float: Z axis component |
scaleM
open static fun scaleM(
sm: FloatArray!,
smOffset: Int,
m: FloatArray!,
mOffset: Int,
x: Float,
y: Float,
z: Float
): Unit
Scales matrix m by x, y, and z, putting the result in sm.
m and sm must not overlap.
Parameters | |
---|---|
sm |
FloatArray!: returns the result |
smOffset |
Int: index into sm where the result matrix starts |
m |
FloatArray!: source matrix |
mOffset |
Int: index into m where the source matrix starts |
x |
Float: scale factor x |
y |
Float: scale factor y |
z |
Float: scale factor z |
scaleM
open static fun scaleM(
m: FloatArray!,
mOffset: Int,
x: Float,
y: Float,
z: Float
): Unit
Scales matrix m in place by sx, sy, and sz.
Parameters | |
---|---|
m |
FloatArray!: matrix to scale |
mOffset |
Int: index into m where the matrix starts |
x |
Float: scale factor x |
y |
Float: scale factor y |
z |
Float: scale factor z |
setIdentityM
open static fun setIdentityM(
sm: FloatArray!,
smOffset: Int
): Unit
Sets matrix m to the identity matrix.
Parameters | |
---|---|
sm |
FloatArray!: returns the result |
smOffset |
Int: index into sm where the result matrix starts |
setLookAtM
open static fun setLookAtM(
rm: FloatArray!,
rmOffset: Int,
eyeX: Float,
eyeY: Float,
eyeZ: Float,
centerX: Float,
centerY: Float,
centerZ: Float,
upX: Float,
upY: Float,
upZ: Float
): Unit
Defines a viewing transformation in terms of an eye point, a center of view, and an up vector.
Parameters | |
---|---|
rm |
FloatArray!: returns the result |
rmOffset |
Int: index into rm where the result matrix starts |
eyeX |
Float: eye point X |
eyeY |
Float: eye point Y |
eyeZ |
Float: eye point Z |
centerX |
Float: center of view X |
centerY |
Float: center of view Y |
centerZ |
Float: center of view Z |
upX |
Float: up vector X |
upY |
Float: up vector Y |
upZ |
Float: up vector Z |
setRotateEulerM
open static funsetRotateEulerM(
rm: FloatArray!,
rmOffset: Int,
x: Float,
y: Float,
z: Float
): Unit
Deprecated: This method is incorrect around the y axis. This method is deprecated and replaced (below) by setRotateEulerM2 which behaves correctly
Converts Euler angles to a rotation matrix.
Parameters | |
---|---|
rm |
FloatArray!: returns the result |
rmOffset |
Int: index into rm where the result matrix starts |
x |
Float: angle of rotation, in degrees |
y |
Float: is broken, do not use |
z |
Float: angle of rotation, in degrees |
setRotateEulerM2
open static fun setRotateEulerM2(
rm: FloatArray,
rmOffset: Int,
x: Float,
y: Float,
z: Float
): Unit
Converts Euler angles to a rotation matrix.
Parameters | |
---|---|
rm |
FloatArray: returns the result |
rmOffset |
Int: index into rm where the result matrix starts |
x |
Float: angle of rotation, in degrees |
y |
Float: angle of rotation, in degrees |
z |
Float: angle of rotation, in degrees |
Exceptions | |
---|---|
java.lang.IllegalArgumentException |
if rm is null; or if rmOffset + 16 > rm.length; rmOffset < 0 |
setRotateM
open static fun setRotateM(
rm: FloatArray!,
rmOffset: Int,
a: Float,
x: Float,
y: Float,
z: Float
): Unit
Creates a matrix for rotation by angle a (in degrees) around the axis (x, y, z).
An optimized path will be used for rotation about a major axis (e.g. x=1.0f y=0.0f z=0.0f).
Parameters | |
---|---|
rm |
FloatArray!: returns the result |
rmOffset |
Int: index into rm where the result matrix starts |
a |
Float: angle to rotate in degrees |
x |
Float: X axis component |
y |
Float: Y axis component |
z |
Float: Z axis component |
translateM
open static fun translateM(
tm: FloatArray!,
tmOffset: Int,
m: FloatArray!,
mOffset: Int,
x: Float,
y: Float,
z: Float
): Unit
Translates matrix m by x, y, and z, putting the result in tm.
m and tm must not overlap.
Parameters | |
---|---|
tm |
FloatArray!: returns the result |
tmOffset |
Int: index into sm where the result matrix starts |
m |
FloatArray!: source matrix |
mOffset |
Int: index into m where the source matrix starts |
x |
Float: translation factor x |
y |
Float: translation factor y |
z |
Float: translation factor z |
translateM
open static fun translateM(
m: FloatArray!,
mOffset: Int,
x: Float,
y: Float,
z: Float
): Unit
Translates matrix m by x, y, and z in place.
Parameters | |
---|---|
m |
FloatArray!: matrix |
mOffset |
Int: index into m where the matrix starts |
x |
Float: translation factor x |
y |
Float: translation factor y |
z |
Float: translation factor z |
transposeM
open static fun transposeM(
mTrans: FloatArray!,
mTransOffset: Int,
m: FloatArray!,
mOffset: Int
): Unit
Transposes a 4 x 4 matrix.
mTrans and m must not overlap.
Parameters | |
---|---|
mTrans |
FloatArray!: the array that holds the output transposed matrix |
mTransOffset |
Int: an offset into mTrans where the transposed matrix is stored. |
m |
FloatArray!: the input array |
mOffset |
Int: an offset into m where the input matrix is stored. |