- resources: 更新 asyncloader, audioclip, mesh-import-settings, texture-loader 文档 - rhi: 更新 opengl render-target-view 文档 - components: 新增 camera-component 全部方法文档 (15个文件)
63 lines
1.9 KiB
Markdown
63 lines
1.9 KiB
Markdown
# OBB
|
||
|
||
**命名空间**: `XCEngine::Math`
|
||
|
||
**类型**: `struct`
|
||
|
||
**头文件**: `XCEngine/Core/Math/AABB.h`
|
||
|
||
**描述**: 有向包围盒(Oriented Bounding Box),支持任意方向旋转的盒状包围体
|
||
|
||
## 概述
|
||
|
||
OBB(Oriented Bounding Box)是一种包围盒类型,与轴对齐包围盒(AABB)不同,OBB 可以任意旋转,因此能够更紧凑地包围复杂形状的对象。OBB 由一个中心点、半长向量(extents)和一个变换矩阵组成,变换矩阵定义了盒子的朝向。
|
||
|
||
OBB 常用于碰撞检测、剔除运算和物理模拟等场景。
|
||
|
||
## 结构体成员
|
||
|
||
| 成员 | 类型 | 描述 |
|
||
|------|------|------|
|
||
| `center` | `Vector3` | OBB 中心点 |
|
||
| `extents` | `Vector3` | 从中心到每个面的距离(半长) |
|
||
| `transform` | `Matrix4x4` | 变换矩阵,定义盒子朝向 |
|
||
|
||
## 公共方法
|
||
|
||
| 方法 | 描述 |
|
||
|------|------|
|
||
| `GetAxis(int index)` | 获取指定索引处的局部轴方向 |
|
||
| `GetMin()` | 获取局部空间最小顶点 |
|
||
| `GetMax()` | 获取局部空间最大顶点 |
|
||
| `Contains(const Vector3& point)` | 检测点是否在 OBB 内 |
|
||
| `Intersects(const OBB& other)` | 检测与另一个 OBB 是否相交 |
|
||
| `Intersects(const Sphere& sphere)` | 检测与球体是否相交 |
|
||
|
||
## 使用示例
|
||
|
||
```cpp
|
||
#include <XCEngine/Core/Math/AABB.h>
|
||
#include <XCEngine/Core/Math/Vector3.h>
|
||
#include <XCEngine/Core/Math/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)) {
|
||
// 点在 OBB 内
|
||
}
|
||
|
||
Vector3 axis = obb.GetAxis(0);
|
||
Vector3 min = obb.GetMin();
|
||
Vector3 max = obb.GetMax();
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [Bounds](../bounds/bounds.md) - 轴对齐包围盒
|
||
- [Vector3](../vector3/vector3.md) - 三维向量
|
||
- [Matrix4](../matrix4/matrix4.md) - 4x4 变换矩阵
|
||
- [Sphere](../sphere/sphere.md) - 球体
|