Files
XCEngine/docs/api/math/matrix3/matrix3.md
ssdfasd f5a34f8adc docs: 重构 API 文档 - components 和 scene 模块
- components: 修复英文标题为中文,添加缺失组件文档
  - 新增 camera-component, light-component, audio-source-component, audio-listener-component 类总览
  - 修复 get-position.md 格式
  - 更新 components.md 模块总览
- scene: 修复方法文档格式,新增缺失方法
  - 修复 find.md, create-game-object.md 英文标题
  - 新增 FindByID, SerializeToString, DeserializeFromString 方法文档
  - 更新 scene.md 类总览方法列表
2026-03-26 01:50:27 +08:00

2.2 KiB
Raw Blame History

Matrix3 / Matrix3x3

命名空间: XCEngine::Math

类型: struct

头文件: XCEngine/Core/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/Core/Math/Matrix3.h>
#include <XCEngine/Core/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();

相关文档