docs: update math API docs
This commit is contained in:
@@ -1,25 +1,37 @@
|
||||
# Frustum::Intersects (sphere)
|
||||
# Frustum::Intersects
|
||||
|
||||
```cpp
|
||||
bool Intersects(const Sphere& sphere) const
|
||||
```
|
||||
|
||||
检测球体是否与视锥体相交。
|
||||
检测球体是否与视锥体相交。判断方式为:依次计算球心到 6 个裁剪平面的有符号距离,若任意一个距离小于 `-radius`(即球体完全在平面外侧),则两者不相交;否则认为相交。
|
||||
|
||||
注意:此方法与 `Contains(Sphere)` 的区别在于——`Contains` 要求球体完全在视锥内,而 `Intersects` 只要有任意重叠就返回 `true`。
|
||||
|
||||
**参数:**
|
||||
- `sphere` - 要检测的球体
|
||||
- `sphere` - 要检测的球体,包含圆心 `center` 和半径 `radius`
|
||||
|
||||
**返回:** `bool` - 与视锥相交返回 true
|
||||
**返回:** `bool` - 视锥与球体相交返回 `true`,否则返回 `false`
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅(只读操作,不修改状态)
|
||||
|
||||
**复杂度:** O(6),即遍历 6 个裁剪平面
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
Sphere collider = object.GetBoundingSphere();
|
||||
if (frustum.Intersects(collider)) {
|
||||
// 球体与视锥相交
|
||||
Render(object);
|
||||
#include <XCEngine/Math/Frustum.h>
|
||||
#include <XCEngine/Math/Sphere.h>
|
||||
|
||||
void CheckSphereIntersection(const Frustum& frustum, const Sphere& sphere) {
|
||||
if (frustum.Intersects(sphere)) {
|
||||
// 球体与视锥相交
|
||||
Render();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Frustum 总览](frustum.md) - 返回类总览
|
||||
- [Contains](contains-sphere.md) - 球体完全包含检测
|
||||
|
||||
Reference in New Issue
Block a user