Files
XCEngine/docs/api/math/matrix3/matrix3.md
2026-03-20 02:35:15 +08:00

2.2 KiB
Raw Blame History

Matrix3 / Matrix3x3

命名空间: XCEngine::Math

类型: struct

头文件: XCEngine/Math/Matrix3.h

描述: 3x3 矩阵,用于旋转变换和线性代数运算。

概述

Matrix3别名 Matrix3x3是一个 3x3 浮点矩阵结构体,主要用于图形引擎中的旋转变换和线性代数运算。

设计目的:

  • 旋转变换(绕 X/Y/Z 轴)
  • 缩放变换
  • 矩阵运算(乘法、转置、求逆、行列式计算)

存储方式: 行优先存储 (row-major)

m[row][col]
m[0][0] m[0][1] m[0][2]
m[1][0] m[1][1] m[1][2]
m[2][0] m[2][1] m[2][2]

类型别名:

using Matrix3 = Matrix3x3;

结构体成员

成员 类型 描述
m[3][3] float 矩阵元素数组,行优先存储

公共方法

方法 描述
Identity() 获取单位矩阵
Zero() 获取零矩阵
RotationX() 创建绕 X 轴旋转矩阵
RotationY() 创建绕 Y 轴旋转矩阵
RotationZ() 创建绕 Z 轴旋转矩阵
Scale() 创建缩放矩阵
operator*(Matrix3) 矩阵乘法
operator*(Vector3) 矩阵-向量乘法
Transpose() 转置矩阵
Inverse() 逆矩阵
Determinant() 行列式
operator[] 访问矩阵元素

使用示例

#include <XCEngine/Math/Matrix3.h>
#include <XCEngine/Math/Vector3.h>

using namespace XCEngine::Math;

// 创建绕 Y 轴旋转 45 度的矩阵
Matrix3 rotation = Matrix3::RotationY(0.785f); // PI/4

// 对向量进行变换
Vector3 v(1.0f, 0.0f, 0.0f);
Vector3 rotated = rotation * v;

// 矩阵运算
Matrix3 m1 = Matrix3::RotationX(0.5f);
Matrix3 m2 = Matrix3::RotationY(0.3f);
Matrix3 combined = m1 * m2;

// 求逆矩阵
Matrix3 inv = combined.Inverse();
float det = combined.Determinant();

相关文档