docs: update math API docs
This commit is contained in:
@@ -1,61 +1,72 @@
|
||||
# Quaternion
|
||||
|
||||
四元数结构体,用于表示 3D 旋转,避免欧拉角的万向锁问题。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Quaternion.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Quaternion.h`
|
||||
|
||||
## 结构体定义
|
||||
**描述**: 四元数,用于表示三维旋转
|
||||
|
||||
## 概述
|
||||
|
||||
Quaternion 提供了一套完整的三维旋转表示和操作方法。四元数可以避免欧拉角的万向节锁问题,并提供平滑的旋转插值(Slerp)。
|
||||
|
||||
## 结构体成员
|
||||
|
||||
| 成员 | 类型 | 描述 | 默认值 |
|
||||
|------|------|------|--------|
|
||||
| `x` | `float` | X 分量 | `0.0f` |
|
||||
| `y` | `float` | Y 分量 | `0.0f` |
|
||||
| `z` | `float` | Z 分量 | `0.0f` |
|
||||
| `w` | `float` | W 分量(标量部分) | `1.0f` |
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Identity`](identity.md) | 返回单位四元数 |
|
||||
| [`FromAxisAngle`](from-axis-angle.md) | 从轴角创建四元数 |
|
||||
| [`FromEulerAngles`](from-euler-angles.md) | 从欧拉角创建四元数 |
|
||||
| [`FromRotationMatrix`](from-rotation-matrix.md) | 从旋转矩阵创建四元数 |
|
||||
| [`Slerp`](slerp.md) | 球面线性插值 |
|
||||
| [`LookRotation`](look-rotation.md) | 创建看向目标的旋转 |
|
||||
| [`ToEulerAngles`](to-euler-angles.md) | 转换为欧拉角 |
|
||||
| [`ToMatrix4x4`](to-matrix4x4.md) | 转换为 4x4 矩阵 |
|
||||
| [`operator*`](operator-mul.md) | 四元数乘法 |
|
||||
| [`Inverse`](inverse.md) | 求四元数逆 |
|
||||
| [`Dot`](dot.md) | 点积 |
|
||||
| [`Magnitude`](magnitude.md) | 求模长 |
|
||||
| [`Normalized`](normalized.md) | 返回归一化四元数 |
|
||||
| [`Normalize`](normalize.md) | 归一化四元数(静态) |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
struct Quaternion {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float z = 0.0f;
|
||||
float w = 1.0f;
|
||||
};
|
||||
#include <XCEngine/Math/Quaternion.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
// 从欧拉角创建
|
||||
Quaternion q1 = Quaternion::FromEulerAngles(0, Math::Radians(90.0f), 0);
|
||||
|
||||
// 从轴角创建
|
||||
Quaternion q2 = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(45.0f));
|
||||
|
||||
// 组合旋转
|
||||
Quaternion combined = q1 * q2;
|
||||
|
||||
// 旋转向量
|
||||
Vector3 rotated = q2 * Vector3::Forward();
|
||||
|
||||
// 球面插值
|
||||
Quaternion result = Quaternion::Slerp(q1, q2, 0.5f);
|
||||
```
|
||||
|
||||
## 静态工厂方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Identity()](identity.md) | `Quaternion` | 返回 (0, 0, 0, 1),恒等旋转 |
|
||||
| [FromAxisAngle(axis, radians)](fromaxisangle.md) | `Quaternion` | 从轴角创建 |
|
||||
| [FromEulerAngles(pitch, yaw, roll)](fromeulerangles.md) | `Quaternion` | 从欧拉角创建(弧度) |
|
||||
| [FromEulerAngles(euler)](fromeulerangles.md) | `Quaternion` | 从 Vector3 欧拉角创建 |
|
||||
| [FromRotationMatrix(matrix)](fromrotationmatrix.md) | `Quaternion` | 从旋转矩阵创建 |
|
||||
| [Slerp(a, b, t)](slerp.md) | `Quaternion` | 球面线性插值 |
|
||||
| [LookRotation(forward, up)](lookrotation.md) | `Quaternion` | 看向方向 |
|
||||
|
||||
## 实例方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [ToEulerAngles()](toeulerangles.md) | `Vector3` | 转换为欧拉角(弧度) |
|
||||
| [ToMatrix4x4()](tomatrix4x4.md) | `Matrix4` | 转换为 4x4 旋转矩阵 |
|
||||
| [Inverse()](inverse.md) | `Quaternion` | 共轭/逆四元数 |
|
||||
| [Dot(other)](dot.md) | `float` | 点积 |
|
||||
| [Magnitude()](magnitude.md) | `float` | 模长 |
|
||||
| [Normalized()](normalized.md) | `Quaternion` | 归一化副本 |
|
||||
|
||||
## 静态方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Normalize(q)](normalized.md) | `Quaternion` | 归一化四元数 |
|
||||
|
||||
## 运算符
|
||||
|
||||
| 运算符 | 描述 |
|
||||
|--------|------|
|
||||
| `operator*(Quaternion, Quaternion)` | 组合旋转 |
|
||||
|
||||
## 与 Vector3 的乘法
|
||||
|
||||
[Vector3 * Quaternion](quaternion-multiply.md) - 用四元数旋转向量
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Math 模块总览](../math.md) - Math 模块概览
|
||||
- [Vector3](../vector3/vector3.md) - 三维向量
|
||||
- [Matrix4](../matrix4/matrix4.md) - 4x4 矩阵
|
||||
|
||||
Reference in New Issue
Block a user