68 lines
1.5 KiB
Markdown
68 lines
1.5 KiB
Markdown
# Transform
|
|
|
|
3D 变换结构体,包含位置、旋转和缩放,用于层次化变换。
|
|
|
|
## 头文件
|
|
|
|
```cpp
|
|
#include <XCEngine/Math/Transform.h>
|
|
```
|
|
|
|
## 命名空间
|
|
|
|
`XCEngine::Math`
|
|
|
|
## Space 枚举
|
|
|
|
```cpp
|
|
enum class Space { Self, World };
|
|
```
|
|
|
|
## 结构体定义
|
|
|
|
```cpp
|
|
struct Transform {
|
|
Vector3 position = Vector3::Zero();
|
|
Quaternion rotation = Quaternion::Identity();
|
|
Vector3 scale = Vector3::One();
|
|
};
|
|
```
|
|
|
|
## 实例方法
|
|
|
|
| 方法 | 返回值 | 描述 |
|
|
|------|--------|------|
|
|
| `ToMatrix()` | `Matrix4` | 转换为 4x4 变换矩阵 |
|
|
| `Inverse()` | `Transform` | 逆变换 |
|
|
| `operator*(Transform, Transform)` | `Transform` | 组合变换 |
|
|
|
|
### 空间变换
|
|
|
|
| 方法 | 返回值 | 描述 |
|
|
|------|--------|------|
|
|
| `TransformPoint(point)` | `Vector3` | 变换点(带平移) |
|
|
| `TransformDirection(direction)` | `Vector3` | 变换方向(不带平移) |
|
|
| `InverseTransformPoint(point)` | `Vector3` | 逆变换点 |
|
|
| `InverseTransformDirection(direction)` | `Vector3` | 逆变换方向 |
|
|
|
|
## 使用示例
|
|
|
|
```cpp
|
|
Transform world;
|
|
world.position = Vector3(10.0f, 0.0f, 0.0f);
|
|
world.rotation = Quaternion::Identity();
|
|
world.scale = Vector3::One();
|
|
|
|
Matrix4 matrix = world.ToMatrix();
|
|
|
|
// 组合父子变换
|
|
Transform parent, child;
|
|
parent.position = Vector3(5.0f, 0.0f, 0.0f);
|
|
child.position = Vector3(2.0f, 0.0f, 0.0f);
|
|
Transform worldTransform = parent * child;
|
|
|
|
// 变换点
|
|
Vector3 localPos(1.0f, 0.0f, 0.0f);
|
|
Vector3 worldPos = world.TransformPoint(localPos);
|
|
```
|