Most visited

Recently visited

Added in API level 1

Matrix

public class Matrix
extends Object

java.lang.Object
   ↳ android.opengl.Matrix


矩阵数学实用程序。 这些方法在存储在浮点数组中的OpenGL ES格式矩阵和向量上运行。

矩阵是以列主要顺序存储的4 x 4列向量矩阵:

  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()

此构造函数在API级别19中已被弃用。所有方法都是静态的,不要实例化此类。

Public methods

static void frustumM(float[] m, int offset, float left, float right, float bottom, float top, float near, float far)

根据六个剪辑平面定义投影矩阵。

static boolean invertM(float[] mInv, int mInvOffset, float[] m, int mOffset)

反转4×4矩阵。

static float length(float x, float y, float z)

计算矢量的长度。

static void multiplyMM(float[] result, int resultOffset, float[] lhs, int lhsOffset, float[] rhs, int rhsOffset)

将两个4x4矩阵相乘并将结果存储在第三个4x4矩阵中。

static void multiplyMV(float[] resultVec, int resultVecOffset, float[] lhsMat, int lhsMatOffset, float[] rhsVec, int rhsVecOffset)

将4元素向量乘以4x4矩阵,并将结果存储在4元素列向量中。

static void orthoM(float[] m, int mOffset, float left, float right, float bottom, float top, float near, float far)

计算正交投影矩阵。

static void perspectiveM(float[] m, int offset, float fovy, float aspect, float zNear, float zFar)

根据视场角,纵横比和z剪辑平面定义投影矩阵。

static void rotateM(float[] rm, int rmOffset, float[] m, int mOffset, float a, float x, float y, float z)

围绕轴(x,y,z)以角度a(以度为单位)旋转矩阵M.

static void rotateM(float[] m, int mOffset, float a, float x, float y, float z)

围绕轴(x,y,z)以角度α(以度为单位)将矩阵m旋转到位。

static void scaleM(float[] m, int mOffset, float x, float y, float z)

通过sx,sy和sz来缩放矩阵m。

static void scaleM(float[] sm, int smOffset, float[] m, int mOffset, float x, float y, float z)

将矩阵m按x,y和z进行缩放,将结果放入sm。

static void setIdentityM(float[] sm, int smOffset)

将矩阵m设置为单位矩阵。

static void setLookAtM(float[] rm, int rmOffset, float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)

根据视点,视点和向上矢量定义视图变换。

static void setRotateEulerM(float[] rm, int rmOffset, float x, float y, float z)

将欧拉角转换为旋转矩阵。

static void setRotateM(float[] rm, int rmOffset, float a, float x, float y, float z)

创建一个矩阵,用于围绕轴(x,y,z)旋转角度α(以度为单位)。

static void translateM(float[] m, int mOffset, float x, float y, float z)

将矩阵m转换为x,y和z。

static void translateM(float[] tm, int tmOffset, float[] m, int mOffset, float x, float y, float z)

用x,y和z转换矩阵m,将结果放入tm。

static void transposeM(float[] mTrans, int mTransOffset, float[] m, int mOffset)

转置4 x 4矩阵。

Inherited methods

From class java.lang.Object

Public constructors

Matrix

Added in API level 1
Matrix ()

此构造函数在API级别19中已被弃用。
所有的方法都是静态的,不要实例化这个类。

Public methods

frustumM

Added in API level 1
void frustumM (float[] m, 
                int offset, 
                float left, 
                float right, 
                float bottom, 
                float top, 
                float near, 
                float far)

根据六个剪辑平面定义投影矩阵。

Parameters
m float: the float array that holds the output perspective matrix
offset int: the offset into float array m where the perspective matrix data is written

invertM

Added in API level 1
boolean invertM (float[] mInv, 
                int mInvOffset, 
                float[] m, 
                int mOffset)

反转4×4矩阵。

mInv和m不能重叠。

Parameters
mInv float: the array that holds the output inverted matrix
mInvOffset int: an offset into mInv where the inverted matrix is stored.
m float: the input array
mOffset int: an offset into m where the input matrix is stored.
Returns
boolean true if the matrix could be inverted, false if it could not.

length

Added in API level 1
float length (float x, 
                float y, 
                float z)

计算矢量的长度。

Parameters
x float: x coordinate of a vector
y float: y coordinate of a vector
z float: z coordinate of a vector
Returns
float the length of a vector

multiplyMM

Added in API level 1
void multiplyMM (float[] result, 
                int resultOffset, 
                float[] lhs, 
                int lhsOffset, 
                float[] rhs, 
                int rhsOffset)

将两个4x4矩阵相乘并将结果存储在第三个4x4矩阵中。 在矩阵符号中:结果= lhs x rhs。 由于矩阵乘法的工作方式,结果矩阵将具有与首先乘以rhs矩阵相同的效果,然后乘以lhs矩阵。 这与你所期望的相反。

相同的浮点数组可以传递结果,lhs和/或rhs。 但是,如果结果元素与lhs或rhs元素重叠,则结果元素值未定义。

Parameters
result float: The float array that holds the result.
resultOffset int: The offset into the result array where the result is stored.
lhs float: The float array that holds the left-hand-side matrix.
lhsOffset int: The offset into the lhs array where the lhs is stored
rhs float: The float array that holds the right-hand-side matrix.
rhsOffset int: The offset into the rhs array where the rhs is stored.
Throws
IllegalArgumentException if result, lhs, or rhs are null, or if resultOffset + 16 > result.length or lhsOffset + 16 > lhs.length or rhsOffset + 16 > rhs.length.

