修复的问题: - math: 修复 Quaternion::Normalize 链接错误 - containers: HashMap 迭代器示例使用不存在的 cbegin/cend,删除冗余构造函数声明 - core: RefCounted 析构函数访问级别修正 (protected) - debug: LogLevelToString 示例返回值大小写修正 - memory: 修正 LinearAllocator::Reallocate 返回 nullptr,ProxyAllocator 统计描述,头文件路径 IAllocator.h -> Allocator.h - resources: Texture::Create mipLevels 参数描述修正 - rhi: 修复多处链接错误,新增缺失的方法文档 - threading: TaskSystem 配置项未实现状态标注,Wait 方法空实现标注
1.8 KiB
1.8 KiB
Quaternion
四元数结构体,用于表示 3D 旋转,避免欧拉角的万向锁问题。
头文件: #include <XCEngine/Math/Quaternion.h>
命名空间: XCEngine::Math
结构体定义
struct Quaternion {
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
float w = 1.0f;
};
静态工厂方法
| 方法 | 返回值 | 描述 |
|---|---|---|
| Identity() | Quaternion |
返回 (0, 0, 0, 1),恒等旋转 |
| FromAxisAngle(axis, radians) | Quaternion |
从轴角创建 |
| FromEulerAngles(pitch, yaw, roll) | Quaternion |
从欧拉角创建(弧度) |
| FromEulerAngles(euler) | Quaternion |
从 Vector3 欧拉角创建 |
| FromRotationMatrix(matrix) | Quaternion |
从旋转矩阵创建 |
| Slerp(a, b, t) | Quaternion |
球面线性插值 |
| LookRotation(forward, up) | Quaternion |
看向方向 |
实例方法
| 方法 | 返回值 | 描述 |
|---|---|---|
| ToEulerAngles() | Vector3 |
转换为欧拉角(弧度) |
| ToMatrix4x4() | Matrix4 |
转换为 4x4 旋转矩阵 |
| Inverse() | Quaternion |
共轭/逆四元数 |
| Dot(other) | float |
点积 |
| Magnitude() | float |
模长 |
| Normalized() | Quaternion |
归一化 |
| Normalize(q) | Quaternion |
归一化(静态) |
运算符
| 运算符 | 描述 |
|---|---|
operator*(Quaternion, Quaternion) |
组合旋转 |
与 Vector3 的乘法
Vector3 * Quaternion - 用四元数旋转向量
相关文档
- Math 模块总览 - 返回 Math 模块总览