docs: update math API docs
This commit is contained in:
@@ -1,25 +1,35 @@
|
||||
# Frustum::Contains (bounds)
|
||||
# Frustum::Contains
|
||||
|
||||
```cpp
|
||||
bool Contains(const Bounds& bounds) const
|
||||
```
|
||||
|
||||
检测轴对齐包围盒是否完全在视锥体内。
|
||||
检测轴对齐包围盒(Axis-Aligned Bounding Box,AABB)是否完全位于视锥体内。判断方式为:先取出 Bounds 的 8 个顶点坐标,然后对每个裁剪平面,检查所有 8 个顶点是否都在该平面外侧(距离小于 0)。若存在某个平面使得全部 8 个顶点都在其外侧,则包围盒完全在视锥外;否则认为包围盒至少部分在视锥内。
|
||||
|
||||
**参数:**
|
||||
- `bounds` - 要检测的轴对齐包围盒
|
||||
|
||||
**返回:** `bool` - Bounds 完全在视锥内返回 true
|
||||
**返回:** `bool` - Bounds 完全在视锥内返回 `true`,否则返回 `false`
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅(只读操作,不修改状态)
|
||||
|
||||
**复杂度:** O(48),即遍历 6 个平面 × 8 个顶点
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
Bounds objectBounds = object.GetWorldBounds();
|
||||
if (frustum.Contains(objectBounds)) {
|
||||
// 包围盒完全在视锥内,需要渲染
|
||||
Render(object);
|
||||
#include <XCEngine/Math/Frustum.h>
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
|
||||
void CheckBoundsInFrustum(const Frustum& frustum, const Bounds& bounds) {
|
||||
if (frustum.Contains(bounds)) {
|
||||
// 包围盒完全在视锥内,必须渲染
|
||||
Render();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Frustum 总览](frustum.md) - 返回类总览
|
||||
- [Intersects](intersects-bounds.md) - 包围盒与视锥相交检测
|
||||
|
||||
Reference in New Issue
Block a user