Files
XCEngine/docs/api/math/math-vector4.md

63 lines
1.1 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.
# Vector4
4D 向量结构体,用于表示齐次坐标、颜色 (RGBA) 或 SIMD 操作。
## 头文件
```cpp
#include <XCEngine/Math/Vector4.h>
```
## 命名空间
`XCEngine::Math`
## 结构体定义
```cpp
struct Vector4 {
float x = 0.0f;
float y = 0.0f;
float z = 0.0f;
float w = 0.0f;
};
```
## 构造方法
- `Vector4(float x, float y, float z, float w)` - 从四个分量构造
- `explicit Vector4(const Vector3& v, float w = 0.0f)` - 从 Vector3 构造
## 静态工厂方法
| 方法 | 返回值 | 描述 |
|------|--------|------|
| `Zero()` | `Vector4` | 返回 (0, 0, 0, 0) |
| `One()` | `Vector4` | 返回 (1, 1, 1, 1) |
## 静态数学方法
| 方法 | 返回值 | 描述 |
|------|--------|------|
| `Dot(a, b)` | `float` | 4D 点积 |
| `Project(vector, onNormal)` | `Vector4` | 投影 |
## 实例方法
| 方法 | 返回值 | 描述 |
|------|--------|------|
| `ToVector3()` | `Vector3` | 转换到 Vector3丢弃 w |
## 运算符
- 算术: `+`, `-`, `*` (scalar)
- 下标: `operator[]`
- 比较: `==`, `!=`
## 使用示例
```cpp
Vector4 pos4(1.0f, 2.0f, 3.0f, 1.0f);
Vector3 pos3 = pos4.ToVector3();
```