docs: update math API docs
This commit is contained in:
34
docs/api/math/viewport/getaspectratio.md
Normal file
34
docs/api/math/viewport/getaspectratio.md
Normal 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)
|
||||
34
docs/api/math/viewport/getrect.md
Normal file
34
docs/api/math/viewport/getrect.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# Viewport::GetRect
|
||||
|
||||
```cpp
|
||||
Rect GetRect() const;
|
||||
```
|
||||
|
||||
将视口转换为 Rect。
|
||||
|
||||
**返回:** 对应的 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::GetAspectRatio`](getaspectratio.md) - 获取宽高比
|
||||
- [Viewport 总览](viewport.md)
|
||||
49
docs/api/math/viewport/viewport.md
Normal file
49
docs/api/math/viewport/viewport.md
Normal 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) - 二维向量
|
||||
Reference in New Issue
Block a user