multiplyMV

Added in API level 1
void multiplyMV (float[] resultVec, 
                int resultVecOffset, 
                float[] lhsMat, 
                int lhsMatOffset, 
                float[] rhsVec, 
                int rhsVecOffset)

将4元素向量乘以4x4矩阵,并将结果存储在4元素列向量中。 在矩阵符号中:结果= lhs x rhs

可以为resultVec,lhsMat和/或rhsVec传递相同的浮点数组。 但是,如果resultVec元素与lhsMat或rhsVec元素重叠,则resultVec元素值未定义。

Parameters
resultVec float: The float array that holds the result vector.
resultVecOffset int: The offset into the result array where the result vector is stored.
lhsMat float: The float array that holds the left-hand-side matrix.
lhsMatOffset int: The offset into the lhs array where the lhs is stored
rhsVec float: The float array that holds the right-hand-side vector.
rhsVecOffset int: The offset into the rhs vector where the rhs vector is stored.
Throws
IllegalArgumentException if resultVec, lhsMat, or rhsVec are null, or if resultVecOffset + 4 > resultVec.length or lhsMatOffset + 16 > lhsMat.length or rhsVecOffset + 4 > rhsVec.length.

orthoM

Added in API level 1
void orthoM (float[] m, 
                int mOffset, 
                float left, 
                float right, 
                float bottom, 
                float top, 
                float near, 
                float far)

计算正交投影矩阵。

Parameters
m float: returns the result

perspectiveM

Added in API level 14
void perspectiveM (float[] m, 
                int offset, 
                float fovy, 
                float aspect, 
                float zNear, 
                float zFar)

根据视场角,纵横比和z剪辑平面定义投影矩阵。

Parameters
m float: 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

rotateM

Added in API level 1
void rotateM (float[] rm, 
                int rmOffset, 
                float[] m, 
                int mOffset, 
                float a, 
                float x, 
                float y, 
                float z)

围绕轴(x,y,z)以角度a(以度为单位)旋转矩阵M.

m和rm不能重叠。

Parameters
rm float: returns the result
rmOffset int: index into rm where the result matrix starts
m float: 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

Added in API level 1
void rotateM (float[] m, 
                int mOffset, 
                float a, 
                float x, 
                float y, 
                float z)

围绕轴(x,y,z)以角度α(以度为单位)将矩阵m旋转到位。

Parameters
m float: 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

Added in API level 1
void scaleM (float[] m, 
                int mOffset, 
                float x, 
                float y, 
                float z)

通过sx,sy和sz来缩放矩阵m。

Parameters
m float: 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

scaleM

Added in API level 1
void scaleM (float[] sm, 
                int smOffset, 
                float[] m, 
                int mOffset, 
                float x, 
                float y, 
                float z)

将矩阵m按x,y和z进行缩放,将结果放入sm。

m和sm不能重叠。

Parameters
sm float: returns the result
smOffset int: index into sm where the result matrix starts
m float: 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

setIdentityM

Added in API level 1
void setIdentityM (float[] sm, 
                int smOffset)

将矩阵m设置为单位矩阵。

Parameters
sm float: returns the result
smOffset int: index into sm where the result matrix starts

setLookAtM

Added in API level 8
void setLookAtM (float[] rm, 
                int rmOffset, 
                float eyeX, 
                float eyeY, 
                float eyeZ, 
                float centerX, 
                float centerY, 
                float centerZ, 
                float upX, 
                float upY, 
                float upZ)

根据视点,视点和向上矢量定义视图变换。

Parameters
rm float: 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

Added in API level 1
void setRotateEulerM (float[] rm, 
                int rmOffset, 
                float x, 
                float y, 
                float z)

将欧拉角转换为旋转矩阵。

Parameters
rm float: 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

setRotateM

Added in API level 1
void setRotateM (float[] rm, 
                int rmOffset, 
                float a, 
                float x, 
                float y, 
                float z)

创建一个矩阵,用于围绕轴(x,y,z)旋转角度α(以度为单位)。

优化路径将用于围绕主轴旋转(例如x = 1.0fy = 0.0fz = 0.0f)。

Parameters
rm float: 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

Added in API level 1
void translateM (float[] m, 
                int mOffset, 
                float x, 
                float y, 
                float z)

将矩阵m转换为x,y和z。

Parameters
m float: 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

translateM

Added in API level 1
void translateM (float[] tm, 
                int tmOffset, 
                float[] m, 
                int mOffset, 
                float x, 
                float y, 
                float z)

用x,y和z转换矩阵m,将结果放入tm。

m和tm不能重叠。

Parameters
tm float: returns the result
tmOffset int: index into sm where the result matrix starts
m float: 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

transposeM

Added in API level 1
void transposeM (float[] mTrans, 
                int mTransOffset, 
                float[] m, 
                int mOffset)

转置4 x 4矩阵。

mTrans和m不能重叠。

Parameters
mTrans float: the array that holds the output transposed matrix
mTransOffset int: an offset into mTrans where the transposed matrix is stored.
m float: the input array
mOffset int: an offset into m where the input matrix is stored.

Hooray!