52 lines
1.6 KiB
Markdown
52 lines
1.6 KiB
Markdown
# Frustum
|
||
|
||
**命名空间**: `XCEngine::Math`
|
||
|
||
**类型**: `class`
|
||
|
||
**头文件**: `XCEngine/Math/Frustum.h`
|
||
|
||
**描述**: 视锥体,用于 3D 裁剪和可见性判断
|
||
|
||
## 概述
|
||
|
||
Frustum 表示一个视锥体,由 6 个裁剪平面组成(左、右、底、顶、近、远)。主要用于视锥剔除(Frustum Culling),在渲染前判断场景物体是否与相机视锥相交或完全在内,从而决定是否需要渲染该物体,提升渲染性能。
|
||
|
||
## 公共方法
|
||
|
||
| 方法 | 描述 |
|
||
|------|------|
|
||
| [`Contains(Point)`](contains-point.md) | 点是否完全在视锥内 |
|
||
| [`Contains(Sphere)`](contains-sphere.md) | 球体是否完全在视锥内 |
|
||
| [`Contains(Bounds)`](contains-bounds.md) | Bounds 是否完全在视锥内 |
|
||
| [`Intersects(Bounds)`](intersects-bounds.md) | Bounds 是否与视锥相交 |
|
||
| [`Intersects(Sphere)`](intersects-sphere.md) | 球体是否与视锥相交 |
|
||
|
||
## 嵌套类型
|
||
|
||
| 类型 | 描述 |
|
||
|------|------|
|
||
| `PlaneIndex` | 平面索引枚举(Left, Right, Bottom, Top, Near, Far) |
|
||
|
||
## 使用示例
|
||
|
||
```cpp
|
||
Frustum frustum = camera.CalculateFrustum();
|
||
Bounds objectBounds = object.GetWorldBounds();
|
||
|
||
if (frustum.Contains(objectBounds)) {
|
||
// 物体完全在视锥内,必须渲染
|
||
Render(object);
|
||
} else if (frustum.Intersects(objectBounds)) {
|
||
// 物体与视锥相交,可能需要渲染
|
||
Render(object);
|
||
}
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [Math 模块总览](../math.md) - Math 模块总览
|
||
- [Plane](../plane/plane.md) - 平面类型
|
||
- [Bounds](../bounds/bounds.md) - 包围盒类型
|
||
- [Sphere](../sphere/sphere.md) - 球体类型
|