Fix 30+ broken cross-references in docs/api/math/: - viewport: viewport-getaspectratio/getrect -> getaspectratio/getrect - matrix4: ../color/operator-mul -> operator_mul, operator-index -> operator_index - matrix4/get-*: gettranslation/getscale/getrotation -> get-translation/-scale/-rotation - vector3 operator links: operator_*_assign -> operator-*-assign - vector3 operator links: operator_sub/add -> operator-sub/add - vector3 operator-eq/neq: swap mutual references to use hyphen naming - vector4: ../plane/constructor-default -> constructor_default - Linter fixes: aabb and rectint relative paths corrected
72 lines
2.0 KiB
Markdown
72 lines
2.0 KiB
Markdown
# Vector4
|
||
|
||
**命名空间**: `XCEngine::Math`
|
||
|
||
**类型**: `struct`
|
||
|
||
**头文件**: `XCEngine/Math/Vector4.h`
|
||
|
||
**描述**: 四维向量,用于齐次坐标变换和四元数相关计算
|
||
|
||
## 概述
|
||
|
||
Vector4 是四维向量结构体,常用于:
|
||
- 齐次坐标变换(x, y, z, w)
|
||
- RGBA 颜色表示
|
||
- SIMD 矢量操作
|
||
- 四元数分量存储
|
||
|
||
## 结构体成员
|
||
|
||
| 成员 | 类型 | 描述 | 默认值 |
|
||
|------|------|------|--------|
|
||
| `x` | `float` | X 分量 | `0.0f` |
|
||
| `y` | `float` | Y 分量 | `0.0f` |
|
||
| `z` | `float` | Z 分量 | `0.0f` |
|
||
| `w` | `float` | W 分量(齐次坐标) | `0.0f` |
|
||
|
||
## 公共方法
|
||
|
||
| 方法 | 描述 |
|
||
|------|------|
|
||
| [`Vector4()`](constructor_default.md) | 默认构造函数,创建零向量 |
|
||
| [`Vector4(x, y, z, w)`](constructor.md) | 从四个分量构造向量 |
|
||
| [`Vector4(Vector3, w)`](constructor-vector3.md) | 从 Vector3 构造(w 默认 0) |
|
||
| [`Zero`](zero.md) | 返回零向量 (0, 0, 0, 0) |
|
||
| [`One`](one.md) | 返回单位向量 (1, 1, 1, 1) |
|
||
| [`Dot`](dot.md) | 计算两个向量的点积 |
|
||
| [`Project`](project.md) | 将向量投影到法线向量上 |
|
||
| [`ToVector3`](to-vector3.md) | 转换为 Vector3 |
|
||
| [`operator[]`](./operator-brackets.md) | 下标访问分量 |
|
||
| [`operator+`](operator-add.md) | 向量加法 |
|
||
| [`operator-`](operator-sub.md) | 向量减法 |
|
||
| [`operator*`](operator-mul.md) | 向量数乘 |
|
||
| [`operator==`](operator-eq.md) | 相等比较 |
|
||
| [`operator!=`](operator-ne.md) | 不等比较 |
|
||
|
||
## 使用示例
|
||
|
||
```cpp
|
||
#include <XCEngine/Math/Vector4.h>
|
||
#include <XCEngine/Math/Vector3.h>
|
||
#include <cstdio>
|
||
|
||
int main() {
|
||
Vector4 a(1.0f, 2.0f, 3.0f, 4.0f);
|
||
Vector4 b(4.0f, 3.0f, 2.0f, 1.0f);
|
||
|
||
Vector4 sum = a + b;
|
||
Vector4 scaled = a * 2.0f;
|
||
float dot = Vector4::Dot(a, b);
|
||
|
||
Vector4 projected = Vector4::Project(a, Vector4(1.0f, 0.0f, 0.0f, 0.0f));
|
||
Vector3 v3 = a.ToVector3();
|
||
|
||
return 0;
|
||
}
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [Math 模块总览](../math.md) - Math 模块总览
|