Class Info |
|---|
class Matrix4 4*4矩阵类。包含矩阵的赋值、比较、加减乘法、求行列式、求逆、转置等操作,及作为旋转矩阵协助旋转操作。存储时以行为主序。 |
Qualifier and Type |
Field and Description |
|---|---|
m[MATRIX4_ROW_SIZE * MATRIX4_COLUMN_SIZE] 4*4矩阵的一维记录方式。 |
|
M[MATRIX4_ROW_SIZE][MATRIX4_COLUMN_SIZE] 4*4矩阵的四行四列记录方式。 |
Qualifier and Type |
Field and Description |
Value |
|---|---|---|
static const Matrix4 |
ZERO 零矩阵。 |
0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f |
static const Matrix4 |
IDENTITY 单位矩阵。 |
1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f |
static const u32 |
矩阵行数。 |
4 |
static const u32 |
矩阵列数。 |
4 |
static const u32 |
MATRIX4_SIZE 矩阵大小。 |
Qualifier and Type |
Method Name and Description |
|---|---|
f32& |
operator()(u32 row, u32 col) 获取4*4矩阵中第row行(row范围为[0, 3])第col列(col范围为[0, 3])的值。 |
const f32& |
operator()(u32 row, u32 col) const 获取4*4矩阵中第row行(row范围为[0, 3])第col列(col范围为[0, 3])的值。 |
f32& |
operator[](u32 index) 获取4*4矩阵中第index(范围为[0, 15])个数。 |
const f32& |
operator[](u32 index) const 获取4*4矩阵中第index(范围为[0, 15])个数。 |
operator=(const Matrix4& other) 重载赋值运算符,使用Matrix4类对象给当前对象赋值。 |
|
| 重载赋值运算符,使用浮点数给当前对象赋值,4*4矩阵中每个值都赋值为scalar。 |
|
operator+(const Matrix4& other) const 重载+运算符,用于当前对象和指定Matrix4类对象间的矩阵加法运算。 |
|
operator+=(const Matrix4& other) 重载+=运算符,用于当前对象和指定Matrix4类对象间的矩阵加法运算。 |
|
operator-(const Matrix4& other) const 重载-运算符,用于当前对象和指定Matrix4类对象间的矩阵减法运算。 |
|
operator-=(const Matrix4& other) 重载-=运算符,用于当前对象和指定Matrix4类对象间的矩阵减法运算。 |
|
operator*(const Matrix4& other) const 重载*运算符,用于当前对象和指定Matrix4类对象间的矩阵乘法运算。 |
|
operator*=(const Matrix4& other) 重载*=运算符,用于当前对象和指定Matrix4类对象间的矩阵乘法运算。 |
|
operator*(const Vector3& v) const 重载*运算符,以当前对象的4*4矩阵的前三列前三行作为旋转矩阵,第四行前三列作为平移向量,对三维向量进行旋转加平移的坐标变换。 |
|
operator*(const Vector4& v) const 重载*运算符,以当前对象的4*4矩阵为转换矩阵,对四维向量进行坐标变换。 |
|
operator*(const f32& scalar) const 重载*运算符,进行矩阵的数乘运算,当前对象的4*4矩阵中每个值均乘以scalar,返回记录矩阵数乘结果的Matrix4类对象。 |
|
operator*=(const f32& scalar) 重载*=运算符,进行矩阵的数乘运算,当前对象的4*4矩阵中每个值均乘以scalar,返回记录矩阵数乘结果的当前对象的引用。 |
|
bool |
operator==(const Matrix4& other) const 重载==运算符,比较当前对象和指定Matrix4类对象是否相等,相等返回true,不相等返回false。 |
bool |
operator!=(const Matrix4& other) const 重载!=运算符,比较当前对象和指定Matrix4类对象是否不相等,不相等返回true,相等返回false。 |
| 设置当前对象为单位矩阵。 |
|
Determinant() const 计算当前4*4矩阵的行列式。 |
|
Inversed() const 计算当前4*4矩阵的逆,返回记录矩阵求逆结果的Matrix4类对象。 |
|
Inverse() 计算当前4*4矩阵的逆,返回记录矩阵求逆结果的当前对象的引用。 |
|
Transposed() const 矩阵转置,返回记录矩阵转置结果的Matrix4类对象。 |
|
| 矩阵转置,返回记录矩阵转置结果的当前对象的引用。 |
|
| 设置4*4矩阵中的三维平移向量。 |
|
GetTrans() const 获取当前4*4矩阵中的三维平移向量。 |
|
SetScale(const Vector3& scale) 设置4*4矩阵中的三维缩放向量。 |
|
GetScale() const 获取当前4*4矩阵中的三维缩放向量。 |
|
GetUpVector() const 获取当前4*4矩阵中的向上向量。 |
|
GetRightVector() const 获取当前4*4矩阵中的向右向量。 |
|
GetForwardVector() const 获取当前4*4矩阵中的向前向量。 |
|
GetRotationMatrix(const Quaternion& rot) 根据四元数获取旋转矩阵,返回Matrix4类型的四元数对应的旋转矩阵,由于旋转矩阵为3*3,Matrix4矩阵第四行和第四列补0,对角线补1。 |
|
GetRotation() const 当前4*4矩阵前三行前三列作为旋转矩阵转换为欧拉角。 |
|
SetRotation(const Vector3& rotation) 当前4*4矩阵前三行前三列设置为根据欧拉角rotation转换成的旋转矩阵,第四行和第四列无变化。 |
|
MakeRotationAxisAngle(const f32& radianAngle, const Vector3& axis) 轴角对转旋转矩阵,存储于当前4*4矩阵的前三行三列中。 |
|
Rotate(const Vector3& axis, f32 radianAngle) 当前4*4矩阵绕旋转轴axis旋转radianAngle弧度。 |
|
void |
MakeTransform(const Vector3& position, const Vector3& scale, const Vector3& rotate) 当前对象设置为根据欧拉角rotate转换成的旋转矩阵,前三行前三列根据scale进行缩放,第四行前三列设置为position。 |
void |
MakeTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation) 当前对象设置为根据四元数orientation转换成的旋转矩阵,前三行前三列根据scale进行缩放,第四行前三列设置为position。 |
void |
Decomposition(Vector3* position, Vector3* scale, Vector3* rotate) const 根据当前4*4矩阵获取平移向量position、缩放向量scale,欧拉角rotate。 |
void |
Decomposition(Vector3* position, Vector3* scale, Quaternion* rotation) const 根据当前4*4矩阵获取平移向量position、缩放向量scale,四元数rotation。 |
void |
三维向量旋转,以当前4*4矩阵的前三行前三列作为旋转矩阵。 |
void |
Translate(Vector3& vect) const 三维向量平移,以当前4*4矩阵的第四行的前三列作为平移向量。 |
void |
Transform(Vector3& vect) const 三维向量旋转并平移,以当前4*4矩阵的前三行前三列作为旋转矩阵,第四行的前三列作为平移向量,结果记录在vect中。 |
Transform(const Vector3& in) const 三维向量旋转并平移,以当前4*4矩阵的前三行前三列作为旋转矩阵,第四行的前三列作为平移向量,返回记录旋转平移后的结果的三维向量。 |
|
Transform(const Vector4& in) const 四维向量旋转,以当前4*4矩阵作为旋转矩阵。 |
|
ToString() const 4*4矩阵转字符串类型,形如 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]。 |
Constructor |
|---|
Matrix4(f32 m00, f32 m01, f32 m02, f32 m03, f32 m10, f32 m11, f32 m12, f32 m13, f32 m20, f32 m21, f32 m22, f32 m23, f32 m30, f32 m31, f32 m32, f32 m33) 构造函数,使用16个参数初始化4*4矩阵。 |
Parameters
Name |
Description |
|---|---|
m00 |
初始化m[0]的值。 |
m01 |
初始化m[1]的值。 |
m02 |
初始化m[2]的值。 |
m03 |
初始化m[3]的值。 |
m10 |
初始化m[4]的值。 |
m11 |
初始化m[5]的值。 |
m12 |
初始化m[6]的值。 |
m13 |
初始化m[7]的值。 |
m20 |
初始化m[8]的值。 |
m21 |
初始化m[9]的值。 |
m22 |
初始化m[10]的值。 |
m23 |
初始化m[11]的值。 |
m30 |
初始化m[12]的值。 |
m31 |
初始化m[13]的值。 |
m32 |
初始化m[14]的值。 |
m33 |
初始化m[15]的值。 |
Parameters
Name |
Description |
|---|---|
row |
行数,若行数小于0,则取0,大于3,则取3。 |
col |
列数,若列数小于0,则取0,大于3,则取3。 |
Returns
Type |
Description |
|---|---|
f32& |
返回4*4矩阵中第row行(row范围为[0, 3])第col列(col范围为[0, 3])的值的引用。 |
Method |
|---|
const f32& operator()(u32 row, u32 col) const 获取4*4矩阵中第row行(row范围为[0, 3])第col列(col范围为[0, 3])的值。 |
Parameters
Name |
Description |
|---|---|
row |
行数,若行数小于0,则取0,大于3,则取3。 |
col |
列数,若列数小于0,则取0,大于3,则取3。 |
Returns
Type |
Description |
|---|---|
f32& |
返回4*4矩阵中第row行(row范围为[0, 3])第col列(col范围为[0, 3])的值的常量引用。 |
Parameters
Name |
Description |
|---|---|
index |
索引,范围为[0, 15]。 |
Returns
Type |
Description |
|---|---|
f32& |
返回4*4矩阵中第index(范围为[0, 15])个数的引用。 |
Parameters
Name |
Description |
|---|---|
index |
索引,范围为[0, 15]。 |
Returns
Type |
Description |
|---|---|
f32& |
返回4*4矩阵中第index(范围为[0, 15])个数的常量引用。 |
Parameters
Name |
Description |
|---|---|
other |
给当前对象赋值的Matrix4类对象。 |
Returns
Type |
Description |
|---|---|
返回赋值后对当前对象的引用。 |
Parameters
Name |
Description |
|---|---|
scalar |
给当前对象赋值的浮点数。 |
Returns
Type |
Description |
|---|---|
返回赋值后对当前对象的引用。 |
Parameters
Name |
Description |
|---|---|
other |
与当前对象进行矩阵加法运算的Matrix4类对象。 |
Returns
Type |
Description |
|---|---|
返回记录矩阵加法结果的当前对象的引用。 |
Parameters
Name |
Description |
|---|---|
other |
与当前对象进行矩阵减法运算并作为减数的Matrix4类对象。 |
Returns
Type |
Description |
|---|---|
返回记录矩阵减法结果的当前对象的引用。 |
Parameters
Name |
Description |
|---|---|
other |
与当前对象进行矩阵乘法运算的Matrix4类对象。 |
Returns
Type |
Description |
|---|---|
返回记录矩阵乘法结果的当前对象的引用。 |
Method |
|---|
Vector3 operator*(const Vector3& v) const 重载*运算符,以当前对象的4*4矩阵的前三列前三行作为旋转矩阵,第四行前三列作为平移向量,对三维向量进行旋转加平移的坐标变换。 |
Parameters
Name |
Description |
|---|---|
v |
需要进行坐标变换的三维向量。 |
Returns
Type |
Description |
|---|---|
返回记录坐标变换结果的三维向量。 |
Parameters
Name |
Description |
|---|---|
v |
需要进行坐标变换的四维向量。 |
Returns
Type |
Description |
|---|---|
返回记录坐标变换结果的四维向量。 |
Method |
|---|
Matrix4 operator*(const f32& scalar) const 重载*运算符,进行矩阵的数乘运算,当前对象的4*4矩阵中每个值均乘以scalar,返回记录矩阵数乘结果的Matrix4类对象。 |
Parameters
Name |
Description |
|---|---|
scalar |
数乘运算的系数。 |
Returns
Method |
|---|
Matrix4& operator*=(const f32& scalar) 重载*=运算符,进行矩阵的数乘运算,当前对象的4*4矩阵中每个值均乘以scalar,返回记录矩阵数乘结果的当前对象的引用。 |
Parameters
Name |
Description |
|---|---|
scalar |
数乘运算的系数。 |
Returns
Type |
Description |
|---|---|
返回记录矩阵数乘结果的当前对象的引用。 |
Method |
|---|
bool operator==(const Matrix4& other) const 重载==运算符,比较当前对象和指定Matrix4类对象是否相等,相等返回true,不相等返回false。 |
Parameters
Name |
Description |
|---|---|
other |
与当前对象进行比较的Matrix4类对象。 |
Returns
Type |
Description |
|---|---|
bool |
|
Method |
|---|
bool operator!=(const Matrix4& other) const 重载!=运算符,比较当前对象和指定Matrix4类对象是否不相等,不相等返回true,相等返回false。 |
Parameters
Name |
Description |
|---|---|
other |
与当前对象进行比较的Matrix4类对象。 |
Returns
Type |
Description |
|---|---|
bool |
|
Method |
|---|
Matrix4& MakeIdentity() 设置当前对象为单位矩阵。 |
Returns
Type |
Description |
|---|---|
返回设置为单位矩阵后对当前对象的引用。 |
Method |
|---|
f32 Determinant() const 计算当前4*4矩阵的行列式。 |
Returns
Type |
Description |
|---|---|
返回当前4*4矩阵的行列式。 |
Method |
|---|
Matrix4& Inverse() 计算当前4*4矩阵的逆,返回记录矩阵求逆结果的当前对象的引用。 |
Returns
Type |
Description |
|---|---|
返回记录矩阵求逆结果的当前对象的引用。 |
Method |
|---|
Matrix4& Transpose() 矩阵转置,返回记录矩阵转置结果的当前对象的引用。 |
Returns
Type |
Description |
|---|---|
返回记录矩阵转置结果的当前对象的引用。 |
Method |
|---|
Vector3 GetTrans() const 获取当前4*4矩阵中的三维平移向量。 |
Returns
Type |
Description |
|---|---|
返回4*4矩阵中的平移向量。 |
Parameters
Name |
Description |
|---|---|
scale |
待设置缩放向量。 |
Returns
Type |
Description |
|---|---|
返回对设置缩放向量后的当前对象的引用。 |
Method |
|---|
Vector3 GetScale() const 获取当前4*4矩阵中的三维缩放向量。 |
Returns
Type |
Description |
|---|---|
返回4*4矩阵中的缩放向量。 |
Method |
|---|
Vector3 GetUpVector() const 获取当前4*4矩阵中的向上向量。 |
Returns
Type |
Description |
|---|---|
返回4*4矩阵中的向上向量。 |
Method |
|---|
Vector3 GetRightVector() const 获取当前4*4矩阵中的向右向量。 |
Returns
Type |
Description |
|---|---|
返回4*4矩阵中的向右向量。 |
Method |
|---|
Vector3 GetForwardVector() const 获取当前4*4矩阵中的向前向量。 |
Returns
Type |
Description |
|---|---|
返回4*4矩阵中的向前向量。 |
Method |
|---|
Matrix4 GetRotationMatrix(const Quaternion& rot) 根据四元数获取旋转矩阵,返回Matrix4类型的四元数对应的旋转矩阵,由于旋转矩阵为3*3,Matrix4矩阵第四行和第四列补0,对角线补1。 |
Parameters
Name |
Description |
|---|---|
rot |
待转换为旋转矩阵的四元数。 |
Returns
Method |
|---|
Vector3 GetRotation() const 当前4*4矩阵前三行前三列作为旋转矩阵转换为欧拉角。 |
Returns
Type |
Description |
|---|---|
返回转换后的欧拉角。 |
Method |
|---|
Matrix4& SetRotation(const Vector3& rotation) 当前4*4矩阵前三行前三列设置为根据欧拉角rotation转换成的旋转矩阵,第四行和第四列无变化。 |
Parameters
Name |
Description |
|---|---|
rotation |
待转换为旋转矩阵的欧拉角。 |
Returns
Type |
Description |
|---|---|
返回记录了旋转矩阵的当前对象的引用。 |
Method |
|---|
Matrix4& MakeRotationAxisAngle(const f32& radianAngle, const Vector3& axis) 轴角对转旋转矩阵,存储于当前4*4矩阵的前三行三列中。 |
Parameters
Name |
Description |
|---|---|
radianAngle |
旋转弧度。 |
axis |
旋转轴。 |
Returns
Type |
Description |
|---|---|
返回记录了轴角对转旋转矩阵结果的当前对象的引用。 |
Parameters
Name |
Description |
|---|---|
axis |
旋转轴。 |
radianAngle |
旋转弧度。 |
Returns
Type |
Description |
|---|---|
返回对旋转后当前对象的引用。 |
Method |
|---|
void MakeTransform(const Vector3& position, const Vector3& scale, const Vector3& rotate) 当前对象设置为根据欧拉角rotate转换成的旋转矩阵,前三行前三列根据scale进行缩放,第四行前三列设置为position。 |
Parameters
Name |
Description |
|---|---|
position |
平移向量。 |
scale |
缩放向量。 |
rotate |
欧拉角。 |
Method |
|---|
void MakeTransform(const Vector3& position, const Vector3& scale, const Quaternion& orientation) 当前对象设置为根据四元数orientation转换成的旋转矩阵,前三行前三列根据scale进行缩放,第四行前三列设置为position。 |
Parameters
Name |
Description |
|---|---|
position |
平移向量。 |
scale |
缩放向量。 |
orientation |
四元数。 |
Method |
|---|
void Decomposition(Vector3* position, Vector3* scale, Vector3* rotate) const 根据当前4*4矩阵获取平移向量position、缩放向量scale,欧拉角rotate。 |
Parameters
Name |
Description |
|---|---|
position |
从4*4矩阵中获取的平移向量。 |
scale |
从4*4矩阵中获取的缩放向量。 |
rotate |
从4*4矩阵中获取的欧拉角。 |
Method |
|---|
void Decomposition(Vector3* position, Vector3* scale, Quaternion* rotation) const 根据当前4*4矩阵获取平移向量position、缩放向量scale,四元数rotation。 |
Parameters
Name |
Description |
|---|---|
position |
从4*4矩阵中获取的平移向量。 |
scale |
从4*4矩阵中获取的缩放向量。 |
rotation |
从4*4矩阵中获取的欧拉角。 |
Method |
|---|
void Rotate(Vector3& vect) const 三维向量旋转,以当前4*4矩阵的前三行前三列作为旋转矩阵。 |
Parameters
Name |
Description |
|---|---|
vect |
待旋转的三维向量。 |
Method |
|---|
void Translate(Vector3& vect) const 三维向量平移,以当前4*4矩阵的第四行的前三列作为平移向量。 |
Parameters
Name |
Description |
|---|---|
vect |
待平移的三维向量。 |
Method |
|---|
void Transform(Vector3& vect) const 三维向量旋转并平移,以当前4*4矩阵的前三行前三列作为旋转矩阵,第四行的前三列作为平移向量。 |
Parameters
Name |
Description |
|---|---|
vect |
待平移的三维向量引用,并记录旋转平移后的结果。 |
Parameters
Name |
Description |
|---|---|
in |
待平移的三维向量。 |
Returns
Type |
Description |
|---|---|
返回记录旋转平移后结果的三维向量。 |