1.1 KiB
1.1 KiB
Frustum
视锥体,用于视锥剔除。
头文件
#include <XCEngine/Math/Frustum.h>
命名空间
XCEngine::Math
结构体定义
class Frustum {
public:
Plane planes[6]; // 6 个裁剪平面
enum class PlaneIndex {
Left = 0,
Right = 1,
Bottom = 2,
Top = 3,
Near = 4,
Far = 5
};
};
实例方法
| 方法 | 返回值 | 描述 |
|---|---|---|
Contains(point) |
bool |
点是否在视锥内 |
Contains(Sphere) |
bool |
球体是否在视锥内 |
Contains(Bounds) |
bool |
Bounds 是否在视锥内 |
Intersects(Bounds) |
bool |
Bounds 是否与视锥相交 |
Intersects(Sphere) |
bool |
球体是否与视锥相交 |
使用示例
Frustum frustum;
// 需要从相机矩阵构建视锥平面
// 视锥剔除
for (const auto& object : objects) {
if (frustum.Contains(object.bounds)) {
// 物体在视锥内,渲染
Render(object);
}
}
// 或使用相交检测
if (frustum.Intersects(bounds)) {
Render(object);
}