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

65 lines
1.9 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.
# Bounds
**命名空间**: `XCEngine::Math`
**类型**: `struct`
**头文件**: `XCEngine/Math/Bounds.h`
**描述**: 轴对齐包围盒,用于场景管理中的快速剔除
## 概述
Bounds 表示一个轴对齐包围盒AABB使用中心点 `center` 和范围 `extents` 定义。`extents` 是从中心到包围盒每个面的距离,因此实际尺寸为 `extents * 2`。常用于视锥剔除、碰撞检测和场景管理中的快速排除不可见物体。
## 结构体成员
| 成员 | 类型 | 描述 |
|------|------|------|
| `center` | `Vector3` | 包围盒中心点 |
| `extents` | `Vector3` | 从中心到每个面的距离(实际尺寸 = extents * 2 |
## 公共方法
| 方法 | 描述 |
|------|------|
| [`Bounds`](bounds.constructors.md) | 构造函数 |
| [`GetMin`](getmin.md) | 获取包围盒最小点 |
| [`GetMax`](getmax.md) | 获取包围盒最大点 |
| [`SetMinMax`](setminmax.md) | 从最小/最大点设置包围盒 |
| [`Intersects`](intersects.md) | 检测与另一个 Bounds 是否相交 |
| [`Contains`](contains.md) | 检测点是否在盒内 |
| [`Encapsulate`](encapsulate.md) | 扩展包围盒以包含点或另一个 Bounds |
| [`Expand`](expand.md) | 扩展包围盒 |
| [`GetClosestPoint`](getclosestpoint.md) | 获取盒上最接近给定点的点 |
| [`GetVolume`](getvolume.md) | 计算包围盒体积 |
## 使用示例
```cpp
#include <XCEngine/Math/Bounds.h>
#include <XCEngine/Math/Vector3.h>
using namespace XCEngine::Math;
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
Vector3 min = bounds.GetMin();
Vector3 max = bounds.GetMax();
bounds.Expand(1.0f);
if (bounds.Contains(Vector3(0.0f, 0.0f, 0.0f))) {
// point is inside
}
Bounds other(Vector3(5.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
if (bounds.Intersects(other)) {
// bounds intersect
}
```
## 相关文档
- [Math 模块总览](../math.md) - 返回 Math 模块总览