docs: update math API docs

This commit is contained in:
2026-03-20 02:35:15 +08:00
parent e165dbea1c
commit c5b17239ca
243 changed files with 5307 additions and 1327 deletions

View File

@@ -0,0 +1,34 @@
# Viewport::GetAspectRatio
```cpp
float GetAspectRatio() const;
```
获取视口宽高比。
**返回:** 宽高比 (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::GetRect`](getrect.md) - 转换为 Rect
- [Viewport 总览](viewport.md)

View File

@@ -0,0 +1,34 @@
# Viewport::GetRect
```cpp
Rect GetRect() const;
```
将视口转换为 Rect。
**返回:** 对应的 Rectx, 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::GetAspectRatio`](getaspectratio.md) - 获取宽高比
- [Viewport 总览](viewport.md)

View File

@@ -0,0 +1,49 @@
# Viewport
**命名空间**: `XCEngine::Math`
**类型**: `struct`
**头文件**: `XCEngine/Math/Viewport.h`
**描述**: 视口,用于渲染目标区域和坐标映射
## 概述
Viewport 结构体表示一个渲染视口,除了位置和尺寸外,还包含深度范围 `(minDepth, maxDepth)`。主要用于屏幕到归一化设备坐标NDC的映射以及渲染目标区域的定义。
## 公共方法
| 方法 | 描述 |
|------|------|
| [`GetAspectRatio`](getaspectratio.md) | 获取视口宽高比 |
| [`GetRect`](getrect.md) | 转换为 Rect |
## 使用示例
```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;
}
```
## 相关文档
- [`Rect`](../rect/rect.md) - 浮点矩形
- [`RectInt`](../rect/rectint.md) - 整数矩形
- [`Vector2`](../vector2/vector2.md) - 二维向量