docs: update math API docs

This commit is contained in:
2026-03-20 02:35:15 +08:00
parent e165dbea1c
commit c5b17239ca
243 changed files with 5307 additions and 1327 deletions

View File

@@ -1,25 +1,35 @@
# Frustum::Contains (bounds)
# Frustum::Contains
```cpp
bool Contains(const Bounds& bounds) const
```
检测轴对齐包围盒是否完全视锥体内。
检测轴对齐包围盒Axis-Aligned Bounding BoxAABB是否完全位于视锥体内。判断方式为:先取出 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) - 包围盒与视锥相交检测

View File

@@ -1,24 +1,34 @@
# Frustum::Contains (point)
# Frustum::Contains
```cpp
bool Contains(const Vector3& point) const
```
检测点是否在视锥体内
检测世界空间中的点是否完全位于视锥体内。判断方式为:依次计算该点到 6 个裁剪平面的有符号距离,若任意一个距离小于 0则点位于该平面外侧视锥体不包含该点
**参数:**
- `point` - 要检测的世界空间点
- `point` - 要检测的世界空间三维
**返回:** `bool` - 点在视锥内返回 true
**返回:** `bool` - 点完全在视锥内返回 `true`,否则返回 `false`
**复杂度** O(1)
**线程安全** ✅(只读操作,不修改状态)
**复杂度:** O(6),即遍历 6 个裁剪平面
**示例:**
```cpp
Frustum frustum = camera.CalculateFrustum();
Vector3 point = object.GetPosition();
if (frustum.Contains(point)) {
// 点在视锥内
#include <XCEngine/Math/Frustum.h>
#include <XCEngine/Math/Vector3.h>
void CheckPointInFrustum(const Frustum& frustum, const Vector3& point) {
if (frustum.Contains(point)) {
// 点完全在视锥内
}
}
```
## 相关文档
- [Frustum 总览](frustum.md) - 返回类总览
- [Intersects](intersects-bounds.md) - 视锥体相交检测

View File

@@ -1,24 +1,34 @@
# Frustum::Contains (sphere)
# Frustum::Contains
```cpp
bool Contains(const Sphere& sphere) const
```
检测球体是否完全在视锥体内
检测球体是否完全位于视锥体内。判断方式为:依次计算球心到 6 个裁剪平面的有符号距离,若任意一个距离小于 `-radius`(即球心到平面的距离小于球半径的负数,说明球体完全在平面外侧),则视锥体不包含该球体
**参数:**
- `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.Contains(collider)) {
// 球体完全在视锥内
#include <XCEngine/Math/Frustum.h>
#include <XCEngine/Math/Sphere.h>
void CheckSphereInFrustum(const Frustum& frustum, const Sphere& sphere) {
if (frustum.Contains(sphere)) {
// 球体完全在视锥内
}
}
```
## 相关文档
- [Frustum 总览](frustum.md) - 返回类总览
- [Intersects](intersects-sphere.md) - 球体与视锥相交检测

View File

@@ -1,45 +1,51 @@
# Frustum
视锥体,用于视锥剔除。
**命名空间**: `XCEngine::Math`
**头文件:** `#include <XCEngine/Math/Frustum.h>`
**类型**: `class`
**命名空间:** `XCEngine::Math`
**头文件**: `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
class Frustum {
public:
Plane planes[6];
Frustum frustum = camera.CalculateFrustum();
Bounds objectBounds = object.GetWorldBounds();
enum class PlaneIndex {
Left = 0,
Right = 1,
Bottom = 2,
Top = 3,
Near = 4,
Far = 5
};
bool Contains(const Vector3& point) const;
bool Contains(const Sphere& sphere) const;
bool Contains(const Bounds& bounds) const;
bool Intersects(const Bounds& bounds) const;
bool Intersects(const Sphere& sphere) const;
};
if (frustum.Contains(objectBounds)) {
// 物体完全在视锥内,必须渲染
Render(object);
} else if (frustum.Intersects(objectBounds)) {
// 物体与视锥相交,可能需要渲染
Render(object);
}
```
## 实例方法
| 方法 | 返回值 | 描述 |
|------|--------|------|
| [Contains(point)](contains-point.md) | `bool` | 点是否在视锥内 |
| [Contains(sphere)](contains-sphere.md) | `bool` | 球体是否完全在视锥内 |
| [Contains(bounds)](contains-bounds.md) | `bool` | Bounds 是否完全在视锥内 |
| [Intersects(bounds)](intersects-bounds.md) | `bool` | Bounds 是否与视锥相交 |
| [Intersects(sphere)](intersects-sphere.md) | `bool` | 球体是否与视锥相交 |
## 相关文档
- [Math 模块总览](../math.md) - 返回 Math 模块总览
- [Math 模块总览](../math.md) - Math 模块总览
- [Plane](../plane/plane.md) - 平面类型
- [Bounds](../bounds/bounds.md) - 包围盒类型
- [Sphere](../sphere/sphere.md) - 球体类型

View File

@@ -1,26 +1,39 @@
# Frustum::Intersects (bounds)
# Frustum::Intersects
```cpp
bool Intersects(const Bounds& bounds) const
```
检测轴对齐包围盒是否与视锥体相交。
检测轴对齐包围盒Axis-Aligned Bounding BoxAABB是否与视锥体相交。判断方式为对每个裁剪平面检查 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) - 包围盒完全包含检测

View File

@@ -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) - 球体完全包含检测