Files
XCEngine/docs/api/math/quaternion/quaternion.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

73 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Quaternion
**命名空间**: `XCEngine::Math`
**类型**: `struct`
**头文件**: `XCEngine/Core/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
#include <XCEngine/Core/Math/Quaternion.h>
#include <XCEngine/Core/Math/Vector3.h>
#include <XCEngine/Core/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);
```
## 相关文档
- [Math 模块总览](../math.md) - Math 模块概览
- [Vector3](../vector3/vector3.md) - 三维向量
- [Matrix4](../matrix4/matrix4.md) - 4x4 矩阵