- audio: 更新 audio-system 方法文档 - components: 新增 audio-listener/audio-source 组件方法文档,新增 remove-component 方法 - core: 更新 filewriter, types 文档 - math: 更新 box 方法文档 - memory: 更新 proxy-allocator 文档 - resources: 更新 loader 和 texture 文档 - rhi: 更新 opengl 设备、shader、swap-chain 文档 - threading: 更新 mutex 和 task-system 文档
53 lines
1.5 KiB
Markdown
53 lines
1.5 KiB
Markdown
# OBB
|
||
|
||
**命名空间**: `XCEngine::Math`
|
||
|
||
**类型**: `struct`
|
||
|
||
**头文件**: `XCEngine/Math/AABB.h`
|
||
|
||
**描述**: 定向包围盒,支持任意方向旋转的盒状包围体
|
||
|
||
## 概述
|
||
|
||
OBB(Oriented Bounding Box)是一种包围盒类型,与轴对齐包围盒(AABB)不同,OBB 可以任意旋转,因此能够更紧凑地包围复杂形状的对象。OBB 由一个中心点、半长向量(extents)和一个变换矩阵组成,变换矩阵定义了盒子的朝向。
|
||
|
||
OBB 常用于碰撞检测、剔除运算和物理模拟等场景。
|
||
|
||
## 公共方法
|
||
|
||
| 方法 | 描述 |
|
||
|------|------|
|
||
| [`GetAxis`](get-axis.md) | 获取指定索引处的局部轴方向 |
|
||
| [`GetMin`](get-min.md) | 获取包围盒最小顶点 |
|
||
| [`GetMax`](get-max.md) | 获取包围盒最大顶点 |
|
||
| [`Contains`](contains.md) | 检测点是否在包围盒内 |
|
||
| [`Intersects`](intersects-obb.md) | 检测与另一个 OBB 是否相交 |
|
||
| [`Intersects`](intersects-sphere.md) | 检测与球体是否相交 |
|
||
|
||
## 使用示例
|
||
|
||
```cpp
|
||
#include "AABB.h"
|
||
#include "Vector3.h"
|
||
#include "Matrix4.h"
|
||
|
||
using namespace XCEngine::Math;
|
||
|
||
OBB obb(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 1.0f));
|
||
|
||
Vector3 point(0.5f, 0.25f, 0.5f);
|
||
if (obb.Contains(point)) {
|
||
}
|
||
|
||
Vector3 axis = obb.GetAxis(0);
|
||
Vector3 min = obb.GetMin();
|
||
Vector3 max = obb.GetMax();
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [Vector3](../vector3/vector3.md) - 三维向量
|
||
- [Matrix4](../matrix4/matrix4.md) - 4x4 变换矩阵
|
||
- [Sphere](../sphere/sphere.md) - 球体
|