docs: update math API docs
This commit is contained in:
@@ -1,39 +1,71 @@
|
||||
# Transform
|
||||
|
||||
3D 变换结构体,包含位置、旋转和缩放,用于层次化变换。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Transform.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Transform.h`
|
||||
|
||||
## Space 枚举
|
||||
**描述**: 变换组件,包含位置、旋转和缩放,用于层级变换计算
|
||||
|
||||
## 概述
|
||||
|
||||
`Transform` 是 XCEngine 中的核心变换组件,封装了 3D 空间中的位置(position)、旋转(rotation)和缩放(scale)信息。它支持层级变换计算,可以将点或方向从本地空间变换到世界空间,或进行逆变换。
|
||||
|
||||
该结构体设计用于游戏引擎的层级关系系统中,每个 `Transform` 可以通过 `operator*` 与父级 `Transform` 组合,实现累积变换。
|
||||
|
||||
## 结构体成员
|
||||
|
||||
| 成员 | 类型 | 描述 | 默认值 |
|
||||
|------|------|------|--------|
|
||||
| `position` | `Vector3` | 位置 | `Vector3::Zero()` |
|
||||
| `rotation` | `Quaternion` | 旋转(四元数) | `Quaternion::Identity()` |
|
||||
| `scale` | `Vector3` | 缩放 | `Vector3::One()` |
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`ToMatrix`](to-matrix.md) | 将变换转换为 4x4 矩阵 |
|
||||
| [`Inverse`](inverse.md) | 返回变换的逆变换 |
|
||||
| [`operator*`](operator-star.md) | 组合两个变换 |
|
||||
| [`TransformPoint`](transform-point.md) | 变换一个点(考虑位置、旋转和缩放) |
|
||||
| [`TransformDirection`](transform-direction.md) | 变换一个方向(仅考虑旋转和缩放) |
|
||||
| [`InverseTransformPoint`](inverse-transform-point.md) | 逆变换一个点 |
|
||||
| [`InverseTransformDirection`](inverse-transform-direction.md) | 逆变换一个方向 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
enum class Space { Self, World };
|
||||
#include "XCEngine/Math/Transform.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
#include "XCEngine/Math/Quaternion.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
void TransformExample() {
|
||||
Transform parent;
|
||||
parent.position = Vector3(10.0f, 0.0f, 0.0f);
|
||||
parent.rotation = Quaternion::Identity();
|
||||
parent.scale = Vector3(2.0f, 2.0f, 2.0f);
|
||||
|
||||
Transform child;
|
||||
child.position = Vector3(5.0f, 0.0f, 0.0f);
|
||||
child.rotation = Quaternion::Identity();
|
||||
child.scale = Vector3(1.0f, 1.0f, 1.0f);
|
||||
|
||||
Transform combined = parent * child;
|
||||
|
||||
Vector3 localPoint(1.0f, 0.0f, 0.0f);
|
||||
Vector3 worldPoint = combined.TransformPoint(localPoint);
|
||||
|
||||
Vector3 worldDir(0.0f, 1.0f, 0.0f);
|
||||
Vector3 transformedDir = combined.TransformDirection(worldDir);
|
||||
|
||||
Matrix4 mat = combined.ToMatrix();
|
||||
}
|
||||
```
|
||||
|
||||
## 结构体定义
|
||||
|
||||
```cpp
|
||||
struct Transform {
|
||||
Vector3 position = Vector3::Zero();
|
||||
Quaternion rotation = Quaternion::Identity();
|
||||
Vector3 scale = Vector3::One();
|
||||
};
|
||||
```
|
||||
|
||||
## 实例方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [ToMatrix()](tomatrix.md) | `Matrix4` | 转换为 4x4 变换矩阵 |
|
||||
| [Inverse()](inverse.md) | `Transform` | 逆变换 |
|
||||
| `operator*(Transform, Transform)` | `Transform` | 组合变换 |
|
||||
| [TransformPoint(point)](transformpoint.md) | `Vector3` | 变换点(带平移) |
|
||||
| [TransformDirection(direction)](transformdirection.md) | `Vector3` | 变换方向(包含旋转和缩放) |
|
||||
| [InverseTransformPoint(point)](inversetransformpoint.md) | `Vector3` | 逆变换点 |
|
||||
| [InverseTransformDirection(direction)](inversetransformdirection.md) | `Vector3` | 逆变换方向 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Matrix4](../matrix4/matrix4.md) - 4x4 矩阵
|
||||
|
||||
Reference in New Issue
Block a user