- 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 类总览方法列表
61 lines
1.8 KiB
Markdown
61 lines
1.8 KiB
Markdown
# Ray
|
||
|
||
**命名空间**: `XCEngine::Math`
|
||
|
||
**类型**: `struct`
|
||
|
||
**头文件**: `XCEngine/Core/Math/Ray.h`
|
||
|
||
**描述**: 射线,用于 3D 拾取和光线追踪
|
||
|
||
## 概述
|
||
|
||
`Ray` 表示从原点出发沿特定方向延伸的无限射线。通过 `direction` 方向的归一化,确保射线方向向量为单位长度,支持精确的交点计算。广泛应用于光线追踪、碰撞拾取和视锥体裁剪等图形学场景。
|
||
|
||
**注意**:构造时 `direction` 会被自动归一化。
|
||
|
||
## 结构体成员
|
||
|
||
| 成员 | 类型 | 描述 |
|
||
|------|------|------|
|
||
| `origin` | `Vector3` | 射线起点 |
|
||
| `direction` | `Vector3` | 射线方向(归一化) |
|
||
|
||
## 公共方法
|
||
|
||
| 方法 | 描述 |
|
||
|------|------|
|
||
| [`Ray()`](ray-constructor-default.md) | 默认构造函数 |
|
||
| [`Ray(origin, direction)`](ray-constructor.md) | 从起点和方向构造(direction 会被自动归一化) |
|
||
| [`GetPoint`](getpoint.md) | 获取射线上 t 距离处的点 |
|
||
| [`Intersects`](intersects-sphere.md) | 与球体相交检测 |
|
||
| [`Intersects`](intersects-box.md) | 与有向包围盒相交检测 |
|
||
| [`Intersects`](intersects-plane.md) | 与平面相交检测 |
|
||
|
||
## 使用示例
|
||
|
||
```cpp
|
||
#include <XCEngine/Core/Math/Ray.h>
|
||
#include <XCEngine/Core/Math/Vector3.h>
|
||
#include <XCEngine/Core/Math/Sphere.h>
|
||
|
||
using namespace XCEngine::Math;
|
||
|
||
Ray ray(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 0.0f, 0.0f));
|
||
Vector3 point = ray.GetPoint(5.0f); // point = (5, 0, 0)
|
||
|
||
Sphere sphere(Vector3(10.0f, 0.0f, 0.0f), 1.0f);
|
||
float t;
|
||
if (ray.Intersects(sphere, t)) {
|
||
Vector3 hitPoint = ray.GetPoint(t);
|
||
}
|
||
```
|
||
|
||
## 相关文档
|
||
|
||
- [Math 模块总览](../math.md) - Math 模块总览
|
||
- [Vector3](../vector3/vector3.md) - 方向和点类型
|
||
- [Sphere](../sphere/sphere.md) - 球体类型
|
||
- [Box](../box/box.md) - 包围盒类型
|
||
- [Plane](../plane/plane.md) - 平面类型
|