2026-03-18 17:49:22 +08:00
|
|
|
|
# Vector4
|
|
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
**命名空间**: `XCEngine::Math`
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
**类型**: `struct`
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
**头文件**: `XCEngine/Math/Vector4.h`
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
**描述**: 四维向量,用于齐次坐标变换和四元数相关计算
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
## 概述
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
Vector4 是四维向量结构体,常用于:
|
|
|
|
|
|
- 齐次坐标变换(x, y, z, w)
|
|
|
|
|
|
- RGBA 颜色表示
|
|
|
|
|
|
- SIMD 矢量操作
|
|
|
|
|
|
- 四元数分量存储
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
## 结构体成员
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
| 成员 | 类型 | 描述 | 默认值 |
|
|
|
|
|
|
|------|------|------|--------|
|
|
|
|
|
|
| `x` | `float` | X 分量 | `0.0f` |
|
|
|
|
|
|
| `y` | `float` | Y 分量 | `0.0f` |
|
|
|
|
|
|
| `z` | `float` | Z 分量 | `0.0f` |
|
|
|
|
|
|
| `w` | `float` | W 分量(齐次坐标) | `0.0f` |
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
## 公共方法
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
| 方法 | 描述 |
|
|
|
|
|
|
|------|------|
|
docs: fix naming conventions across threading, math, memory, core, and debug modules
threading/:
- Rename 19 camelCase method files to hyphenated names
- task-system: createtaskgroup→create-task-group, etc.
- tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc.
- thread: getcurrentid→get-current-id, etc.
- task: addref→add-ref, getid→get-id, etc.
math/:
- Rename underscore operator files to hyphenated
- vector3: operator_add→operator-add, etc.
- matrix4: gettranslation→get-translation, etc.
- vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3
- sphere: sphere_constructor→sphere-constructor, etc.
memory/:
- Remove duplicate memorymanager/ folder (kept manager/ which was correct)
core/:
- filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md
- Rename dtor.md→destructor.md
debug/:
- filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md
All overview pages updated with new file references.
2026-03-22 23:09:29 +08:00
|
|
|
|
| [`Vector4()`](constructor-default.md) | 默认构造函数,创建零向量 |
|
2026-03-20 02:35:15 +08:00
|
|
|
|
| [`Vector4(x, y, z, w)`](constructor.md) | 从四个分量构造向量 |
|
docs: fix naming conventions across threading, math, memory, core, and debug modules
threading/:
- Rename 19 camelCase method files to hyphenated names
- task-system: createtaskgroup→create-task-group, etc.
- tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc.
- thread: getcurrentid→get-current-id, etc.
- task: addref→add-ref, getid→get-id, etc.
math/:
- Rename underscore operator files to hyphenated
- vector3: operator_add→operator-add, etc.
- matrix4: gettranslation→get-translation, etc.
- vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3
- sphere: sphere_constructor→sphere-constructor, etc.
memory/:
- Remove duplicate memorymanager/ folder (kept manager/ which was correct)
core/:
- filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md
- Rename dtor.md→destructor.md
debug/:
- filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md
All overview pages updated with new file references.
2026-03-22 23:09:29 +08:00
|
|
|
|
| [`Vector4(Vector3, w)`](constructor-vector3.md) | 从 Vector3 构造(w 默认 0) |
|
2026-03-20 02:35:15 +08:00
|
|
|
|
| [`Zero`](zero.md) | 返回零向量 (0, 0, 0, 0) |
|
|
|
|
|
|
| [`One`](one.md) | 返回单位向量 (1, 1, 1, 1) |
|
|
|
|
|
|
| [`Dot`](dot.md) | 计算两个向量的点积 |
|
|
|
|
|
|
| [`Project`](project.md) | 将向量投影到法线向量上 |
|
docs: fix naming conventions across threading, math, memory, core, and debug modules
threading/:
- Rename 19 camelCase method files to hyphenated names
- task-system: createtaskgroup→create-task-group, etc.
- tasksystemconfig: enabletaskprofiling→enable-task-profiling, etc.
- thread: getcurrentid→get-current-id, etc.
- task: addref→add-ref, getid→get-id, etc.
math/:
- Rename underscore operator files to hyphenated
- vector3: operator_add→operator-add, etc.
- matrix4: gettranslation→get-translation, etc.
- vector4: tovector3→to-vector3, constructor_vector3→constructor-vector3
- sphere: sphere_constructor→sphere-constructor, etc.
memory/:
- Remove duplicate memorymanager/ folder (kept manager/ which was correct)
core/:
- filewriter: Consolidate ctor-default.md and ctor-file.md into constructor.md
- Rename dtor.md→destructor.md
debug/:
- filelogsink: Rename construct.md→constructor.md, ~filelogsink.md→destructor.md
All overview pages updated with new file references.
2026-03-22 23:09:29 +08:00
|
|
|
|
| [`ToVector3`](to-vector3.md) | 转换为 Vector3 |
|
2026-03-20 02:35:15 +08:00
|
|
|
|
| [`operator[]`](./operator-brackets.md) | 下标访问分量 |
|
|
|
|
|
|
| [`operator+`](operator-add.md) | 向量加法 |
|
|
|
|
|
|
| [`operator-`](operator-sub.md) | 向量减法 |
|
|
|
|
|
|
| [`operator*`](operator-mul.md) | 向量数乘 |
|
|
|
|
|
|
| [`operator==`](operator-eq.md) | 相等比较 |
|
|
|
|
|
|
| [`operator!=`](operator-ne.md) | 不等比较 |
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
## 使用示例
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
```cpp
|
|
|
|
|
|
#include <XCEngine/Math/Vector4.h>
|
|
|
|
|
|
#include <XCEngine/Math/Vector3.h>
|
|
|
|
|
|
#include <cstdio>
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
int main() {
|
|
|
|
|
|
Vector4 a(1.0f, 2.0f, 3.0f, 4.0f);
|
|
|
|
|
|
Vector4 b(4.0f, 3.0f, 2.0f, 1.0f);
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
Vector4 sum = a + b;
|
|
|
|
|
|
Vector4 scaled = a * 2.0f;
|
|
|
|
|
|
float dot = Vector4::Dot(a, b);
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
Vector4 projected = Vector4::Project(a, Vector4(1.0f, 0.0f, 0.0f, 0.0f));
|
|
|
|
|
|
Vector3 v3 = a.ToVector3();
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
docs: 重构 API 文档结构并修正源码准确性
- 重组文档目录结构: 每个模块的概述页移动到模块子目录
- 重命名 index.md 为 main.md
- 修正所有模块文档中的错误:
- math: FromEuler→FromEulerAngles, TransformDirection 包含缩放, Box 是 OBB, Color::ToRGBA 格式
- containers: 新增 operator==/!= 文档, 补充 std::hash DJB 算法细节
- core: 修复 types 链接错误
- debug: LogLevelToString 返回大写, timestamp 是秒, Profiler 空实现标注, Windows API vs ANSI
- memory: 修复头文件路径, malloc vs operator new, 新增方法文档
- resources: 修复 Shader/Texture 链接错误
- threading: TaskSystem::Wait 空实现标注, ReadWriteLock 重入描述, LambdaTask 链接
- 验证: fix_links.py 确认 0 个断裂引用
2026-03-19 00:22:30 +08:00
|
|
|
|
## 相关文档
|
2026-03-18 17:49:22 +08:00
|
|
|
|
|
2026-03-20 02:35:15 +08:00
|
|
|
|
- [Math 模块总览](../math.md) - Math 模块总览
|