Update API documentation and remove obsolete plan files
This commit is contained in:
@@ -58,7 +58,7 @@ using namespace XCEngine::Math;
|
||||
void MatrixExample() {
|
||||
Matrix4 mat = Matrix4::TRS(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Quaternion::FromEuler(0.0f, 90.0f, 0.0f),
|
||||
Quaternion::FromEulerAngles(0.0f, 90.0f, 0.0f),
|
||||
Vector3(1.5f, 1.5f, 1.5f)
|
||||
);
|
||||
|
||||
|
||||
@@ -65,5 +65,5 @@ struct Rect {
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Rect 模块总览
|
||||
- [RectInt](rectint.md) - 整数矩形版本
|
||||
- [Viewport](viewport.md) - 渲染视口
|
||||
- [RectInt](../rectint/rectint.md) - 整数矩形版本
|
||||
- [Viewport](../viewport/viewport.md) - 渲染视口
|
||||
|
||||
@@ -76,6 +76,6 @@ int main() {
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt`](rectint.md) - 整数矩形
|
||||
- [`Viewport`](viewport.md) - 视口
|
||||
- [`RectInt`](../rectint/rectint.md) - 整数矩形
|
||||
- [`Viewport`](../viewport/viewport.md) - 视口
|
||||
- [`Vector2`](../vector2/vector2.md) - 二维向量
|
||||
@@ -1,24 +0,0 @@
|
||||
# RectInt::Contains
|
||||
|
||||
```cpp
|
||||
bool Contains(int32_t px, int32_t py) const
|
||||
```
|
||||
|
||||
检测整数坐标点是否在矩形内。
|
||||
|
||||
**参数:**
|
||||
- `px` - 点的 x 坐标
|
||||
- `py` - 点的 y 坐标
|
||||
|
||||
**返回:** `bool` - 点在矩形内(包含边界)返回 true
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rect(0, 0, 1920, 1080);
|
||||
if (rect.Contains(pixelX, pixelY)) {
|
||||
// 像素在矩形内
|
||||
}
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# RectInt::GetBottom
|
||||
|
||||
```cpp
|
||||
int32_t GetBottom() const
|
||||
```
|
||||
|
||||
获取矩形下边界。
|
||||
|
||||
**返回:** `int32_t` - 下边界坐标 (y + height)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t bottom = rect.GetBottom(); // 70
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# RectInt::GetCenter
|
||||
|
||||
```cpp
|
||||
Vector2 GetCenter() const
|
||||
```
|
||||
|
||||
获取矩形中心点(转换为浮点)。
|
||||
|
||||
**返回:** `Vector2` - 中心点坐标
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 center = rect.GetCenter(); // (60.0f, 45.0f)
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# RectInt::GetLeft
|
||||
|
||||
```cpp
|
||||
int32_t GetLeft() const
|
||||
```
|
||||
|
||||
获取矩形左边界。
|
||||
|
||||
**返回:** `int32_t` - 左边界坐标 (x)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t left = rect.GetLeft(); // 10
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# RectInt::GetPosition
|
||||
|
||||
```cpp
|
||||
Vector2 GetPosition() const
|
||||
```
|
||||
|
||||
获取矩形左上角位置(转换为浮点)。
|
||||
|
||||
**返回:** `Vector2` - 位置向量
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 pos = rect.GetPosition(); // (10.0f, 20.0f)
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# RectInt::GetRight
|
||||
|
||||
```cpp
|
||||
int32_t GetRight() const
|
||||
```
|
||||
|
||||
获取矩形右边界。
|
||||
|
||||
**返回:** `int32_t` - 右边界坐标 (x + width)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t right = rect.GetRight(); // 110
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# RectInt::GetSize
|
||||
|
||||
```cpp
|
||||
Vector2 GetSize() const
|
||||
```
|
||||
|
||||
获取矩形尺寸(转换为浮点)。
|
||||
|
||||
**返回:** `Vector2` - 尺寸向量
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 size = rect.GetSize(); // (100.0f, 50.0f)
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# RectInt::GetTop
|
||||
|
||||
```cpp
|
||||
int32_t GetTop() const
|
||||
```
|
||||
|
||||
获取矩形上边界。
|
||||
|
||||
**返回:** `int32_t` - 上边界坐标 (y)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t top = rect.GetTop(); // 20
|
||||
```
|
||||
@@ -1,24 +0,0 @@
|
||||
# RectInt::Intersects
|
||||
|
||||
```cpp
|
||||
bool Intersects(const RectInt& other) const
|
||||
```
|
||||
|
||||
检测两整数矩形是否相交。
|
||||
|
||||
**参数:**
|
||||
- `other` - 另一个整数矩形
|
||||
|
||||
**返回:** `bool` - 两矩形相交返回 true
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
RectInt rectA(0, 0, 100, 100);
|
||||
RectInt rectB(50, 50, 100, 100);
|
||||
if (rectA.Intersects(rectB)) {
|
||||
// 两矩形相交
|
||||
}
|
||||
```
|
||||
@@ -1,53 +0,0 @@
|
||||
# RectInt
|
||||
|
||||
整数矩形结构体,用于像素级 2D 区域表示。
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Rect.h>`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
|
||||
## 结构体定义
|
||||
|
||||
```cpp
|
||||
struct RectInt {
|
||||
int32_t x = 0;
|
||||
int32_t y = 0;
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
|
||||
RectInt() = default;
|
||||
RectInt(int32_t x, int32_t y, int32_t w, int32_t h);
|
||||
};
|
||||
```
|
||||
|
||||
## 构造函数
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `RectInt()` | 默认构造 |
|
||||
| `RectInt(x, y, w, h)` | 从整数坐标和尺寸构造 |
|
||||
|
||||
## 边界访问
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [GetLeft()](rectint-getleft.md) | `int32_t` | 左边界 |
|
||||
| [GetRight()](rectint-getright.md) | `int32_t` | 右边界 |
|
||||
| [GetTop()](rectint-gettop.md) | `int32_t` | 上边界 |
|
||||
| [GetBottom()](rectint-getbottom.md) | `int32_t` | 下边界 |
|
||||
| [GetPosition()](rectint-getposition.md) | `Vector2` | 位置(转换为浮点) |
|
||||
| [GetSize()](rectint-getsize.md) | `Vector2` | 尺寸(转换为浮点) |
|
||||
| [GetCenter()](rectint-getcenter.md) | `Vector2` | 中心点 |
|
||||
|
||||
## 检测方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Contains(px, py)](rectint-contains.md) | `bool` | 整数坐标点检测 |
|
||||
| [Intersects(other)](rectint-intersects.md) | `bool` | 与另一矩形相交 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Rect 模块总览
|
||||
- [Rect](rect-overview.md) - 浮点矩形版本
|
||||
- [Viewport](viewport.md) - 渲染视口
|
||||
@@ -1,18 +0,0 @@
|
||||
# Viewport::GetAspectRatio
|
||||
|
||||
```cpp
|
||||
float GetAspectRatio() const
|
||||
```
|
||||
|
||||
获取视口宽高比。
|
||||
|
||||
**返回:** `float` - 宽高比 (width / height),height 为 0 时返回 0.0f
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Viewport viewport(0, 0, 1920, 1080);
|
||||
float aspect = viewport.GetAspectRatio(); // 1.777... (16:9)
|
||||
```
|
||||
@@ -1,18 +0,0 @@
|
||||
# Viewport::GetRect
|
||||
|
||||
```cpp
|
||||
Rect GetRect() const
|
||||
```
|
||||
|
||||
将视口转换为 Rect。
|
||||
|
||||
**返回:** `Rect` - 对应的矩形 (x, y, width, height),不包含深度范围
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Viewport viewport(0, 0, 1920, 1080, 0.0f, 1.0f);
|
||||
Rect rect = viewport.GetRect(); // (0, 0, 1920, 1080)
|
||||
```
|
||||
@@ -1,45 +0,0 @@
|
||||
# Viewport
|
||||
|
||||
渲染视口结构体,用于屏幕到归一化坐标的映射。
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Rect.h>`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
|
||||
## 结构体定义
|
||||
|
||||
```cpp
|
||||
struct Viewport {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float width = 0.0f;
|
||||
float height = 0.0f;
|
||||
float minDepth = 0.0f;
|
||||
float maxDepth = 1.0f;
|
||||
|
||||
Viewport() = default;
|
||||
Viewport(float x, float y, float w, float h);
|
||||
Viewport(float x, float y, float w, float h, float minD, float maxD);
|
||||
};
|
||||
```
|
||||
|
||||
## 构造函数
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `Viewport()` | 默认构造 |
|
||||
| `Viewport(x, y, w, h)` | 2D 视口 |
|
||||
| `Viewport(x, y, w, h, minD, maxD)` | 带深度范围的 3D 视口 |
|
||||
|
||||
## 方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [GetAspectRatio()](viewport-getaspectratio.md) | `float` | 宽高比 (width / height) |
|
||||
| [GetRect()](viewport-getrect.md) | `Rect` | 转换为 Rect |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Rect](rect-overview.md) - 浮点矩形
|
||||
- [RectInt](rectint.md) - 整数矩形
|
||||
@@ -1,47 +1,24 @@
|
||||
# RectInt::Contains
|
||||
|
||||
```cpp
|
||||
bool Contains(int32_t px, int32_t py) const;
|
||||
bool Contains(int32_t px, int32_t py) const
|
||||
```
|
||||
|
||||
判断整数坐标点是否在矩形内部。
|
||||
|
||||
矩形使用左上位坐标系,内部定义为:x >= left && x < right && y >= top && y < bottom。即左边界和上边界在内部,右边界和下边界在外部。
|
||||
检测整数坐标点是否在矩形内。
|
||||
|
||||
**参数:**
|
||||
- `px` - 点的 x 坐标
|
||||
- `py` - 点的 y 坐标
|
||||
|
||||
**返回:** 点在矩形内部返回 true,否则返回 false
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `bool` - 点在矩形内(包含边界)返回 true
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(0, 0, 1920, 1080);
|
||||
|
||||
if (rect.Contains(960, 540)) {
|
||||
std::cout << "Point (960, 540) is inside\n";
|
||||
}
|
||||
|
||||
if (!rect.Contains(2000, 1000)) {
|
||||
std::cout << "Point (2000, 1000) is outside\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
RectInt rect(0, 0, 1920, 1080);
|
||||
if (rect.Contains(pixelX, pixelY)) {
|
||||
// 像素在矩形内
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::Intersects`](intersects.md) - 判断是否相交
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,36 +1,18 @@
|
||||
# RectInt::GetBottom
|
||||
|
||||
```cpp
|
||||
int32_t GetBottom() const;
|
||||
int32_t GetBottom() const
|
||||
```
|
||||
|
||||
获取矩形下边界 y 坐标。
|
||||
获取矩形下边界。
|
||||
|
||||
**返回:** 矩形下边界 y 坐标(等于 y + height)
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `int32_t` - 下边界坐标 (y + height)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t bottom = rect.GetBottom();
|
||||
std::cout << "Bottom: " << bottom << "\n";
|
||||
return 0;
|
||||
}
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t bottom = rect.GetBottom(); // 70
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetLeft`](getleft.md) - 获取左边界
|
||||
- [`RectInt::GetRight`](getright.md) - 获取右边界
|
||||
- [`RectInt::GetTop`](gettop.md) - 获取上边界
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,35 +1,18 @@
|
||||
# RectInt::GetCenter
|
||||
|
||||
```cpp
|
||||
Vector2 GetCenter() const;
|
||||
Vector2 GetCenter() const
|
||||
```
|
||||
|
||||
获取矩形中心点坐标。
|
||||
获取矩形中心点(转换为浮点)。
|
||||
|
||||
**返回:** 表示矩形中心点的 Vector2(转换为浮点)
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `Vector2` - 中心点坐标
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 center = rect.GetCenter();
|
||||
std::cout << "Center: (" << center.x << ", " << center.y << ")\n";
|
||||
return 0;
|
||||
}
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 center = rect.GetCenter(); // (60.0f, 45.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetPosition`](getposition.md) - 获取位置
|
||||
- [`RectInt::GetSize`](getsize.md) - 获取尺寸
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,36 +1,18 @@
|
||||
# RectInt::GetLeft
|
||||
|
||||
```cpp
|
||||
int32_t GetLeft() const;
|
||||
int32_t GetLeft() const
|
||||
```
|
||||
|
||||
获取矩形左边界 x 坐标。
|
||||
获取矩形左边界。
|
||||
|
||||
**返回:** 矩形左边界 x 坐标(等于 x 成员变量)
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `int32_t` - 左边界坐标 (x)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t left = rect.GetLeft();
|
||||
std::cout << "Left: " << left << "\n";
|
||||
return 0;
|
||||
}
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t left = rect.GetLeft(); // 10
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetRight`](getright.md) - 获取右边界
|
||||
- [`RectInt::GetTop`](gettop.md) - 获取上边界
|
||||
- [`RectInt::GetBottom`](getbottom.md) - 获取下边界
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,35 +1,18 @@
|
||||
# RectInt::GetPosition
|
||||
|
||||
```cpp
|
||||
Vector2 GetPosition() const;
|
||||
Vector2 GetPosition() const
|
||||
```
|
||||
|
||||
获取矩形位置(x, y 坐标)。
|
||||
获取矩形左上角位置(转换为浮点)。
|
||||
|
||||
**返回:** 表示矩形位置的 Vector2(转换为浮点)
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `Vector2` - 位置向量
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 pos = rect.GetPosition();
|
||||
std::cout << "Position: (" << pos.x << ", " << pos.y << ")\n";
|
||||
return 0;
|
||||
}
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 pos = rect.GetPosition(); // (10.0f, 20.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetSize`](getsize.md) - 获取尺寸
|
||||
- [`RectInt::GetCenter`](getcenter.md) - 获取中心点
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,36 +1,18 @@
|
||||
# RectInt::GetRight
|
||||
|
||||
```cpp
|
||||
int32_t GetRight() const;
|
||||
int32_t GetRight() const
|
||||
```
|
||||
|
||||
获取矩形右边界 x 坐标。
|
||||
获取矩形右边界。
|
||||
|
||||
**返回:** 矩形右边界 x 坐标(等于 x + width)
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `int32_t` - 右边界坐标 (x + width)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t right = rect.GetRight();
|
||||
std::cout << "Right: " << right << "\n";
|
||||
return 0;
|
||||
}
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t right = rect.GetRight(); // 110
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetLeft`](getleft.md) - 获取左边界
|
||||
- [`RectInt::GetTop`](gettop.md) - 获取上边界
|
||||
- [`RectInt::GetBottom`](getbottom.md) - 获取下边界
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,35 +1,18 @@
|
||||
# RectInt::GetSize
|
||||
|
||||
```cpp
|
||||
Vector2 GetSize() const;
|
||||
Vector2 GetSize() const
|
||||
```
|
||||
|
||||
获取矩形尺寸(width, height)。
|
||||
获取矩形尺寸(转换为浮点)。
|
||||
|
||||
**返回:** 表示矩形尺寸的 Vector2(转换为浮点)
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `Vector2` - 尺寸向量
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 size = rect.GetSize();
|
||||
std::cout << "Size: (" << size.x << ", " << size.y << ")\n";
|
||||
return 0;
|
||||
}
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
Vector2 size = rect.GetSize(); // (100.0f, 50.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetPosition`](getposition.md) - 获取位置
|
||||
- [`RectInt::GetCenter`](getcenter.md) - 获取中心点
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,36 +1,18 @@
|
||||
# RectInt::GetTop
|
||||
|
||||
```cpp
|
||||
int32_t GetTop() const;
|
||||
int32_t GetTop() const
|
||||
```
|
||||
|
||||
获取矩形上边界 y 坐标。
|
||||
获取矩形上边界。
|
||||
|
||||
**返回:** 矩形上边界 y 坐标(等于 y 成员变量)
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `int32_t` - 上边界坐标 (y)
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t top = rect.GetTop();
|
||||
std::cout << "Top: " << top << "\n";
|
||||
return 0;
|
||||
}
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
int32_t top = rect.GetTop(); // 20
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::GetLeft`](getleft.md) - 获取左边界
|
||||
- [`RectInt::GetRight`](getright.md) - 获取右边界
|
||||
- [`RectInt::GetBottom`](getbottom.md) - 获取下边界
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,48 +1,24 @@
|
||||
# RectInt::Intersects
|
||||
|
||||
```cpp
|
||||
bool Intersects(const RectInt& other) const;
|
||||
bool Intersects(const RectInt& other) const
|
||||
```
|
||||
|
||||
判断此矩形是否与另一矩形相交。
|
||||
|
||||
使用 AABB(轴对齐包围盒)碰撞检测算法。如果两个矩形在 x 轴和 y 轴上都有重叠,则返回 true。
|
||||
检测两整数矩形是否相交。
|
||||
|
||||
**参数:**
|
||||
- `other` - 另一个矩形
|
||||
- `other` - 另一个整数矩形
|
||||
|
||||
**返回:** 两矩形相交返回 true,否则返回 false
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `bool` - 两矩形相交返回 true
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
RectInt rectA(0, 0, 100, 100);
|
||||
RectInt rectB(50, 50, 100, 100);
|
||||
|
||||
if (rectA.Intersects(rectB)) {
|
||||
std::cout << "Rects intersect\n";
|
||||
}
|
||||
|
||||
RectInt rectC(200, 200, 50, 50);
|
||||
if (!rectA.Intersects(rectC)) {
|
||||
std::cout << "Rects do not intersect\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
RectInt rectA(0, 0, 100, 100);
|
||||
RectInt rectB(50, 50, 100, 100);
|
||||
if (rectA.Intersects(rectB)) {
|
||||
// 两矩形相交
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`RectInt::Contains`](contains.md) - 判断点是否在矩形内
|
||||
- [RectInt 总览](rectint.md)
|
||||
@@ -1,63 +1,53 @@
|
||||
# RectInt
|
||||
|
||||
**命名空间**: `XCEngine::Math`
|
||||
整数矩形结构体,用于像素级 2D 区域表示。
|
||||
|
||||
**类型**: `struct`
|
||||
**头文件:** `#include <XCEngine/Math/Rect.h>`
|
||||
|
||||
**头文件**: `XCEngine/Math/Rect.h`
|
||||
**命名空间:** `XCEngine::Math`
|
||||
|
||||
**描述**: 二维整数矩形,用于表示像素级 2D 区域
|
||||
## 结构体定义
|
||||
|
||||
## 概述
|
||||
```cpp
|
||||
struct RectInt {
|
||||
int32_t x = 0;
|
||||
int32_t y = 0;
|
||||
int32_t width = 0;
|
||||
int32_t height = 0;
|
||||
|
||||
RectInt 结构体表示一个二维整数矩形,由整数位置 `(x, y)` 和尺寸 `(width, height)` 组成。与 Rect 不同,它使用 `int32_t` 类型,适合像素级操作和坐标计算。
|
||||
RectInt() = default;
|
||||
RectInt(int32_t x, int32_t y, int32_t w, int32_t h);
|
||||
};
|
||||
```
|
||||
|
||||
## 公共方法
|
||||
## 构造函数
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`GetLeft`](getleft.md) | 获取矩形左边界 |
|
||||
| [`GetRight`](getright.md) | 获取矩形右边界 |
|
||||
| [`GetTop`](gettop.md) | 获取矩形上边界 |
|
||||
| [`GetBottom`](getbottom.md) | 获取矩形下边界 |
|
||||
| [`GetPosition`](getposition.md) | 获取矩形位置 |
|
||||
| [`GetSize`](getsize.md) | 获取矩形尺寸 |
|
||||
| [`GetCenter`](getcenter.md) | 获取矩形中心点 |
|
||||
| [`Contains`](contains.md) | 判断点是否在矩形内 |
|
||||
| [`Intersects`](intersects.md) | 判断是否与另一矩形相交 |
|
||||
| `RectInt()` | 默认构造 |
|
||||
| `RectInt(x, y, w, h)` | 从整数坐标和尺寸构造 |
|
||||
|
||||
## 使用示例
|
||||
## 边界访问
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include "XCEngine/Math/Vector2.h"
|
||||
#include <iostream>
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [GetLeft()](rectint-getleft.md) | `int32_t` | 左边界 |
|
||||
| [GetRight()](rectint-getright.md) | `int32_t` | 右边界 |
|
||||
| [GetTop()](rectint-gettop.md) | `int32_t` | 上边界 |
|
||||
| [GetBottom()](rectint-getbottom.md) | `int32_t` | 下边界 |
|
||||
| [GetPosition()](rectint-getposition.md) | `Vector2` | 位置(转换为浮点) |
|
||||
| [GetSize()](rectint-getsize.md) | `Vector2` | 尺寸(转换为浮点) |
|
||||
| [GetCenter()](rectint-getcenter.md) | `Vector2` | 中心点 |
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
## 检测方法
|
||||
|
||||
int main() {
|
||||
RectInt rect(10, 20, 100, 50);
|
||||
|
||||
std::cout << "Position: (" << rect.x << ", " << rect.y << ")\n";
|
||||
std::cout << "Size: " << rect.width << " x " << rect.height << "\n";
|
||||
std::cout << "Left: " << rect.GetLeft() << ", Right: " << rect.GetRight() << "\n";
|
||||
std::cout << "Top: " << rect.GetTop() << ", Bottom: " << rect.GetBottom() << "\n";
|
||||
|
||||
if (rect.Contains(50, 30)) {
|
||||
std::cout << "Point (50, 30) is inside rect\n";
|
||||
}
|
||||
|
||||
RectInt other(60, 40, 100, 50);
|
||||
if (rect.Intersects(other)) {
|
||||
std::cout << "Rects intersect\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Contains(px, py)](rectint-contains.md) | `bool` | 整数坐标点检测 |
|
||||
| [Intersects(other)](rectint-intersects.md) | `bool` | 与另一矩形相交 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`Rect`](../rect/rect.md) - 浮点矩形
|
||||
- [`Viewport`](../rect/viewport.md) - 视口
|
||||
- [`Vector2`](../vector2/vector2.md) - 二维向量
|
||||
- [Math 模块总览](../math.md) - 返回 Rect 模块总览
|
||||
- [Rect](rect-overview.md) - 浮点矩形版本
|
||||
- [Viewport](viewport.md) - 渲染视口
|
||||
|
||||
40
docs/api/math/transform/space.md
Normal file
40
docs/api/math/transform/space.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Transform::Space
|
||||
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**类型**: `enum class`
|
||||
|
||||
**头文件**: `XCEngine/Math/Transform.h`
|
||||
|
||||
## 概述
|
||||
|
||||
`Space` 枚举用于指定变换操作的参考空间。
|
||||
|
||||
## 枚举值
|
||||
|
||||
| 枚举值 | 数值 | 描述 |
|
||||
|--------|------|------|
|
||||
| `Self` | `0` | 相对于自身空间进行变换 |
|
||||
| `World` | `1` | 相对于世界空间进行变换 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Transform.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Transform transform;
|
||||
transform.position = Vector3(10.0f, 0.0f, 0.0f);
|
||||
|
||||
// 在自身空间旋转
|
||||
// transform.Rotate(Vector3::Up(), 45.0f * DEG_TO_RAD, Space::Self);
|
||||
|
||||
// 在世界空间旋转
|
||||
// transform.Rotate(Vector3::Up(), 45.0f * DEG_TO_RAD, Space::World);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Transform 总览](transform.md) - Transform 类总览
|
||||
@@ -34,6 +34,12 @@
|
||||
| [`InverseTransformPoint`](inverse-transform-point.md) | 逆变换一个点 |
|
||||
| [`InverseTransformDirection`](inverse-transform-direction.md) | 逆变换一个方向 |
|
||||
|
||||
## 枚举
|
||||
|
||||
| 枚举 | 描述 |
|
||||
|------|------|
|
||||
| [`Space`](space.md) | 变换参考空间(Self 或 World) |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
|
||||
29
docs/api/math/vector2/operator-add-assign.md
Normal file
29
docs/api/math/vector2/operator-add-assign.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector2::operator+=
|
||||
|
||||
```cpp
|
||||
Vector2& operator+=(const Vector2& other)
|
||||
```
|
||||
|
||||
向量加法赋值,将 `other` 的分量加到当前向量。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要加的向量
|
||||
|
||||
**返回:** `Vector2&` - 引用到修改后的当前向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 v(1.0f, 2.0f);
|
||||
v += Vector2(3.0f, 4.0f); // v = (4.0f, 6.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator+`](operator-add.md) - 加法
|
||||
- [`operator-=`](operator-sub-assign.md) - 减法赋值
|
||||
30
docs/api/math/vector2/operator-add.md
Normal file
30
docs/api/math/vector2/operator-add.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Vector2::operator+
|
||||
|
||||
```cpp
|
||||
Vector2 operator+(const Vector2& other) const
|
||||
```
|
||||
|
||||
向量加法,将当前向量与另一个向量相加。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要相加的向量
|
||||
|
||||
**返回:** `Vector2` - 相加结果向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 a(1.0f, 2.0f);
|
||||
Vector2 b(3.0f, 4.0f);
|
||||
Vector2 c = a + b; // (4.0f, 6.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator-`](operator-sub.md) - 减法
|
||||
- [`operator+=`](operator-add-assign.md) - 加法赋值
|
||||
29
docs/api/math/vector2/operator-div-assign.md
Normal file
29
docs/api/math/vector2/operator-div-assign.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector2::operator/=
|
||||
|
||||
```cpp
|
||||
Vector2& operator/=(float scalar)
|
||||
```
|
||||
|
||||
向量除法赋值,将当前向量除以标量。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量值(不能为零)
|
||||
|
||||
**返回:** `Vector2&` - 引用到修改后的当前向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 v(4.0f, 6.0f);
|
||||
v /= 2.0f; // v = (2.0f, 3.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator/`](operator-div.md) - 除法
|
||||
- [`operator*=`](operator-mul-assign.md) - 乘法赋值
|
||||
29
docs/api/math/vector2/operator-div.md
Normal file
29
docs/api/math/vector2/operator-div.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector2::operator/
|
||||
|
||||
```cpp
|
||||
Vector2 operator/(float scalar) const
|
||||
```
|
||||
|
||||
向量数除,将向量除以标量。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量值(不能为零)
|
||||
|
||||
**返回:** `Vector2` - 缩放后的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 v(4.0f, 6.0f);
|
||||
Vector2 result = v / 2.0f; // (2.0f, 3.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator*`](operator-mul.md) - 乘法
|
||||
- [`operator/=`](operator-div-assign.md) - 除法赋值
|
||||
29
docs/api/math/vector2/operator-eq.md
Normal file
29
docs/api/math/vector2/operator-eq.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector2::operator==
|
||||
|
||||
```cpp
|
||||
bool operator==(const Vector2& other) const
|
||||
```
|
||||
|
||||
判断两个向量是否相等。使用 EPSILON 进行浮点比较。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要比较的向量
|
||||
|
||||
**返回:** `bool` - 如果所有分量差的绝对值都小于 EPSILON 则返回 true
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 a(1.0f, 2.0f);
|
||||
Vector2 b(1.0f, 2.0f);
|
||||
bool equal = (a == b); // true
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator!=`](operator-neq.md) - 不等比较
|
||||
29
docs/api/math/vector2/operator-mul-assign.md
Normal file
29
docs/api/math/vector2/operator-mul-assign.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector2::operator*=
|
||||
|
||||
```cpp
|
||||
Vector2& operator*=(float scalar)
|
||||
```
|
||||
|
||||
向量乘法赋值,将当前向量乘以标量。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量值
|
||||
|
||||
**返回:** `Vector2&` - 引用到修改后的当前向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 v(2.0f, 3.0f);
|
||||
v *= 2.0f; // v = (4.0f, 6.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator*`](operator-mul.md) - 乘法
|
||||
- [`operator/=`](operator-div-assign.md) - 除法赋值
|
||||
29
docs/api/math/vector2/operator-mul.md
Normal file
29
docs/api/math/vector2/operator-mul.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector2::operator*
|
||||
|
||||
```cpp
|
||||
Vector2 operator*(float scalar) const
|
||||
```
|
||||
|
||||
向量数乘,将向量与标量相乘。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量值
|
||||
|
||||
**返回:** `Vector2` - 缩放后的向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 v(2.0f, 3.0f);
|
||||
Vector2 scaled = v * 2.0f; // (4.0f, 6.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator/`](operator-div.md) - 除法
|
||||
- [`operator*=`](operator-mul-assign.md) - 乘法赋值
|
||||
29
docs/api/math/vector2/operator-neq.md
Normal file
29
docs/api/math/vector2/operator-neq.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector2::operator!=
|
||||
|
||||
```cpp
|
||||
bool operator!=(const Vector2& other) const
|
||||
```
|
||||
|
||||
判断两个向量是否不相等。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要比较的向量
|
||||
|
||||
**返回:** `bool` - 如果任何分量差的绝对值大于等于 EPSILON 则返回 true
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 a(1.0f, 2.0f);
|
||||
Vector2 b(3.0f, 4.0f);
|
||||
bool notEqual = (a != b); // true
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator==`](operator-eq.md) - 相等比较
|
||||
29
docs/api/math/vector2/operator-sub-assign.md
Normal file
29
docs/api/math/vector2/operator-sub-assign.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Vector2::operator-=
|
||||
|
||||
```cpp
|
||||
Vector2& operator-=(const Vector2& other)
|
||||
```
|
||||
|
||||
向量减法赋值,将 `other` 的分量从当前向量减去。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要减的向量
|
||||
|
||||
**返回:** `Vector2&` - 引用到修改后的当前向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 v(5.0f, 8.0f);
|
||||
v -= Vector2(2.0f, 3.0f); // v = (3.0f, 5.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator-`](operator-sub.md) - 减法
|
||||
- [`operator+=`](operator-add-assign.md) - 加法赋值
|
||||
30
docs/api/math/vector2/operator-sub.md
Normal file
30
docs/api/math/vector2/operator-sub.md
Normal file
@@ -0,0 +1,30 @@
|
||||
# Vector2::operator-
|
||||
|
||||
```cpp
|
||||
Vector2 operator-(const Vector2& other) const
|
||||
```
|
||||
|
||||
向量减法,将当前向量减去另一个向量。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要减去的向量
|
||||
|
||||
**返回:** `Vector2` - 相减结果向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector2 a(5.0f, 8.0f);
|
||||
Vector2 b(2.0f, 3.0f);
|
||||
Vector2 c = a - b; // (3.0f, 5.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector2 总览](vector2.md)
|
||||
- [`operator+`](operator-add.md) - 加法
|
||||
- [`operator-=`](operator-sub-assign.md) - 减法赋值
|
||||
@@ -23,31 +23,30 @@ Vector2 是 XCEngine 中的二维向量结构体,用于表示 2D 空间中的
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Zero`](Zero.md) | 返回 (0, 0) 零向量 |
|
||||
| [`One`](One.md) | 返回 (1, 1) 单位向量 |
|
||||
| [`Up`](Up.md) | 返回 (0, 1) 上方向 |
|
||||
| [`Down`](Down.md) | 返回 (0, -1) 下方向 |
|
||||
| [`Right`](Right.md) | 返回 (1, 0) 右方向 |
|
||||
| [`Left`](Left.md) | 返回 (-1, 0) 左方向 |
|
||||
| [`Dot`](Dot.md) | 计算两个向量的点积 |
|
||||
| [`Cross`](Cross.md) | 计算两个向量的叉积(返回标量) |
|
||||
| [`Normalize`](Normalize.md) | 归一化向量为单位长度 |
|
||||
| [`Magnitude`](Magnitude.md) | 计算向量长度 |
|
||||
| [`SqrMagnitude`](SqrMagnitude.md) | 计算向量长度平方 |
|
||||
| [`Lerp`](Lerp.md) | 线性插值 |
|
||||
| [`MoveTowards`](MoveTowards.md) | 朝目标移动 |
|
||||
| [`Magnitude`](Magnitude.md) | 实例方法,计算当前向量长度 |
|
||||
| [`SqrMagnitude`](SqrMagnitude.md) | 实例方法,计算当前向量长度平方 |
|
||||
| [`Normalized`](Normalized.md) | 实例方法,返回归一化副本 |
|
||||
| [`Zero`](zero.md) | 返回 (0, 0) 零向量 |
|
||||
| [`One`](one.md) | 返回 (1, 1) 单位向量 |
|
||||
| [`Up`](up.md) | 返回 (0, 1) 上方向 |
|
||||
| [`Down`](down.md) | 返回 (0, -1) 下方向 |
|
||||
| [`Right`](right.md) | 返回 (1, 0) 右方向 |
|
||||
| [`Left`](left.md) | 返回 (-1, 0) 左方向 |
|
||||
| [`Dot`](dot.md) | 计算两个向量的点积 |
|
||||
| [`Cross`](cross.md) | 计算两个向量的叉积(返回标量) |
|
||||
| [`Normalize`](normalize.md) | 归一化向量为单位长度(静态方法) |
|
||||
| [`Magnitude`](magnitude.md) | 计算向量长度 |
|
||||
| [`SqrMagnitude`](sqrmagnitude.md) | 计算向量长度平方 |
|
||||
| [`Lerp`](lerp.md) | 线性插值 |
|
||||
| [`MoveTowards`](movetowards.md) | 朝目标移动 |
|
||||
| [`Normalized`](normalized.md) | 实例方法,返回归一化副本 |
|
||||
|
||||
## 运算符
|
||||
|
||||
| 运算符 | 描述 |
|
||||
|--------|------|
|
||||
| `+`, `-` | 向量加减运算 |
|
||||
| `*`, `/` | 向量与标量乘除运算 |
|
||||
| `+=`, `-=`, `*=`, `/=` | 复合赋值运算 |
|
||||
| `==`, `!=` | 相等性比较(基于 EPSILON 浮点比较) |
|
||||
| [`+`](operator-add.md), [`-`](operator-sub.md) | 向量加减运算 |
|
||||
| [`*`](operator-mul.md), [`/`](operator-div.md) | 向量与标量乘除运算 |
|
||||
| [`*=`](operator-mul-assign.md), [`/=`](operator-div-assign.md) | 复合赋值运算 |
|
||||
| [`+=`](operator-add-assign.md), [`-=`](operator-sub-assign.md) | 复合赋值运算 |
|
||||
| [`==`](operator-eq.md), [`!=`](operator-neq.md) | 相等性比较(基于 EPSILON 浮点比较) |
|
||||
|
||||
## 使用示例
|
||||
|
||||
|
||||
27
docs/api/math/vector3/magnitude-instance.md
Normal file
27
docs/api/math/vector3/magnitude-instance.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Vector3::Magnitude
|
||||
|
||||
```cpp
|
||||
float Magnitude() const
|
||||
```
|
||||
|
||||
计算向量的长度(模)。
|
||||
|
||||
**返回:** `float` - 向量的长度
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(3.0f, 4.0f, 0.0f);
|
||||
float mag = v.Magnitude(); // 5.0f
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 总览](vector3.md)
|
||||
- [`SqrMagnitude`](sqrmagnitude.md) - 长度的平方
|
||||
- [`Normalized`](normalized.md) - 归一化副本
|
||||
- [`static Magnitude`](magnitude.md) - 静态版本
|
||||
27
docs/api/math/vector3/normalized-instance.md
Normal file
27
docs/api/math/vector3/normalized-instance.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Vector3::Normalized
|
||||
|
||||
```cpp
|
||||
Vector3 Normalized() const
|
||||
```
|
||||
|
||||
返回向量的归一化副本(单位长度为 1 的向量)。不会修改原向量。
|
||||
|
||||
**返回:** `Vector3` - 归一化后的向量副本;如果向量长度接近零,则返回零向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(3.0f, 4.0f, 0.0f);
|
||||
Vector3 normalized = v.Normalized(); // (0.6f, 0.8f, 0.0f)
|
||||
// v 仍然是 (3.0f, 4.0f, 0.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 总览](vector3.md)
|
||||
- [`static Normalize`](normalize.md) - 静态版本(会修改原向量)
|
||||
- [`Magnitude`](magnitude-instance.md) - 向量长度
|
||||
27
docs/api/math/vector3/sqrmagnitude-instance.md
Normal file
27
docs/api/math/vector3/sqrmagnitude-instance.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Vector3::SqrMagnitude
|
||||
|
||||
```cpp
|
||||
float SqrMagnitude() const
|
||||
```
|
||||
|
||||
计算向量长度的平方。用于在不计算平方根的情况下比较长度,性能更优。
|
||||
|
||||
**返回:** `float` - 向量长度的平方
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 v(3.0f, 4.0f, 0.0f);
|
||||
float sqrMag = v.SqrMagnitude(); // 25.0f
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector3 总览](vector3.md)
|
||||
- [`Magnitude`](magnitude-instance.md) - 向量长度
|
||||
- [`Normalized`](normalized.md) - 归一化副本
|
||||
- [`static SqrMagnitude`](sqrmagnitude.md) - 静态版本
|
||||
@@ -51,11 +51,20 @@ Vector3 是 XCEngine 中用于表示三维向量的核心类型,支持常见
|
||||
|--------|------|
|
||||
| [`+`](operator_add.md), [`-`](operator_sub.md) | 向量加减 |
|
||||
| [`*`](operator_mul.md), [`/`](operator_div.md) | 向量与标量或分量相乘/相除 |
|
||||
| [`+=`](operator_add_assign.md), [`-=`](operator_sub_assign.md) | 复合赋值运算符 |
|
||||
| [`*=`](operator_mul_assign.md), [`/=`](operator_div_assign.md) | 复合赋值运算符 |
|
||||
| [`[]`](./operator_index.md) | 下标访问 x, y, z 分量 |
|
||||
| [`==`](operator_eq.md), [`!=`](operator_neq.md) | 相等性比较 |
|
||||
| [`* (Quaternion)`](quaternion-multiply.md) | 用四元数旋转向量 |
|
||||
|
||||
## 实例方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Magnitude()`](magnitude-instance.md) | 计算向量长度 |
|
||||
| [`SqrMagnitude()`](sqrmagnitude-instance.md) | 计算向量长度的平方 |
|
||||
| [`Normalized()`](normalized-instance.md) | 返回归一化副本 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
|
||||
26
docs/api/math/vector4/operator-neg.md
Normal file
26
docs/api/math/vector4/operator-neg.md
Normal file
@@ -0,0 +1,26 @@
|
||||
# Vector4::operator-
|
||||
|
||||
```cpp
|
||||
Vector4 operator-() const
|
||||
```
|
||||
|
||||
一元负号运算符,返回当前向量的负向量。
|
||||
|
||||
**返回:** `Vector4` - 每个分量取负的新向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector4 v(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
Vector4 neg = -v; // (-1.0f, -2.0f, -3.0f, -4.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Vector4 总览](vector4.md)
|
||||
- [`operator+`](operator-add.md) - 加法
|
||||
- [`operator-`](operator-sub.md) - 二元减法
|
||||
@@ -1,34 +1,18 @@
|
||||
# Viewport::GetAspectRatio
|
||||
|
||||
```cpp
|
||||
float GetAspectRatio() const;
|
||||
float GetAspectRatio() const
|
||||
```
|
||||
|
||||
获取视口宽高比。
|
||||
|
||||
**返回:** 宽高比 (width / height),如果 height 为 0 则返回 0.0f
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `float` - 宽高比 (width / height),height 为 0 时返回 0.0f
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
Viewport viewport(0.0f, 0.0f, 1920.0f, 1080.0f);
|
||||
float aspect = viewport.GetAspectRatio();
|
||||
std::cout << "Aspect Ratio: " << aspect << "\n";
|
||||
return 0;
|
||||
}
|
||||
Viewport viewport(0, 0, 1920, 1080);
|
||||
float aspect = viewport.GetAspectRatio(); // 1.777... (16:9)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`Viewport::GetRect`](getrect.md) - 转换为 Rect
|
||||
- [Viewport 总览](viewport.md)
|
||||
@@ -1,34 +1,18 @@
|
||||
# Viewport::GetRect
|
||||
|
||||
```cpp
|
||||
Rect GetRect() const;
|
||||
Rect GetRect() const
|
||||
```
|
||||
|
||||
将视口转换为 Rect。
|
||||
|
||||
**返回:** 对应的 Rect(x, y, width, height),不包含深度范围
|
||||
|
||||
**线程安全:** ✅
|
||||
**返回:** `Rect` - 对应的矩形 (x, y, width, height),不包含深度范围
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
Viewport viewport(0.0f, 0.0f, 1920.0f, 1080.0f, 0.0f, 1.0f);
|
||||
Rect rect = viewport.GetRect();
|
||||
std::cout << "Rect: (" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << ")\n";
|
||||
return 0;
|
||||
}
|
||||
Viewport viewport(0, 0, 1920, 1080, 0.0f, 1.0f);
|
||||
Rect rect = viewport.GetRect(); // (0, 0, 1920, 1080)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`Viewport::GetAspectRatio`](getaspectratio.md) - 获取宽高比
|
||||
- [Viewport 总览](viewport.md)
|
||||
@@ -1,49 +1,45 @@
|
||||
# Viewport
|
||||
|
||||
**命名空间**: `XCEngine::Math`
|
||||
渲染视口结构体,用于屏幕到归一化坐标的映射。
|
||||
|
||||
**类型**: `struct`
|
||||
**头文件:** `#include <XCEngine/Math/Rect.h>`
|
||||
|
||||
**头文件**: `XCEngine/Math/Viewport.h`
|
||||
**命名空间:** `XCEngine::Math`
|
||||
|
||||
**描述**: 视口,用于渲染目标区域和坐标映射
|
||||
## 结构体定义
|
||||
|
||||
## 概述
|
||||
```cpp
|
||||
struct Viewport {
|
||||
float x = 0.0f;
|
||||
float y = 0.0f;
|
||||
float width = 0.0f;
|
||||
float height = 0.0f;
|
||||
float minDepth = 0.0f;
|
||||
float maxDepth = 1.0f;
|
||||
|
||||
Viewport 结构体表示一个渲染视口,除了位置和尺寸外,还包含深度范围 `(minDepth, maxDepth)`。主要用于屏幕到归一化设备坐标(NDC)的映射,以及渲染目标区域的定义。
|
||||
Viewport() = default;
|
||||
Viewport(float x, float y, float w, float h);
|
||||
Viewport(float x, float y, float w, float h, float minD, float maxD);
|
||||
};
|
||||
```
|
||||
|
||||
## 公共方法
|
||||
## 构造函数
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`GetAspectRatio`](getaspectratio.md) | 获取视口宽高比 |
|
||||
| [`GetRect`](getrect.md) | 转换为 Rect |
|
||||
| `Viewport()` | 默认构造 |
|
||||
| `Viewport(x, y, w, h)` | 2D 视口 |
|
||||
| `Viewport(x, y, w, h, minD, maxD)` | 带深度范围的 3D 视口 |
|
||||
|
||||
## 使用示例
|
||||
## 方法
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Rect.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
int main() {
|
||||
Viewport viewport(0.0f, 0.0f, 1920.0f, 1080.0f, 0.0f, 1.0f);
|
||||
|
||||
std::cout << "Position: (" << viewport.x << ", " << viewport.y << ")\n";
|
||||
std::cout << "Size: " << viewport.width << " x " << viewport.height << "\n";
|
||||
std::cout << "Depth: " << viewport.minDepth << " to " << viewport.maxDepth << "\n";
|
||||
std::cout << "Aspect Ratio: " << viewport.GetAspectRatio() << "\n";
|
||||
|
||||
Rect rect = viewport.GetRect();
|
||||
std::cout << "As Rect: (" << rect.x << ", " << rect.y << ", " << rect.width << ", " << rect.height << ")\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [GetAspectRatio()](viewport-getaspectratio.md) | `float` | 宽高比 (width / height) |
|
||||
| [GetRect()](viewport-getrect.md) | `Rect` | 转换为 Rect |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [`Rect`](../rect/rect.md) - 浮点矩形
|
||||
- [`RectInt`](../rect/rectint.md) - 整数矩形
|
||||
- [`Vector2`](../vector2/vector2.md) - 二维向量
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Rect](rect-overview.md) - 浮点矩形
|
||||
- [RectInt](rectint.md) - 整数矩形
|
||||
|
||||
Reference in New Issue
Block a user