Added in API level 35

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

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 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 ]
  

Public methods
open Matrix44

Multiplies `this` matrix (A) and provided Matrix (B) in the order of A * B.

open Boolean
equals(other: Any?)

Indicates whether some other object is "equal to" this one.

open Float
get(row: Int, col: Int)

Gets the value at the matrix's row and column.

open Unit

Copies matrix values into the provided array in row-major order.

open Int

Returns a hash code value for the object.

open Boolean

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
map(x: Float, y: Float, z: Float, w: Float)

Multiplies (x, y, z, w) vector by the Matrix44, then returns the new (x, y, z, w).

open Unit
map(x: Float, y: Float, z: Float, w: Float, dst: FloatArray)

Multiplies (x, y, z, w) vector by the Matrix44, then returns the new (x, y, z, w).

open Unit

Sets the Matrix44 to the identity matrix.

open Matrix44
rotate(deg: Float, xComp: Float, yComp: Float, zComp: Float)

Applies a rotation around a given axis, then returns self.

open Matrix44
scale(x: Float, y: Float, z: Float)

Applies scaling factors to `this` Matrix44, then returns self.

open Unit
set(row: Int, col: Int, val: Float)

Sets the value at the matrix's row and column to the provided value.

open Unit

Replaces the Matrix's values with the values in the provided array.

open String

Returns a string representation of the object.

open Matrix44
translate(x: Float, y: Float, z: Float)

Applies a translation to `this` Matrix44, then returns self.

Public constructors

Matrix44

Added in API level 35
Matrix44()

The default Matrix44 constructor will instantiate an identity matrix.

Matrix44

Added in API level 35
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

Added in API level 35
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

Added in API level 35
open fun equals(other: Any?): Boolean

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

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

Added in API level 35
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

Added in API level 35
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

Added in API level 35
open fun hashCode(): Int

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Return
Int a hash code value for this object.

invert

Added in API level 35
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

Added in API level 35
open fun isIdentity(): Boolean

Returns true if Matrix44 is equal to identity matrix.

map

Added in API level 35
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

Added in API level 35
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.

reset

Added in API level 35
open fun reset(): Unit

Sets the Matrix44 to the identity matrix.

rotate

Added in API level 35
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

Added in API level 35
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

Added in API level 35
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

Added in API level 35
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

Added in API level 35
open fun toString(): String

Returns a string representation of the object.

Return
String a string representation of the object.

translate

Added in API level 35
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.