- 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 类总览方法列表
65 lines
2.0 KiB
Markdown
65 lines
2.0 KiB
Markdown
# Plane
|
||
|
||
**命名空间**: `XCEngine::Math`
|
||
|
||
**类型**: `struct`
|
||
|
||
**头文件**: `XCEngine/Core/Math/Plane.h`
|
||
|
||
**描述**: 平面,用于 3D 空间中的平面表示和相交测试
|
||
|
||
## 概述
|
||
|
||
`Plane` 结构体用于表示 3D 空间中的平面,通过法线向量(normal)和距离值(distance)定义。平面方程为 `dot(normal, point) + distance = 0`。常用于碰撞检测、视锥体裁剪、射线投射等图形学基础运算。
|
||
|
||
默认构造创建一个朝上(y 轴正方向)的单位平面。
|
||
|
||
## 结构体成员
|
||
|
||
| 成员 | 类型 | 描述 | 默认值 |
|
||
|------|------|------|--------|
|
||
| `normal` | `Vector3` | 平面法线向量 | `Vector3::Up()` |
|
||
| `distance` | `float` | 原点到平面的有符号距离 | `0.0f` |
|
||
|
||
## 公共方法
|
||
|
||
| 方法 | 描述 |
|
||
|------|------|
|
||
| [`Plane()`](constructor-default.md) | 默认构造函数,创建 y=0 平面 |
|
||
| [`Plane(normal, distance)`](constructor.md) | 从法线和距离构造平面 |
|
||
| [`FromPoints`](frompoints.md) | 从三个不共线点创建平面 |
|
||
| [`GetDistanceToPoint`](getdistancetopoint.md) | 计算点到平面的有符号距离 |
|
||
| [`GetClosestPoint`](getclosestpoint.md) | 计算平面上最接近给定点的点 |
|
||
| [`GetSide`](getside.md) | 判断点在平面的哪一侧 |
|
||
| [`Intersects`](intersects.md) | 检测与球体是否相交 |
|
||
|
||
## 使用示例
|
||
|
||
```cpp
|
||
#include <XCEngine/Core/Math/Plane.h>
|
||
#include <XCEngine/Core/Math/Vector3.h>
|
||
#include <XCEngine/Core/Math/Sphere.h>
|
||
|
||
using namespace XCEngine::Math;
|
||
|
||
void PlaneExample() {
|
||
Plane plane(Vector3::Up(), 0.0f);
|
||
|
||
Vector3 point(1.0f, 2.0f, 0.0f);
|
||
float dist = plane.GetDistanceToPoint(point);
|
||
|
||
Vector3 closest = plane.GetClosestPoint(point);
|
||
|
||
bool onNormalSide = plane.GetSide(point);
|
||
|
||
Sphere sphere(Vector3(1.0f, 0.5f, 0.0f), 1.0f);
|
||
bool intersects = plane.Intersects(sphere);
|
||
}
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [Math 模块总览](../math.md) - Math 模块总览
|
||
- [Sphere](../sphere/sphere.md) - 球体
|
||
- [Vector3](../vector3/vector3.md) - 三维向量
|