docs: update math API docs
This commit is contained in:
@@ -1,26 +1,39 @@
|
||||
# Frustum::Intersects (bounds)
|
||||
# Frustum::Intersects
|
||||
|
||||
```cpp
|
||||
bool Intersects(const Bounds& bounds) const
|
||||
```
|
||||
|
||||
检测轴对齐包围盒是否与视锥体相交。
|
||||
检测轴对齐包围盒(Axis-Aligned Bounding Box,AABB)是否与视锥体相交。判断方式为:对每个裁剪平面,检查 8 个顶点是否全部在该平面外侧(allNegative)或全部在内侧(allPositive)。若存在某个平面使得全部 8 个顶点都在其外侧,则视锥与包围盒不相交;否则认为两者相交。
|
||||
|
||||
注意:此方法与 `Contains(Bounds)` 的区别在于——`Contains` 要求包围盒完全在视锥内,而 `Intersects` 只要有任意重叠就返回 `true`。
|
||||
|
||||
**参数:**
|
||||
- `bounds` - 要检测的轴对齐包围盒
|
||||
|
||||
**返回:** `bool` - 与视锥相交返回 true
|
||||
**返回:** `bool` - 视锥与 Bounds 相交返回 `true`,否则返回 `false`
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅(只读操作,不修改状态)
|
||||
|
||||
**复杂度:** O(48),即遍历 6 个平面 × 8 个顶点
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
for (const auto& object : sceneObjects) {
|
||||
if (frustum.Intersects(object.bounds)) {
|
||||
// 物体与视锥相交,需要渲染
|
||||
Render(object);
|
||||
#include <XCEngine/Math/Frustum.h>
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
|
||||
void FrustumCullingExample(const Frustum& frustum, const std::vector<Bounds>& objectBounds) {
|
||||
for (const auto& bounds : objectBounds) {
|
||||
if (frustum.Intersects(bounds)) {
|
||||
// 物体与视锥相交,需要渲染
|
||||
Render(bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Frustum 总览](frustum.md) - 返回类总览
|
||||
- [Contains](contains-bounds.md) - 包围盒完全包含检测
|
||||
|
||||
Reference in New Issue
Block a user