Matrix44
open class Matrix44
| kotlin.Any | |
| ↳ | android.graphics.Matrix44 |
The Matrix44 class holds a 4x4 matrix for transforming coordinates. It is similar to Matrix, and should be used when you want to manipulate the canvas in 3D. Values are kept in row-major order. The values and operations are treated as column vectors.
Summary
| Public constructors | |
|---|---|
Matrix44()The default Matrix44 constructor will instantiate an identity matrix. |
|
|
Creates and returns a Matrix44 by taking the 3x3 Matrix and placing it on the 0 of the z-axis by setting row [ a b c ] [ a b 0 c ] [ d e f ] -> [ d e 0 f ] [ g h i ] [ 0 0 1 0 ] [ g h 0 i ] |
|
| Public methods | |
|---|---|
| open Matrix44 |
Multiplies `this` matrix (A) and provided Matrix (B) in the order of A * B. |
| open Boolean | |
| open Float |
Gets the value at the matrix's row and column. |
| open Unit |
getValues(dst: FloatArray)Copies matrix values into the provided array in row-major order. |
| open Int |
hashCode() |
| open Boolean |
invert()Inverts the Matrix44, then return true if successful, false if unable to invert. |
| open Boolean |
Returns true if Matrix44 is equal to identity matrix. |
| open FloatArray |
Multiplies (x, y, z, w) vector by the Matrix44, then returns the new (x, y, z, w). |
| open Unit |
Multiplies (x, y, z, w) vector by the Matrix44, then returns the new (x, y, z, w). |
| open Unit |
reset()Sets the Matrix44 to the identity matrix. |
| open Matrix44 |
Applies a rotation around a given axis, then returns self. |
| open Matrix44 |
Applies scaling factors to `this` Matrix44, then returns self. |
| open Unit |
Sets the value at the matrix's row and column to the provided value. |
| open Unit |
setValues(src: FloatArray)Replaces the Matrix's values with the values in the provided array. |
| open String |
toString() |
| open Matrix44 |
Applies a translation to `this` Matrix44, then returns self. |
Public constructors
Matrix44
Matrix44()
The default Matrix44 constructor will instantiate an identity matrix.
Matrix44
Matrix44(mat: Matrix)
Creates and returns a Matrix44 by taking the 3x3 Matrix and placing it on the 0 of the z-axis by setting row 2 and column 2 to the identity as seen in the following operation:
[ a b c ] [ a b 0 c ] [ d e f ] -> [ d e 0 f ] [ g h i ] [ 0 0 1 0 ] [ g h 0 i ]
| Parameters | |
|---|---|
mat |
Matrix: A 3x3 Matrix to be converted (original Matrix will not be changed) This value cannot be null. |
Public methods
concat
open fun concat(b: Matrix44): Matrix44
Multiplies `this` matrix (A) and provided Matrix (B) in the order of A * B. The result is saved in `this` Matrix.
| Parameters | |
|---|---|
b |
Matrix44: The second Matrix in the concatenation operation This value cannot be null. |
| Return | |
|---|---|
Matrix44 |
A reference to this Matrix, which can be used to chain Matrix operations This value cannot be null. |
equals
open fun equals(other: Any?): Boolean
| Parameters | |
|---|---|
obj |
the reference object with which to compare. |
| Return | |
|---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
get
open fun get(
row: Int,
col: Int
): Float
Gets the value at the matrix's row and column.
| Parameters | |
|---|---|
row |
Int: An integer from 0 to 3 indicating the row of the value to get Value is between 0 and 3 inclusive |
col |
Int: An integer from 0 to 3 indicating the column of the value to get Value is between 0 and 3 inclusive |
getValues
open fun getValues(dst: FloatArray): Unit
Copies matrix values into the provided array in row-major order.
| Parameters | |
|---|---|
dst |
FloatArray: The float array where values will be copied, must be of length 16 This value cannot be null. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if the destination float array is not of length 16 |
hashCode
open fun hashCode(): Int
| Return | |
|---|---|
Int |
a hash code value for this object. |
invert
open fun invert(): Boolean
Inverts the Matrix44, then return true if successful, false if unable to invert.
| Return | |
|---|---|
Boolean |
true on success, false otherwise |
isIdentity
open fun isIdentity(): Boolean
Returns true if Matrix44 is equal to identity matrix.
map
open fun map(
x: Float,
y: Float,
z: Float,
w: Float
): FloatArray
Multiplies (x, y, z, w) vector by the Matrix44, then returns the new (x, y, z, w). Users should set w to 1 to indicate the coordinates are normalized.
| Return | |
|---|---|
FloatArray |
An array of length 4 that represents the x, y, z, w (where w is perspective) value after multiplying x, y, z, 1 by the matrix This value cannot be null. |
map
open fun map(
x: Float,
y: Float,
z: Float,
w: Float,
dst: FloatArray
): Unit
Multiplies (x, y, z, w) vector by the Matrix44, then returns the new (x, y, z, w). Users should set w to 1 to indicate the coordinates are normalized.
| Parameters | |
|---|---|
dst |
FloatArray: This value cannot be null. |
rotate
open fun rotate(
deg: Float,
xComp: Float,
yComp: Float,
zComp: Float
): Matrix44
Applies a rotation around a given axis, then returns self. x, y, z represent the axis by which to rotate around. For example, pass in 1, 0, 0 to rotate around the x-axis. The axis provided will be normalized.
| Parameters | |
|---|---|
deg |
Float: Amount in degrees to rotate the matrix about the x-axis |
xComp |
Float: X component of the rotation axis |
yComp |
Float: Y component of the rotation axis |
zComp |
Float: Z component of the rotation axis |
| Return | |
|---|---|
Matrix44 |
A reference to this Matrix, which can be used to chain Matrix operations This value cannot be null. |
scale
open fun scale(
x: Float,
y: Float,
z: Float
): Matrix44
Applies scaling factors to `this` Matrix44, then returns self. Pass 1s for no change.
| Parameters | |
|---|---|
x |
Float: Scaling factor for the x-axis |
y |
Float: Scaling factor for the y-axis |
z |
Float: Scaling factor for the z-axis |
| Return | |
|---|---|
Matrix44 |
A reference to this Matrix, which can be used to chain Matrix operations This value cannot be null. |
set
open fun set(
row: Int,
col: Int,
val: Float
): Unit
Sets the value at the matrix's row and column to the provided value.
| Parameters | |
|---|---|
row |
Int: An integer from 0 to 3 indicating the row of the value to change Value is between 0 and 3 inclusive |
col |
Int: An integer from 0 to 3 indicating the column of the value to change Value is between 0 and 3 inclusive |
val |
Float: The value the element at the specified index will be set to |
setValues
open fun setValues(src: FloatArray): Unit
Replaces the Matrix's values with the values in the provided array.
| Parameters | |
|---|---|
src |
FloatArray: A float array of length 16. Floats are treated in row-major order This value cannot be null. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
if the destination float array is not of length 16 |
toString
open fun toString(): String
| Return | |
|---|---|
String |
a string representation of the object. |
translate
open fun translate(
x: Float,
y: Float,
z: Float
): Matrix44
Applies a translation to `this` Matrix44, then returns self.
| Parameters | |
|---|---|
x |
Float: Translation for the x-axis |
y |
Float: Translation for the y-axis |
z |
Float: Translation for the z-axis |
| Return | |
|---|---|
Matrix44 |
A reference to this Matrix, which can be used to chain Matrix operations This value cannot be null. |