1.4 KiB
1.4 KiB
Bounds
轴对齐包围盒 (AABB),中心-范围表示。
头文件
#include <XCEngine/Math/Bounds.h>
命名空间
XCEngine::Math
结构体定义
struct Bounds {
Vector3 center = Vector3::Zero();
Vector3 extents = Vector3::Zero(); // 半长,不是最大点
};
构造函数
Bounds()- 默认构造Bounds(const Vector3& center, const Vector3& size)- 从中心和大小构造
实例方法
| 方法 | 返回值 | 描述 |
|---|---|---|
GetMin() |
Vector3 |
最小点: center - extents |
GetMax() |
Vector3 |
最大点: center + extents |
SetMinMax(min, max) |
void |
从最小/最大点设置 |
Contains(point) |
bool |
点是否在盒内 |
Intersects(other) |
bool |
与另一个 Bounds 相交 |
Encapsulate(point) |
void |
扩展包含点 |
Encapsulate(bounds) |
void |
扩展包含另一个 Bounds |
Expand(amount) |
void |
各方向扩展 amount |
Expand(amount) |
void |
按 Vector3 扩展 |
GetClosestPoint(point) |
Vector3 |
盒上最接近给定点的点 |
GetVolume() |
float |
体积 |
使用示例
Bounds bounds(center, extents);
// 包含点
if (bounds.Contains(point)) { ... }
// 扩展包围盒
bounds.Encapsulate(newPoint);
// 相交检测
if (bounds.Intersects(other)) { ... }
// 设置
bounds.SetMinMax(minPoint, maxPoint);