Files
XCEngine/docs/api/math/viewport/viewport.md
2026-03-20 02:35:15 +08:00

49 lines
1.4 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.
# 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) - 二维向量