- components: 修复英文标题为中文,添加缺失组件文档 - 新增 camera-component, light-component, audio-source-component, audio-listener-component 类总览 - 修复 get-position.md 格式 - 更新 components.md 模块总览 - scene: 修复方法文档格式,新增缺失方法 - 修复 find.md, create-game-object.md 英文标题 - 新增 FindByID, SerializeToString, DeserializeFromString 方法文档 - 更新 scene.md 类总览方法列表
66 lines
2.2 KiB
Markdown
66 lines
2.2 KiB
Markdown
# Box
|
||
|
||
**命名空间**: `XCEngine::Math`
|
||
|
||
**类型**: `struct`
|
||
|
||
**头文件**: `XCEngine/Core/Math/Box.h`
|
||
|
||
**描述**: 轴对齐盒体,用于碰撞检测和视锥体裁剪
|
||
|
||
## 概述
|
||
|
||
`Box` 是一个轴对齐包围盒(AABB)结构体,支持可选的变换矩阵以实现定向包围盒(OBB)语义。盒体由中心点 `center` 和半长 `extents` 定义,`transform` 矩阵可用于 `Contains` 和 `Intersects(Sphere)` 方法以执行真正的 OBB 检测。
|
||
|
||
**注意:**
|
||
- `Contains` 和 `Intersects(Sphere)` 方法会将点/球心变换到盒体局部空间(使用 `transform` 的逆矩阵)进行检测
|
||
- `GetMin` / `GetMax` 返回的是未应用 `transform` 的局部空间角点(即 `center ± extents`)
|
||
- `Intersects(Box)` 目前使用 AABB 简化算法,未考虑旋转
|
||
|
||
## 结构体成员
|
||
|
||
| 成员 | 类型 | 描述 | 默认值 |
|
||
|------|------|------|--------|
|
||
| `center` | `Vector3` | 盒体中心点 | `Vector3::Zero()` |
|
||
| `extents` | `Vector3` | 从中心到每个面的距离(实际尺寸 = extents * 2) | `Vector3::Zero()` |
|
||
| `transform` | `Matrix4` | 变换矩阵,用于 OBB 检测 | 单位矩阵 |
|
||
|
||
## 公共方法
|
||
|
||
| 方法 | 描述 |
|
||
|------|------|
|
||
| [`Box()`](constructor.md) | 默认构造(各量为零) |
|
||
| [`Box(center, extents)`](constructor.md) | 从中心和半长构造 |
|
||
| [`GetMin`](getmin.md) | 获取局部空间最小点 |
|
||
| [`GetMax`](getmax.md) | 获取局部空间最大点 |
|
||
| [`Contains`](contains.md) | 点是否在盒内(使用 transform) |
|
||
| [`Intersects(Sphere)`](intersects.md) | 与球体相交 |
|
||
| [`Intersects(Box)`](intersects-box.md) | 与另一个盒相交(AABB 检测) |
|
||
| [`Intersects(Ray, t)`](intersects-ray.md) | 与射线相交 |
|
||
|
||
## 使用示例
|
||
|
||
```cpp
|
||
#include <XCEngine/Core/Math/Box.h>
|
||
#include <XCEngine/Core/Math/Vector3.h>
|
||
#include <XCEngine/Core/Math/Sphere.h>
|
||
|
||
using namespace XCEngine::Math;
|
||
|
||
Box box(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||
|
||
Vector3 min = box.GetMin();
|
||
Vector3 max = box.GetMax();
|
||
|
||
if (box.Contains(Vector3(0.5f, 0.5f, 0.5f))) {
|
||
}
|
||
|
||
Sphere sphere(Vector3(2.0f, 0.0f, 0.0f), 1.0f);
|
||
if (box.Intersects(sphere)) {
|
||
}
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|