docs: update math API docs
This commit is contained in:
@@ -1,10 +1,16 @@
|
||||
# AABB / OBB
|
||||
|
||||
轴对齐包围盒 (AABB) 和有向包围盒 (OBB)。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/AABB.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/AABB.h`
|
||||
|
||||
**描述**: 轴对齐包围盒 (AABB) 和有向包围盒 (OBB)
|
||||
|
||||
## 概述
|
||||
|
||||
`AABB` 在 Math 库中通过 `Bounds` 类型实现。OBB 是可以任意方向旋转的包围盒。
|
||||
|
||||
## AABB
|
||||
|
||||
@@ -14,30 +20,28 @@
|
||||
|
||||
OBB 是可以任意方向旋转的包围盒。
|
||||
|
||||
```cpp
|
||||
struct OBB {
|
||||
Vector3 center;
|
||||
Vector3 extents;
|
||||
Matrix4 transform;
|
||||
};
|
||||
```
|
||||
## 结构体成员
|
||||
|
||||
### 构造函数
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `center` | `Vector3` | OBB 中心点 |
|
||||
| `extents` | `Vector3` | 从中心到每个面的距离 |
|
||||
| `transform` | `Matrix4` | 变换矩阵 |
|
||||
|
||||
- `OBB()` - 默认构造
|
||||
- `OBB(const Vector3& center, const Vector3& extents)` - 从中心和半长构造
|
||||
## 公共方法
|
||||
|
||||
### 实例方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [GetAxis(index)](getaxis.md) | `Vector3` | 获取局部轴(index 必须是 0、1 或 2) |
|
||||
| [GetMin()](../box/getmin.md) | `Vector3` | 局部空间最小点 |
|
||||
| [GetMax()](../box/getmax.md) | `Vector3` | 局部空间最大点 |
|
||||
| [Contains(point)](../box/contains.md) | `bool` | 点是否在 OBB 内 |
|
||||
| [Intersects(OBB)](intersects-obb.md) | `bool` | 与另一个 OBB 相交 |
|
||||
| [Intersects(Sphere)](intersects-sphere.md) | `bool` | 与球体相交 |
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| `OBB()` | 默认构造 |
|
||||
| `OBB(const Vector3& center, const Vector3& extents)` | 从中心和半长构造 |
|
||||
| [GetAxis](obb-getaxis.md) | 获取局部轴 |
|
||||
| [GetMin](obb-getmin.md) | 局部空间最小点 |
|
||||
| [GetMax](obb-getmax.md) | 局部空间最大点 |
|
||||
| [Contains](obb-contains.md) | 点是否在 OBB 内 |
|
||||
| [Intersects(OBB)](intersects-obb.md) | 与另一个 OBB 相交 |
|
||||
| [Intersects(Sphere)](intersects-sphere.md) | 与球体相交 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Bounds](bounds/bounds.md) - 轴对齐包围盒
|
||||
- [Math 模块总览](../math.md)
|
||||
@@ -1,23 +0,0 @@
|
||||
# OBB::GetAxis
|
||||
|
||||
```cpp
|
||||
Vector3 GetAxis(int index) const
|
||||
```
|
||||
|
||||
获取 OBB 的局部坐标轴。
|
||||
|
||||
**参数:**
|
||||
- `index` - 轴索引(0=X轴, 1=Y轴, 2=Z轴)
|
||||
|
||||
**返回:** `Vector3` - 对应轴的方向向量
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
OBB obb = ...;
|
||||
Vector3 xAxis = obb.GetAxis(0); // 局部 X 轴
|
||||
Vector3 yAxis = obb.GetAxis(1); // 局部 Y 轴
|
||||
Vector3 zAxis = obb.GetAxis(2); // 局部 Z 轴
|
||||
```
|
||||
@@ -11,6 +11,8 @@ bool Intersects(const OBB& other) const
|
||||
|
||||
**返回:** `bool` - true 表示相交
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -22,3 +24,7 @@ if (obbA.Intersects(obbB)) {
|
||||
// 两个有向包围盒相交
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AABB 总览](aabb.md) - 返回 AABB/OBB 总览
|
||||
@@ -11,6 +11,8 @@ bool Intersects(const Sphere& sphere) const
|
||||
|
||||
**返回:** `bool` - true 表示相交
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -22,3 +24,7 @@ if (obb.Intersects(sphere)) {
|
||||
// OBB 与球体相交
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AABB 总览](aabb.md) - 返回 AABB/OBB 总览
|
||||
@@ -11,6 +11,8 @@ bool Contains(const Vector3& point) const
|
||||
|
||||
**返回:** `bool` - true 表示点在 OBB 内
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -18,3 +20,7 @@ bool Contains(const Vector3& point) const
|
||||
```cpp
|
||||
if (obb.Contains(point)) { /* inside */ }
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AABB 总览](aabb.md) - 返回 AABB/OBB 总览
|
||||
@@ -11,6 +11,8 @@ Vector3 GetAxis(int index) const
|
||||
|
||||
**返回:** `Vector3` - 对应的局部轴
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -18,3 +20,7 @@ Vector3 GetAxis(int index) const
|
||||
```cpp
|
||||
Vector3 xAxis = obb.GetAxis(0);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AABB 总览](aabb.md) - 返回 AABB/OBB 总览
|
||||
@@ -8,6 +8,8 @@ Vector3 GetMax() const
|
||||
|
||||
**返回:** `Vector3` - center + extents
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +17,7 @@ Vector3 GetMax() const
|
||||
```cpp
|
||||
Vector3 max = obb.GetMax();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AABB 总览](aabb.md) - 返回 AABB/OBB 总览
|
||||
@@ -8,6 +8,8 @@ Vector3 GetMin() const
|
||||
|
||||
**返回:** `Vector3` - center - extents
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +17,7 @@ Vector3 GetMin() const
|
||||
```cpp
|
||||
Vector3 min = obb.GetMin();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AABB 总览](aabb.md) - 返回 AABB/OBB 总览
|
||||
@@ -1,25 +0,0 @@
|
||||
# OBB::Intersects(OBB)
|
||||
|
||||
```cpp
|
||||
bool Intersects(const OBB& other) const;
|
||||
```
|
||||
|
||||
判断两个 OBB 是否相交(SAT 分离轴定理)。
|
||||
|
||||
**返回:** 两包围盒是否相交
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
OBB a(centerA, extentsA);
|
||||
OBB b(centerB, extentsB);
|
||||
if (a.Intersects(b)) {
|
||||
// 两包围盒相交
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AABB 总览](aabb.md) - 返回 AABB 概览
|
||||
@@ -1,28 +0,0 @@
|
||||
# OBB::Intersects(Sphere)
|
||||
|
||||
```cpp
|
||||
bool Intersects(const Sphere& sphere) const;
|
||||
```
|
||||
|
||||
判断 OBB 与球体是否相交。
|
||||
|
||||
**参数:**
|
||||
- `sphere` - 球体
|
||||
|
||||
**返回:** OBB 与球体是否相交
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
OBB obb(center, extents);
|
||||
Sphere s(sphereCenter, radius);
|
||||
if (obb.Intersects(s)) {
|
||||
// OBB 与球体相交
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [AABB 总览](aabb.md) - 返回 AABB 概览
|
||||
38
docs/api/math/bounds/bounds.constructors.md
Normal file
38
docs/api/math/bounds/bounds.constructors.md
Normal file
@@ -0,0 +1,38 @@
|
||||
# Bounds::Bounds
|
||||
|
||||
```cpp
|
||||
Bounds()
|
||||
Bounds(const Vector3& center, const Vector3& size)
|
||||
```
|
||||
|
||||
构造一个 Bounds 对象。默认构造函数创建中心为原点、范围为零的包围盒。
|
||||
|
||||
**参数:**
|
||||
- `center` - 包围盒的中心点
|
||||
- `size` - 包围盒的完整尺寸(非 extents,构造时会自动除以 2)
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
// 默认构造
|
||||
Bounds empty;
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
// center = (0,0,0), extents = (1,1,1), 实际尺寸为 2x2x2
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [GetMin](getmin.md) - 获取最小点
|
||||
- [GetMax](getmax.md) - 获取最大点
|
||||
@@ -1,40 +1,64 @@
|
||||
# Bounds
|
||||
|
||||
轴对齐包围盒 (AABB),中心-范围表示。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Bounds.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Bounds.h`
|
||||
|
||||
## 结构体定义
|
||||
**描述**: 轴对齐包围盒,用于场景管理中的快速剔除
|
||||
|
||||
## 概述
|
||||
|
||||
Bounds 表示一个轴对齐包围盒(AABB),使用中心点 `center` 和范围 `extents` 定义。`extents` 是从中心到包围盒每个面的距离,因此实际尺寸为 `extents * 2`。常用于视锥剔除、碰撞检测和场景管理中的快速排除不可见物体。
|
||||
|
||||
## 结构体成员
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `center` | `Vector3` | 包围盒中心点 |
|
||||
| `extents` | `Vector3` | 从中心到每个面的距离(实际尺寸 = extents * 2) |
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Bounds`](bounds.constructors.md) | 构造函数 |
|
||||
| [`GetMin`](getmin.md) | 获取包围盒最小点 |
|
||||
| [`GetMax`](getmax.md) | 获取包围盒最大点 |
|
||||
| [`SetMinMax`](setminmax.md) | 从最小/最大点设置包围盒 |
|
||||
| [`Intersects`](intersects.md) | 检测与另一个 Bounds 是否相交 |
|
||||
| [`Contains`](contains.md) | 检测点是否在盒内 |
|
||||
| [`Encapsulate`](encapsulate.md) | 扩展包围盒以包含点或另一个 Bounds |
|
||||
| [`Expand`](expand.md) | 扩展包围盒 |
|
||||
| [`GetClosestPoint`](getclosestpoint.md) | 获取盒上最接近给定点的点 |
|
||||
| [`GetVolume`](getvolume.md) | 计算包围盒体积 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
struct Bounds {
|
||||
Vector3 center = Vector3::Zero();
|
||||
Vector3 extents = Vector3::Zero();
|
||||
};
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
|
||||
Vector3 min = bounds.GetMin();
|
||||
Vector3 max = bounds.GetMax();
|
||||
|
||||
bounds.Expand(1.0f);
|
||||
|
||||
if (bounds.Contains(Vector3(0.0f, 0.0f, 0.0f))) {
|
||||
// point is inside
|
||||
}
|
||||
|
||||
Bounds other(Vector3(5.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||||
if (bounds.Intersects(other)) {
|
||||
// bounds intersect
|
||||
}
|
||||
```
|
||||
|
||||
## 构造函数
|
||||
|
||||
- `Bounds()` - 默认构造
|
||||
- `Bounds(const Vector3& center, const Vector3& size)` - 从中心和大小构造
|
||||
|
||||
## 实例方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [GetMin()](getmin.md) | `Vector3` | 最小点 |
|
||||
| [GetMax()](getmax.md) | 最大点 |
|
||||
| [SetMinMax(min, max)](setminmax.md) | `void` | 从最小/最大点设置 |
|
||||
| [Contains(point)](contains.md) | `bool` | 点是否在盒内 |
|
||||
| [Intersects(other)](intersects.md) | `bool` | 与另一个 Bounds 相交 |
|
||||
| [Encapsulate(point)](encapsulate.md) | `void` | 扩展包含点 |
|
||||
| [Encapsulate(bounds)](encapsulate-bounds.md) | `void` | 扩展包含另一个 Bounds |
|
||||
| [Expand(amount)](expand.md) | `void` | 扩展包围盒 |
|
||||
| [GetClosestPoint(point)](getclosestpoint.md) | `Vector3` | 盒上最接近的点 |
|
||||
| [GetVolume()](getvolume.md) | `float` | 体积 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
|
||||
@@ -4,17 +4,35 @@
|
||||
bool Contains(const Vector3& point) const
|
||||
```
|
||||
|
||||
检测点是否在包围盒内。
|
||||
检测给定点是否在包围盒内部。边界上的点被视为在盒内。
|
||||
|
||||
**参数:**
|
||||
- `point` - 要检测的点
|
||||
|
||||
**返回:** `bool` - true 表示点在盒内
|
||||
**返回:** `bool` - true 表示点在盒内(包括边界)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
if (bounds.Contains(point)) { /* inside */ }
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
if (bounds.Contains(Vector3(0.0f, 0.0f, 0.0f))) {
|
||||
// center is inside
|
||||
}
|
||||
if (!bounds.Contains(Vector3(10.0f, 0.0f, 0.0f))) {
|
||||
// far away point is outside
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [Intersects](intersects.md) - 检测与另一个 Bounds 是否相交
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
# Bounds::Encapsulate (Bounds)
|
||||
|
||||
```cpp
|
||||
void Encapsulate(const Bounds& bounds)
|
||||
```
|
||||
|
||||
扩展包围盒以包含另一个 Bounds。
|
||||
|
||||
**参数:**
|
||||
- `bounds` - 要包含的 Bounds
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
bounds.Encapsulate(otherBounds);
|
||||
```
|
||||
@@ -5,17 +5,36 @@ void Encapsulate(const Vector3& point)
|
||||
void Encapsulate(const Bounds& bounds)
|
||||
```
|
||||
|
||||
扩展包围盒以包含点或另一个 Bounds。
|
||||
扩展包围盒以包含指定的点或另一个 Bounds。调用后,包围盒的 min/max 将被更新以确保目标被完全包含。
|
||||
|
||||
**参数:**
|
||||
- `point` - 要包含的点
|
||||
- `bounds` - 要包含的 Bounds
|
||||
|
||||
**返回:** `void`
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
bounds.Encapsulate(point);
|
||||
bounds.Encapsulate(otherBounds);
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
bounds.Encapsulate(Vector3(10.0f, 0.0f, 0.0f));
|
||||
// bounds now spans from (-1,-1,-1) to (10,1,1)
|
||||
|
||||
Bounds other(Vector3(5.0f, 5.0f, 5.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||||
bounds.Encapsulate(other);
|
||||
// bounds now contains both original bounds and 'other'
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [Expand](expand.md) - 均匀扩展包围盒
|
||||
|
||||
@@ -5,15 +5,34 @@ void Expand(float amount)
|
||||
void Expand(const Vector3& amount)
|
||||
```
|
||||
|
||||
扩展包围盒。
|
||||
扩展包围盒。输入值会被除以 2 后添加到 extents 上(标量扩展时,每个轴的 extents 增加 `amount * 0.5f`,即实际尺寸增加 `amount`;向量扩展时,各分量分别处理)。
|
||||
|
||||
**参数:**
|
||||
- `amount` - 扩展量(各方向或统一)
|
||||
- `amount` - 扩展量(标量时各方向均匀扩展,向量时各分量分别扩展)
|
||||
|
||||
**返回:** `void`
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
bounds.Expand(1.0f);
|
||||
// extents becomes (2.0, 2.0, 2.0), size increased by 1 in each direction
|
||||
|
||||
bounds.Expand(Vector3(1.0f, 0.0f, 0.0f));
|
||||
// extents becomes (2.5, 2.0, 2.0), only x extended
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [Encapsulate](encapsulate.md) - 扩展以包含点或 Bounds
|
||||
|
||||
@@ -4,17 +4,35 @@
|
||||
Vector3 GetClosestPoint(const Vector3& point) const
|
||||
```
|
||||
|
||||
获取包围盒上最接近给定点的点。
|
||||
获取包围盒上最接近给定点的点。如果点在盒内,则返回该点本身;如果在盒外,则返回该点在盒面上的投影点。
|
||||
|
||||
**参数:**
|
||||
- `point` - 参考点
|
||||
|
||||
**返回:** `Vector3` - 盒上最接近的点
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Vector3 closest = bounds.GetClosestPoint(point);
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
|
||||
Vector3 inside = bounds.GetClosestPoint(Vector3(0.0f, 0.0f, 0.0f));
|
||||
// returns (0, 0, 0) since point is inside
|
||||
|
||||
Vector3 outside = bounds.GetClosestPoint(Vector3(10.0f, 0.0f, 0.0f));
|
||||
// returns (1, 0, 0) - closest point on box surface
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [Contains](contains.md) - 检测点是否在盒内
|
||||
|
||||
@@ -4,14 +4,28 @@
|
||||
Vector3 GetMax() const
|
||||
```
|
||||
|
||||
获取包围盒的最大点。
|
||||
获取包围盒的最大点(最大 corner)。
|
||||
|
||||
**返回:** `Vector3` - center + extents
|
||||
**返回:** `Vector3` - 包围盒最大点,等于 `center + extents`
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
Vector3 max = bounds.GetMax();
|
||||
// max = (1.0f, 1.0f, 1.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [GetMin](getmin.md) - 获取最小点
|
||||
|
||||
@@ -4,14 +4,28 @@
|
||||
Vector3 GetMin() const
|
||||
```
|
||||
|
||||
获取包围盒的最小点。
|
||||
获取包围盒的最小点(最小 corner)。
|
||||
|
||||
**返回:** `Vector3` - center - extents
|
||||
**返回:** `Vector3` - 包围盒最小点,等于 `center - extents`
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
Vector3 min = bounds.GetMin();
|
||||
// min = (-1.0f, -1.0f, -1.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [GetMax](getmax.md) - 获取最大点
|
||||
|
||||
@@ -4,14 +4,27 @@
|
||||
float GetVolume() const
|
||||
```
|
||||
|
||||
计算包围盒的体积。
|
||||
计算包围盒的体积。返回 `extents.x * 2.0f * extents.y * 2.0f * extents.z * 2.0f`。
|
||||
|
||||
**返回:** `float` - 体积
|
||||
**返回:** `float` - 包围盒体积
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 2.0f, 3.0f));
|
||||
float vol = bounds.GetVolume();
|
||||
// vol = 2 * 4 * 6 = 48
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
|
||||
@@ -4,17 +4,33 @@
|
||||
bool Intersects(const Bounds& other) const
|
||||
```
|
||||
|
||||
检测两个 Bounds 是否相交。
|
||||
检测该包围盒与另一个 Bounds 是否相交(重叠)。使用简化的 AABB 重叠检测算法,通过比较两个包围盒中心距离与它们 extents 之和来判断是否相交。
|
||||
|
||||
**参数:**
|
||||
- `other` - 另一个 Bounds
|
||||
|
||||
**返回:** `bool` - true 表示相交
|
||||
**返回:** `bool` - true 表示两个 Bounds 相交
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
if (bounds.Intersects(other)) { /* collision */ }
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds a(Vector3(0.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
Bounds b(Vector3(1.0f, 0.0f, 0.0f), Vector3(2.0f, 2.0f, 2.0f));
|
||||
if (a.Intersects(b)) {
|
||||
// a and b overlap
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [Contains](contains.md) - 检测点是否在盒内
|
||||
|
||||
@@ -4,16 +4,33 @@
|
||||
void SetMinMax(const Vector3& min, const Vector3& max)
|
||||
```
|
||||
|
||||
从最小/最大点设置包围盒。
|
||||
从最小点和最大点设置包围盒。中心点和范围由输入的 min/max 计算得出。
|
||||
|
||||
**参数:**
|
||||
- `min` - 最小点
|
||||
- `max` - 最大点
|
||||
- `min` - 包围盒的最小点
|
||||
- `max` - 包围盒的最大点
|
||||
|
||||
**返回:** `void`
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
bounds.SetMinMax(minPoint, maxPoint);
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Bounds bounds;
|
||||
bounds.SetMinMax(Vector3(-1.0f, -1.0f, -1.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||||
// center = (0, 0, 0), extents = (1, 1, 1)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Bounds](bounds.md) - 返回类总览
|
||||
- [GetMin](getmin.md) - 获取最小点
|
||||
- [GetMax](getmax.md) - 获取最大点
|
||||
|
||||
@@ -1,44 +1,65 @@
|
||||
# Box
|
||||
|
||||
带变换的包围盒结构体(支持 OBB 语义,取决于方法)。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Box.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/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
|
||||
struct Box {
|
||||
Vector3 center = Vector3::Zero();
|
||||
Vector3 extents = Vector3::Zero();
|
||||
Matrix4x4 transform = Matrix4x4::Identity();
|
||||
};
|
||||
#include <XCEngine/Math/Box.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
#include <XCEngine/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)) {
|
||||
}
|
||||
```
|
||||
|
||||
**成员:**
|
||||
- `center` - 包围盒中心点
|
||||
- `extents` - 包围盒半长(各轴向的半径)
|
||||
- `transform` - 变换矩阵(用于 OBB 检测)
|
||||
|
||||
**注意:** `Contains` 方法会使用 `transform` 进行真正的 OBB 检测。`Intersects(Box)` 目前使用 AABB 简化算法,未考虑旋转。
|
||||
|
||||
## 构造函数
|
||||
|
||||
- `Box()` - 默认构造
|
||||
- `Box(const Vector3& center, const Vector3& extents)` - 从中心和半长构造
|
||||
|
||||
## 实例方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [GetMin()](getmin.md) | `Vector3` | 局部空间最小点 |
|
||||
| [GetMax()](getmax.md) | `Vector3` | 局部空间最大点 |
|
||||
| [Contains(point)](contains.md) | `bool` | 点是否在盒内(使用 transform) |
|
||||
| [Intersects(Sphere)](intersects.md) | `bool` | 与球体相交 |
|
||||
| [Intersects(Box)](intersects-box.md) | `bool` | 与另一个盒相交(AABB 检测) |
|
||||
| [Intersects(Ray, t)](intersects-ray.md) | `bool` | 与射线相交 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
|
||||
42
docs/api/math/box/constructor.md
Normal file
42
docs/api/math/box/constructor.md
Normal file
@@ -0,0 +1,42 @@
|
||||
# Box::Box
|
||||
|
||||
## 默认构造函数
|
||||
|
||||
```cpp
|
||||
Box() = default;
|
||||
```
|
||||
|
||||
构造一个盒体,`center` 为原点,`extents` 为零向量,`transform` 为单位矩阵。
|
||||
|
||||
## 带参构造函数
|
||||
|
||||
```cpp
|
||||
Box(const Vector3& center, const Vector3& extents)
|
||||
```
|
||||
|
||||
从指定的中心和半长构造一个盒体。
|
||||
|
||||
**参数:**
|
||||
- `center` - 盒体的中心点
|
||||
- `extents` - 盒体在各轴向上的半长(从中心到面的距离)
|
||||
|
||||
**返回:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Box.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Box box(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 2.0f, 1.5f));
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Box 类总览](box.md) - 返回类总览
|
||||
@@ -4,17 +4,30 @@
|
||||
bool Contains(const Vector3& point) const
|
||||
```
|
||||
|
||||
检测点是否在盒内。
|
||||
检测点是否在盒体内。该方法使用 `transform` 矩阵将点转换到盒体局部空间进行检测,支持 OBB 语义。
|
||||
|
||||
**参数:**
|
||||
- `point` - 要检测的点
|
||||
- `point` - 要检测的点(世界坐标)
|
||||
|
||||
**返回:** `bool` - true 表示点在盒内
|
||||
**返回:** `bool` - 点在盒体内返回 true,否则返回 false
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
if (box.Contains(point)) { /* inside */ }
|
||||
#include <XCEngine/Math/Box.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Box box(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||||
if (box.Contains(Vector3(0.5f, 0.5f, 0.5f))) {
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Box 类总览](box.md) - 返回类总览
|
||||
|
||||
@@ -4,14 +4,29 @@
|
||||
Vector3 GetMax() const
|
||||
```
|
||||
|
||||
获取局部空间最大点。
|
||||
获取盒体在局部空间中的最大点(角点)。
|
||||
|
||||
**返回:** `Vector3` - (+extents)
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 盒体最大点,即 `center + extents`
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Box.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Box box(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 2.0f, 1.0f));
|
||||
Vector3 max = box.GetMax();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Box 类总览](box.md) - 返回类总览
|
||||
- [GetMin](getmin.md) - 获取最小点
|
||||
|
||||
@@ -4,14 +4,29 @@
|
||||
Vector3 GetMin() const
|
||||
```
|
||||
|
||||
获取局部空间最小点。
|
||||
获取盒体在局部空间中的最小点(角点)。
|
||||
|
||||
**返回:** `Vector3` - (-extents)
|
||||
**参数:** 无
|
||||
|
||||
**返回:** `Vector3` - 盒体最小点,即 `center - extents`
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Box.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Box box(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 2.0f, 1.0f));
|
||||
Vector3 min = box.GetMin();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Box 类总览](box.md) - 返回类总览
|
||||
- [GetMax](getmax.md) - 获取最大点
|
||||
|
||||
@@ -4,19 +4,32 @@
|
||||
bool Intersects(const Box& other) const
|
||||
```
|
||||
|
||||
检测两个盒是否相交(使用 AABB 简化算法,暂未考虑 transform 旋转)。
|
||||
检测两个盒体是否相交。该方法使用 AABB 简化算法,通过比较两个盒体的最小点和最大点进行相交检测。
|
||||
|
||||
**注意:** 当前实现为 AABB 检测,未使用 `transform` 进行真正的 OBB-SAT 检测。
|
||||
|
||||
**参数:**
|
||||
- `other` - 另一个盒
|
||||
- `other` - 另一个盒体
|
||||
|
||||
**返回:** `bool` - true 表示相交
|
||||
**返回:** `bool` - 相交返回 true,否则返回 false
|
||||
|
||||
**注意:** 当前实现为 AABB 检测,未使用 transform 进行真正的 OBB-SAT 检测。
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
if (box.Intersects(otherBox)) { /* collision */ }
|
||||
#include <XCEngine/Math/Box.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Box box1(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||||
Box box2(Vector3(1.5f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||||
if (box1.Intersects(box2)) {
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Box 类总览](box.md) - 返回类总览
|
||||
|
||||
@@ -4,21 +4,35 @@
|
||||
bool Intersects(const Ray& ray, float& t) const
|
||||
```
|
||||
|
||||
检测盒是否与射线相交。
|
||||
检测盒体是否与射线相交。如果相交,通过 `t` 输出射线原点到交点的距离。
|
||||
|
||||
**参数:**
|
||||
- `ray` - 射线
|
||||
- `t` - 输出交点距离
|
||||
- `ray` - 要检测的射线
|
||||
- `t` - 输出交点距离(如果返回 true)
|
||||
|
||||
**返回:** `bool` - true 表示相交
|
||||
**返回:** `bool` - 相交返回 true,否则返回 false
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Box.h>
|
||||
#include <XCEngine/Math/Ray.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Box box(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||||
Ray ray(Vector3(0.0f, 0.0f, -5.0f), Vector3(0.0f, 0.0f, 1.0f));
|
||||
float t;
|
||||
if (box.Intersects(ray, t)) {
|
||||
Vector3 hit = ray.GetPoint(t);
|
||||
Vector3 hitPoint = ray.GetPoint(t);
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Box 类总览](box.md) - 返回类总览
|
||||
- [Ray::Intersects](../ray/ray.md) - 射线相交检测
|
||||
|
||||
@@ -1,20 +1,34 @@
|
||||
# Box::Intersects
|
||||
# Box::Intersects (Sphere)
|
||||
|
||||
```cpp
|
||||
bool Intersects(const Sphere& sphere) const
|
||||
```
|
||||
|
||||
检测盒是否与球体相交。
|
||||
检测盒体是否与球体相交。该方法使用 `transform` 矩阵将球体中心转换到盒体局部空间进行检测,支持 OBB 语义。
|
||||
|
||||
**参数:**
|
||||
- `sphere` - 球体
|
||||
- `sphere` - 要检测的球体
|
||||
|
||||
**返回:** `bool` - true 表示相交
|
||||
**返回:** `bool` - 相交返回 true,否则返回 false
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
if (box.Intersects(sphere)) { /* collision */ }
|
||||
#include <XCEngine/Math/Box.h>
|
||||
#include <XCEngine/Math/Sphere.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Box box(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 1.0f, 1.0f));
|
||||
Sphere sphere(Vector3(2.0f, 0.0f, 0.0f), 1.0f);
|
||||
if (box.Intersects(sphere)) {
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Box 类总览](box.md) - 返回类总览
|
||||
|
||||
@@ -6,6 +6,19 @@ static Color Black()
|
||||
|
||||
返回黑色 (0, 0, 0, 1)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 黑色
|
||||
|
||||
**示例:** `Color c = Color::Black();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::Black();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`White`](white.md) - 返回白色
|
||||
|
||||
@@ -6,6 +6,19 @@ static Color Blue()
|
||||
|
||||
返回蓝色 (0, 0, 1, 1)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 蓝色
|
||||
|
||||
**示例:** `Color c = Color::Blue();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::Blue();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`Yellow`](yellow.md) - 返回黄色
|
||||
|
||||
@@ -6,6 +6,19 @@ static Color Clear()
|
||||
|
||||
返回透明黑色 (0, 0, 0, 0)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 透明黑色
|
||||
|
||||
**示例:** `Color c = Color::Clear();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::Clear();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`Black`](black.md) - 返回不透明黑色
|
||||
|
||||
@@ -1,63 +1,93 @@
|
||||
# Color
|
||||
|
||||
颜色结构体,支持 RGBA 浮点分量。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Color.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Color.h`
|
||||
|
||||
## 结构体定义
|
||||
**描述**: 颜色结构体,支持 RGBA 浮点分量,用于图形渲染
|
||||
|
||||
```cpp
|
||||
struct Color {
|
||||
float r = 1.0f;
|
||||
float g = 1.0f;
|
||||
float b = 1.0f;
|
||||
float a = 1.0f;
|
||||
};
|
||||
```
|
||||
## 概述
|
||||
|
||||
`Color` 是一个简单的 RGBA 颜色结构体,每个分量使用 32 位浮点数,范围 [0, 1]。默认构造创建白色 (1, 1, 1, 1)。该结构体提供静态工厂方法创建常用颜色,以及颜色插值和格式转换功能。
|
||||
|
||||
## 结构体成员
|
||||
|
||||
| 成员 | 类型 | 描述 | 默认值 |
|
||||
|------|------|------|--------|
|
||||
| `r` | `float` | 红色分量,范围 [0, 1] | `1.0f` |
|
||||
| `g` | `float` | 绿色分量,范围 [0, 1] | `1.0f` |
|
||||
| `b` | `float` | 蓝色分量,范围 [0, 1] | `1.0f` |
|
||||
| `a` | `float` | Alpha 分量,范围 [0, 1] | `1.0f` |
|
||||
|
||||
## 构造函数
|
||||
|
||||
- `Color()` - 默认构造,初始化为白色 (1, 1, 1, 1)
|
||||
- `constexpr Color(float r, float g, float b, float a = 1.0f)` - 从 RGBA 分量构造
|
||||
### 默认构造函数
|
||||
|
||||
## 静态工厂方法
|
||||
```cpp
|
||||
Color() = default;
|
||||
```
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [White()](white.md) | `Color` | (1, 1, 1, 1) |
|
||||
| [Black()](black.md) | `Color` | (0, 0, 0, 1) |
|
||||
| [Red()](red.md) | `Color` | (1, 0, 0, 1) |
|
||||
| [Green()](green.md) | `Color` | (0, 1, 0, 1) |
|
||||
| [Blue()](blue.md) | `Color` | (0, 0, 1, 1) |
|
||||
| [Yellow()](yellow.md) | `Color` | (1, 1, 0, 1) |
|
||||
| [Cyan()](cyan.md) | `Color` | (0, 1, 1, 1) |
|
||||
| [Magenta()](magenta.md) | `Color` | (1, 0, 1, 1) |
|
||||
| [Clear()](clear.md) | `Color` | (0, 0, 0, 0),透明黑 |
|
||||
创建白色 (1, 1, 1, 1)。
|
||||
|
||||
## 静态方法
|
||||
### 带参构造函数
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Lerp(a, b, t)](lerp.md) | `Color` | 颜色线性插值 |
|
||||
```cpp
|
||||
constexpr Color(float r, float g, float b, float a = 1.0f)
|
||||
```
|
||||
|
||||
## 实例方法
|
||||
构造指定 RGBA 值的颜色。
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [ToRGBA()](torgba.md) | `uint32_t` | 转换为 32-bit RGBA (0xRRGGBBAA) |
|
||||
| [ToVector3()](tovector3.md) | `Vector3` | 转换为 RGB (丢弃 alpha) |
|
||||
| [ToVector4()](tovector4.md) | `Vector4` | 转换为 RGBA |
|
||||
**参数:**
|
||||
- `r` - 红色分量,范围 [0, 1]
|
||||
- `g` - 绿色分量,范围 [0, 1]
|
||||
- `b` - 蓝色分量,范围 [0, 1]
|
||||
- `a` - Alpha 分量,范围 [0, 1],默认值为 1.0f(完全不透明)
|
||||
|
||||
## 运算符
|
||||
**返回:** `Color` - 构造的颜色
|
||||
|
||||
| 运算符 | 描述 |
|
||||
|--------|------|
|
||||
| `operator+(Color, Color)` | 颜色相加 |
|
||||
| `operator-(Color, Color)` | 颜色相减 |
|
||||
| `operator*(Color, float)` | 颜色乘以标量 |
|
||||
| `operator/(Color, float)` | 颜色除以标量 |
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color red(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
Color halfAlpha(0.5f, 0.5f, 0.5f); // a = 1.0f
|
||||
```
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`White`](white.md) | 返回白色 (1, 1, 1, 1) |
|
||||
| [`Black`](black.md) | 返回黑色 (0, 0, 0, 1) |
|
||||
| [`Red`](red.md) | 返回红色 (1, 0, 0, 1) |
|
||||
| [`Green`](green.md) | 返回绿色 (0, 1, 0, 1) |
|
||||
| [`Blue`](blue.md) | 返回蓝色 (0, 0, 1, 1) |
|
||||
| [`Yellow`](yellow.md) | 返回黄色 (1, 1, 0, 1) |
|
||||
| [`Cyan`](cyan.md) | 返回青色 (0, 1, 1, 1) |
|
||||
| [`Magenta`](magenta.md) | 返回品红色 (1, 0, 1, 1) |
|
||||
| [`Clear`](clear.md) | 返回透明黑色 (0, 0, 0, 0) |
|
||||
| [`Lerp`](lerp.md) | 颜色线性插值 |
|
||||
| [`ToRGBA`](torgba.md) | 转换为 32-bit RGBA 整数 |
|
||||
| [`ToVector3`](tovector3.md) | 转换为 Vector3(丢弃 alpha) |
|
||||
| [`ToVector4`](tovector4.md) | 转换为 Vector4 |
|
||||
| [`operator+`](operator-add.md) | 颜色相加 |
|
||||
| [`operator-`](operator-sub.md) | 颜色相减 |
|
||||
| [`operator*`](operator-mul.md) | 颜色乘以标量 |
|
||||
| [`operator/`](operator-div.md) | 颜色除以标量 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
#include <XCEngine/Math/Color.h>
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Color c1 = Color::Red();
|
||||
Color c2 = Color(0, 1, 0, 1);
|
||||
Color blended = Color::Lerp(c1, c2, 0.5f);
|
||||
uint32_t rgba = blended.ToRGBA();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
|
||||
@@ -6,6 +6,19 @@ static Color Cyan()
|
||||
|
||||
返回青色 (0, 1, 1, 1)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 青色
|
||||
|
||||
**示例:** `Color c = Color::Cyan();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::Cyan();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`Magenta`](magenta.md) - 返回品红色
|
||||
|
||||
@@ -6,6 +6,19 @@ static Color Green()
|
||||
|
||||
返回绿色 (0, 1, 0, 1)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 绿色
|
||||
|
||||
**示例:** `Color c = Color::Green();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::Green();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`Red`](red.md) - 返回红色
|
||||
|
||||
@@ -9,9 +9,11 @@ static Color Lerp(const Color& a, const Color& b, float t)
|
||||
**参数:**
|
||||
- `a` - 起始颜色
|
||||
- `b` - 结束颜色
|
||||
- `t` - 插值因子 (0-1)
|
||||
- `t` - 插值因子,范围 [0, 1]。超出范围的值会被 clamp 到 [0, 1]
|
||||
|
||||
**返回:** `Color` - 插值结果
|
||||
**返回:** `Color` - 插值结果,当 t=0 时返回 a,t=1 时返回 b
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
@@ -20,3 +22,7 @@ static Color Lerp(const Color& a, const Color& b, float t)
|
||||
```cpp
|
||||
Color lerped = Color::Lerp(Color::Red(), Color::Blue(), 0.5f);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
|
||||
@@ -6,6 +6,19 @@ static Color Magenta()
|
||||
|
||||
返回品红色 (1, 0, 1, 1)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 品红色
|
||||
|
||||
**示例:** `Color c = Color::Magenta();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::Magenta();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`Cyan`](cyan.md) - 返回青色
|
||||
|
||||
29
docs/api/math/color/operator-add.md
Normal file
29
docs/api/math/color/operator-add.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Color::operator+
|
||||
|
||||
```cpp
|
||||
Color operator+(const Color& other) const
|
||||
```
|
||||
|
||||
将两个颜色对应分量相加,返回新的颜色。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要加的另一个颜色
|
||||
|
||||
**返回:** `Color` - 分量相加后的新颜色
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color red = Color::Red();
|
||||
Color blue = Color::Blue();
|
||||
Color purple = red + blue;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`operator-`](operator-sub.md) - 颜色相减
|
||||
28
docs/api/math/color/operator-div.md
Normal file
28
docs/api/math/color/operator-div.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Color::operator/
|
||||
|
||||
```cpp
|
||||
Color operator/(float scalar) const
|
||||
```
|
||||
|
||||
将颜色每个分量除以一个标量值,返回新的颜色。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 非零标量除数
|
||||
|
||||
**返回:** `Color` - 缩放后的新颜色
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color red = Color::Red();
|
||||
Color dimRed = red / 2.0f;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`operator*`](operator-mul.md) - 颜色乘以标量
|
||||
28
docs/api/math/color/operator-mul.md
Normal file
28
docs/api/math/color/operator-mul.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Color::operator*
|
||||
|
||||
```cpp
|
||||
Color operator*(float scalar) const
|
||||
```
|
||||
|
||||
将颜色每个分量乘以一个标量值,返回新的颜色。
|
||||
|
||||
**参数:**
|
||||
- `scalar` - 标量乘数
|
||||
|
||||
**返回:** `Color` - 缩放后的新颜色
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color red = Color::Red();
|
||||
Color fadedRed = red * 0.5f;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`operator/`](operator-div.md) - 颜色除以标量
|
||||
29
docs/api/math/color/operator-sub.md
Normal file
29
docs/api/math/color/operator-sub.md
Normal file
@@ -0,0 +1,29 @@
|
||||
# Color::operator-
|
||||
|
||||
```cpp
|
||||
Color operator-(const Color& other) const
|
||||
```
|
||||
|
||||
将两个颜色对应分量相减,返回新的颜色。
|
||||
|
||||
**参数:**
|
||||
- `other` - 要减去的另一个颜色
|
||||
|
||||
**返回:** `Color` - 分量相减后的新颜色
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color red = Color::Red();
|
||||
Color purple = Color(1, 0, 1, 1);
|
||||
Color blue = purple - red;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`operator+`](operator-add.md) - 颜色相加
|
||||
@@ -6,6 +6,19 @@ static Color Red()
|
||||
|
||||
返回红色 (1, 0, 0, 1)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 红色
|
||||
|
||||
**示例:** `Color c = Color::Red();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::Red();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`Green`](green.md) - 返回绿色
|
||||
|
||||
@@ -6,7 +6,9 @@ uint32_t ToRGBA() const
|
||||
|
||||
将颜色转换为 32-bit RGBA 整数格式。
|
||||
|
||||
**返回:** `uint32_t` - RGBA 值 (0xRRGGBBAA)
|
||||
**返回:** `uint32_t` - RGBA 值,格式为 `0xRRGGBBAA`(R在最高字节,A在最低字节)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
@@ -16,3 +18,9 @@ uint32_t ToRGBA() const
|
||||
Color c(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
uint32_t rgba = c.ToRGBA();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`ToVector3`](tovector3.md) - 转换为 Vector3
|
||||
- [`ToVector4`](tovector4.md) - 转换为 Vector4
|
||||
|
||||
@@ -8,6 +8,8 @@ Vector3 ToVector3() const
|
||||
|
||||
**返回:** `Vector3` - RGB 值
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +17,9 @@ Vector3 ToVector3() const
|
||||
```cpp
|
||||
Vector3 rgb = Color::Red().ToVector3();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`ToVector4`](tovector4.md) - 转换为 Vector4
|
||||
- [`ToRGBA`](torgba.md) - 转换为 RGBA 整数
|
||||
|
||||
@@ -8,6 +8,8 @@ Vector4 ToVector4() const
|
||||
|
||||
**返回:** `Vector4` - RGBA 值
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
@@ -15,3 +17,9 @@ Vector4 ToVector4() const
|
||||
```cpp
|
||||
Vector4 rgba = Color::Red().ToVector4();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`ToVector3`](tovector3.md) - 转换为 Vector3(丢弃 alpha)
|
||||
- [`ToRGBA`](torgba.md) - 转换为 RGBA 整数
|
||||
|
||||
@@ -6,6 +6,19 @@ static Color White()
|
||||
|
||||
返回白色 (1, 1, 1, 1)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 白色
|
||||
|
||||
**示例:** `Color c = Color::White();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::White();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`Black`](black.md) - 返回黑色
|
||||
|
||||
@@ -6,6 +6,19 @@ static Color Yellow()
|
||||
|
||||
返回黄色 (1, 1, 0, 1)。
|
||||
|
||||
**返回:** `Color`
|
||||
**返回:** `Color` - 黄色
|
||||
|
||||
**示例:** `Color c = Color::Yellow();`
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Color c = Color::Yellow();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Color](color.md) - 返回类总览
|
||||
- [`Blue`](blue.md) - 返回蓝色
|
||||
|
||||
@@ -1,25 +1,35 @@
|
||||
# Frustum::Contains (bounds)
|
||||
# Frustum::Contains
|
||||
|
||||
```cpp
|
||||
bool Contains(const Bounds& bounds) const
|
||||
```
|
||||
|
||||
检测轴对齐包围盒是否完全在视锥体内。
|
||||
检测轴对齐包围盒(Axis-Aligned Bounding Box,AABB)是否完全位于视锥体内。判断方式为:先取出 Bounds 的 8 个顶点坐标,然后对每个裁剪平面,检查所有 8 个顶点是否都在该平面外侧(距离小于 0)。若存在某个平面使得全部 8 个顶点都在其外侧,则包围盒完全在视锥外;否则认为包围盒至少部分在视锥内。
|
||||
|
||||
**参数:**
|
||||
- `bounds` - 要检测的轴对齐包围盒
|
||||
|
||||
**返回:** `bool` - Bounds 完全在视锥内返回 true
|
||||
**返回:** `bool` - Bounds 完全在视锥内返回 `true`,否则返回 `false`
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅(只读操作,不修改状态)
|
||||
|
||||
**复杂度:** O(48),即遍历 6 个平面 × 8 个顶点
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
Bounds objectBounds = object.GetWorldBounds();
|
||||
if (frustum.Contains(objectBounds)) {
|
||||
// 包围盒完全在视锥内,需要渲染
|
||||
Render(object);
|
||||
#include <XCEngine/Math/Frustum.h>
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
|
||||
void CheckBoundsInFrustum(const Frustum& frustum, const Bounds& bounds) {
|
||||
if (frustum.Contains(bounds)) {
|
||||
// 包围盒完全在视锥内,必须渲染
|
||||
Render();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Frustum 总览](frustum.md) - 返回类总览
|
||||
- [Intersects](intersects-bounds.md) - 包围盒与视锥相交检测
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
# Frustum::Contains (point)
|
||||
# Frustum::Contains
|
||||
|
||||
```cpp
|
||||
bool Contains(const Vector3& point) const
|
||||
```
|
||||
|
||||
检测点是否在视锥体内。
|
||||
检测世界空间中的点是否完全位于视锥体内。判断方式为:依次计算该点到 6 个裁剪平面的有符号距离,若任意一个距离小于 0,则点位于该平面外侧,视锥体不包含该点。
|
||||
|
||||
**参数:**
|
||||
- `point` - 要检测的世界空间点
|
||||
- `point` - 要检测的世界空间三维点
|
||||
|
||||
**返回:** `bool` - 点在视锥内返回 true
|
||||
**返回:** `bool` - 点完全在视锥内返回 `true`,否则返回 `false`
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅(只读操作,不修改状态)
|
||||
|
||||
**复杂度:** O(6),即遍历 6 个裁剪平面
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
Vector3 point = object.GetPosition();
|
||||
if (frustum.Contains(point)) {
|
||||
// 点在视锥内
|
||||
#include <XCEngine/Math/Frustum.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
void CheckPointInFrustum(const Frustum& frustum, const Vector3& point) {
|
||||
if (frustum.Contains(point)) {
|
||||
// 点完全在视锥内
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Frustum 总览](frustum.md) - 返回类总览
|
||||
- [Intersects](intersects-bounds.md) - 视锥体相交检测
|
||||
|
||||
@@ -1,24 +1,34 @@
|
||||
# Frustum::Contains (sphere)
|
||||
# Frustum::Contains
|
||||
|
||||
```cpp
|
||||
bool Contains(const Sphere& sphere) const
|
||||
```
|
||||
|
||||
检测球体是否完全在视锥体内。
|
||||
检测球体是否完全位于视锥体内。判断方式为:依次计算球心到 6 个裁剪平面的有符号距离,若任意一个距离小于 `-radius`(即球心到平面的距离小于球半径的负数,说明球体完全在平面外侧),则视锥体不包含该球体。
|
||||
|
||||
**参数:**
|
||||
- `sphere` - 要检测的球体
|
||||
- `sphere` - 要检测的球体,包含圆心 `center` 和半径 `radius`
|
||||
|
||||
**返回:** `bool` - 球体完全在视锥内返回 true
|
||||
**返回:** `bool` - 球体完全在视锥内返回 `true`,否则返回 `false`
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅(只读操作,不修改状态)
|
||||
|
||||
**复杂度:** O(6),即遍历 6 个裁剪平面
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
Sphere collider = object.GetBoundingSphere();
|
||||
if (frustum.Contains(collider)) {
|
||||
// 球体完全在视锥内
|
||||
#include <XCEngine/Math/Frustum.h>
|
||||
#include <XCEngine/Math/Sphere.h>
|
||||
|
||||
void CheckSphereInFrustum(const Frustum& frustum, const Sphere& sphere) {
|
||||
if (frustum.Contains(sphere)) {
|
||||
// 球体完全在视锥内
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Frustum 总览](frustum.md) - 返回类总览
|
||||
- [Intersects](intersects-sphere.md) - 球体与视锥相交检测
|
||||
|
||||
@@ -1,45 +1,51 @@
|
||||
# Frustum
|
||||
|
||||
视锥体,用于视锥剔除。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Frustum.h>`
|
||||
**类型**: `class`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Frustum.h`
|
||||
|
||||
## 类定义
|
||||
**描述**: 视锥体,用于 3D 裁剪和可见性判断
|
||||
|
||||
## 概述
|
||||
|
||||
Frustum 表示一个视锥体,由 6 个裁剪平面组成(左、右、底、顶、近、远)。主要用于视锥剔除(Frustum Culling),在渲染前判断场景物体是否与相机视锥相交或完全在内,从而决定是否需要渲染该物体,提升渲染性能。
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Contains(Point)`](contains-point.md) | 点是否完全在视锥内 |
|
||||
| [`Contains(Sphere)`](contains-sphere.md) | 球体是否完全在视锥内 |
|
||||
| [`Contains(Bounds)`](contains-bounds.md) | Bounds 是否完全在视锥内 |
|
||||
| [`Intersects(Bounds)`](intersects-bounds.md) | Bounds 是否与视锥相交 |
|
||||
| [`Intersects(Sphere)`](intersects-sphere.md) | 球体是否与视锥相交 |
|
||||
|
||||
## 嵌套类型
|
||||
|
||||
| 类型 | 描述 |
|
||||
|------|------|
|
||||
| `PlaneIndex` | 平面索引枚举(Left, Right, Bottom, Top, Near, Far) |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
class Frustum {
|
||||
public:
|
||||
Plane planes[6];
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
Bounds objectBounds = object.GetWorldBounds();
|
||||
|
||||
enum class PlaneIndex {
|
||||
Left = 0,
|
||||
Right = 1,
|
||||
Bottom = 2,
|
||||
Top = 3,
|
||||
Near = 4,
|
||||
Far = 5
|
||||
};
|
||||
|
||||
bool Contains(const Vector3& point) const;
|
||||
bool Contains(const Sphere& sphere) const;
|
||||
bool Contains(const Bounds& bounds) const;
|
||||
bool Intersects(const Bounds& bounds) const;
|
||||
bool Intersects(const Sphere& sphere) const;
|
||||
};
|
||||
if (frustum.Contains(objectBounds)) {
|
||||
// 物体完全在视锥内,必须渲染
|
||||
Render(object);
|
||||
} else if (frustum.Intersects(objectBounds)) {
|
||||
// 物体与视锥相交,可能需要渲染
|
||||
Render(object);
|
||||
}
|
||||
```
|
||||
|
||||
## 实例方法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Contains(point)](contains-point.md) | `bool` | 点是否在视锥内 |
|
||||
| [Contains(sphere)](contains-sphere.md) | `bool` | 球体是否完全在视锥内 |
|
||||
| [Contains(bounds)](contains-bounds.md) | `bool` | Bounds 是否完全在视锥内 |
|
||||
| [Intersects(bounds)](intersects-bounds.md) | `bool` | Bounds 是否与视锥相交 |
|
||||
| [Intersects(sphere)](intersects-sphere.md) | `bool` | 球体是否与视锥相交 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Math 模块总览](../math.md) - Math 模块总览
|
||||
- [Plane](../plane/plane.md) - 平面类型
|
||||
- [Bounds](../bounds/bounds.md) - 包围盒类型
|
||||
- [Sphere](../sphere/sphere.md) - 球体类型
|
||||
|
||||
@@ -1,26 +1,39 @@
|
||||
# Frustum::Intersects (bounds)
|
||||
# Frustum::Intersects
|
||||
|
||||
```cpp
|
||||
bool Intersects(const Bounds& bounds) const
|
||||
```
|
||||
|
||||
检测轴对齐包围盒是否与视锥体相交。
|
||||
检测轴对齐包围盒(Axis-Aligned Bounding Box,AABB)是否与视锥体相交。判断方式为:对每个裁剪平面,检查 8 个顶点是否全部在该平面外侧(allNegative)或全部在内侧(allPositive)。若存在某个平面使得全部 8 个顶点都在其外侧,则视锥与包围盒不相交;否则认为两者相交。
|
||||
|
||||
注意:此方法与 `Contains(Bounds)` 的区别在于——`Contains` 要求包围盒完全在视锥内,而 `Intersects` 只要有任意重叠就返回 `true`。
|
||||
|
||||
**参数:**
|
||||
- `bounds` - 要检测的轴对齐包围盒
|
||||
|
||||
**返回:** `bool` - 与视锥相交返回 true
|
||||
**返回:** `bool` - 视锥与 Bounds 相交返回 `true`,否则返回 `false`
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅(只读操作,不修改状态)
|
||||
|
||||
**复杂度:** O(48),即遍历 6 个平面 × 8 个顶点
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
for (const auto& object : sceneObjects) {
|
||||
if (frustum.Intersects(object.bounds)) {
|
||||
// 物体与视锥相交,需要渲染
|
||||
Render(object);
|
||||
#include <XCEngine/Math/Frustum.h>
|
||||
#include <XCEngine/Math/Bounds.h>
|
||||
|
||||
void FrustumCullingExample(const Frustum& frustum, const std::vector<Bounds>& objectBounds) {
|
||||
for (const auto& bounds : objectBounds) {
|
||||
if (frustum.Intersects(bounds)) {
|
||||
// 物体与视锥相交,需要渲染
|
||||
Render(bounds);
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Frustum 总览](frustum.md) - 返回类总览
|
||||
- [Contains](contains-bounds.md) - 包围盒完全包含检测
|
||||
|
||||
@@ -1,25 +1,37 @@
|
||||
# Frustum::Intersects (sphere)
|
||||
# Frustum::Intersects
|
||||
|
||||
```cpp
|
||||
bool Intersects(const Sphere& sphere) const
|
||||
```
|
||||
|
||||
检测球体是否与视锥体相交。
|
||||
检测球体是否与视锥体相交。判断方式为:依次计算球心到 6 个裁剪平面的有符号距离,若任意一个距离小于 `-radius`(即球体完全在平面外侧),则两者不相交;否则认为相交。
|
||||
|
||||
注意:此方法与 `Contains(Sphere)` 的区别在于——`Contains` 要求球体完全在视锥内,而 `Intersects` 只要有任意重叠就返回 `true`。
|
||||
|
||||
**参数:**
|
||||
- `sphere` - 要检测的球体
|
||||
- `sphere` - 要检测的球体,包含圆心 `center` 和半径 `radius`
|
||||
|
||||
**返回:** `bool` - 与视锥相交返回 true
|
||||
**返回:** `bool` - 视锥与球体相交返回 `true`,否则返回 `false`
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅(只读操作,不修改状态)
|
||||
|
||||
**复杂度:** O(6),即遍历 6 个裁剪平面
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Frustum frustum = camera.CalculateFrustum();
|
||||
Sphere collider = object.GetBoundingSphere();
|
||||
if (frustum.Intersects(collider)) {
|
||||
// 球体与视锥相交
|
||||
Render(object);
|
||||
#include <XCEngine/Math/Frustum.h>
|
||||
#include <XCEngine/Math/Sphere.h>
|
||||
|
||||
void CheckSphereIntersection(const Frustum& frustum, const Sphere& sphere) {
|
||||
if (frustum.Intersects(sphere)) {
|
||||
// 球体与视锥相交
|
||||
Render();
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Frustum 总览](frustum.md) - 返回类总览
|
||||
- [Contains](contains-sphere.md) - 球体完全包含检测
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Math::DEG_TO_RAD
|
||||
|
||||
```cpp
|
||||
constexpr float DEG_TO_RAD = Math::PI / 180.0f;
|
||||
constexpr float DEG_TO_RAD = PI / 180.0f;
|
||||
```
|
||||
|
||||
`DEG_TO_RAD` 是角度转弧度的转换系数。1 度等于 `PI / 180` 弧度,约等于 0.01745329251994329577。使用该常量将角度值乘以 `DEG_TO_RAD` 即可得到对应的弧度值。
|
||||
|
||||
@@ -13,7 +13,7 @@ constexpr float EPSILON = 1e-6f;
|
||||
|
||||
float a = 0.1f + 0.2f;
|
||||
float b = 0.3f;
|
||||
if (Math::Abs(a - b) < Math::EPSILON) {
|
||||
if (fabsf(a - b) < Math::EPSILON) {
|
||||
// a 和 b 可以视为相等
|
||||
}
|
||||
```
|
||||
|
||||
@@ -11,7 +11,7 @@ constexpr float FLOAT_MAX = 3.402823466e+38f;
|
||||
```cpp
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
float maxDistance = Math::FLOAT_MAX;
|
||||
float maxDistance = FLOAT_MAX;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
**类型**: `header`
|
||||
|
||||
**头文件**: `XCEngine/Math/Math.h`
|
||||
|
||||
**描述**: 数学库常量和辅助函数头文件。
|
||||
|
||||
## 概述
|
||||
@@ -41,7 +43,7 @@ float angle = 90.0f * DEG_TO_RAD; // 90度转弧度
|
||||
|
||||
// 使用函数
|
||||
float rad = Radians(180.0f); // 180度 -> π 弧度
|
||||
float deg = Degrees(Math::PI); // π 弧度 -> 180度
|
||||
float deg = Degrees(PI); // π 弧度 -> 180度
|
||||
|
||||
// 比较浮点数
|
||||
if (fabsf(a - b) < EPSILON) {
|
||||
|
||||
@@ -11,7 +11,7 @@ constexpr float HALF_PI = 1.57079632679489661923f;
|
||||
```cpp
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
float ninetyDegreesRadians = Math::HALF_PI;
|
||||
float ninetyDegreesRadians = HALF_PI;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
@@ -13,8 +13,8 @@ constexpr float PI = 3.14159265358979323846f;
|
||||
```cpp
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
float circumference = 2.0f * Math::PI * radius;
|
||||
float area = Math::PI * radius * radius;
|
||||
float circumference = 2.0f * PI * radius;
|
||||
float area = PI * radius * radius;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Math::RAD_TO_DEG
|
||||
|
||||
```cpp
|
||||
constexpr float RAD_TO_DEG = 180.0f / Math::PI;
|
||||
constexpr float RAD_TO_DEG = 180.0f / PI;
|
||||
```
|
||||
|
||||
`RAD_TO_DEG` 是弧度转角度的转换系数。1 弧度等于 `180 / PI` 度,约等于 57.29577951308232087685。使用该常量将弧度值乘以 `RAD_TO_DEG` 即可得到对应的角度值。
|
||||
|
||||
@@ -11,7 +11,7 @@ constexpr float TWO_PI = 6.28318530717958647692f;
|
||||
```cpp
|
||||
#include <XCEngine/Math/Math.h>
|
||||
|
||||
float fullCircleRadians = Math::TWO_PI;
|
||||
float fullCircleRadians = TWO_PI;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
@@ -98,3 +98,8 @@ Quaternion q2 = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(45.0f));
|
||||
Quaternion combined = q1 * q2;
|
||||
Vector3 rotated = q2 * Vector3::Forward();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Core 模块](../core/core.md) - 核心基础模块
|
||||
- [RHI 模块](../rhi/rhi.md) - 渲染硬件接口
|
||||
|
||||
@@ -6,13 +6,19 @@ Matrix3 Inverse() const
|
||||
|
||||
返回矩阵的逆矩阵。
|
||||
|
||||
**返回:** `Matrix3` - 逆矩阵
|
||||
**返回:** `Matrix3` - 逆矩阵。如果行列式接近零(< EPSILON),则返回单位矩阵。
|
||||
|
||||
**异常:** 当矩阵奇异(行列式为零)时,返回单位矩阵而非抛出异常。
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 mat = ...;
|
||||
Matrix3 mat = Matrix3::RotationY(0.5f);
|
||||
Matrix3 inv = mat.Inverse();
|
||||
```
|
||||
|
||||
// 验证:M * M⁻¹ ≈ I
|
||||
Matrix3 identity = mat * inv;
|
||||
// identity 应接近单位矩阵
|
||||
```
|
||||
@@ -1,20 +1,23 @@
|
||||
# Matrix3 / Matrix3x3
|
||||
|
||||
3x3 矩阵结构体,用于表示 3D 旋转和缩放变换。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Matrix3.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Matrix3.h`
|
||||
|
||||
## 类型别名
|
||||
**描述**: 3x3 矩阵,用于旋转变换和线性代数运算。
|
||||
|
||||
```cpp
|
||||
using Matrix3 = Matrix3x3;
|
||||
```
|
||||
## 概述
|
||||
|
||||
## 存储方式
|
||||
Matrix3(别名 Matrix3x3)是一个 3x3 浮点矩阵结构体,主要用于图形引擎中的旋转变换和线性代数运算。
|
||||
|
||||
行优先存储 (row-major):
|
||||
**设计目的:**
|
||||
- 旋转变换(绕 X/Y/Z 轴)
|
||||
- 缩放变换
|
||||
- 矩阵运算(乘法、转置、求逆、行列式计算)
|
||||
|
||||
**存储方式:** 行优先存储 (row-major)
|
||||
```
|
||||
m[row][col]
|
||||
m[0][0] m[0][1] m[0][2]
|
||||
@@ -22,36 +25,61 @@ m[1][0] m[1][1] m[1][2]
|
||||
m[2][0] m[2][1] m[2][2]
|
||||
```
|
||||
|
||||
## 构造函数
|
||||
**类型别名:**
|
||||
```cpp
|
||||
using Matrix3 = Matrix3x3;
|
||||
```
|
||||
|
||||
- 默认构造函数初始化为零矩阵
|
||||
## 结构体成员
|
||||
|
||||
## 静态工厂方法
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `m[3][3]` | `float` | 矩阵元素数组,行优先存储 |
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Identity()](identity.md) | `Matrix3` | 单位矩阵 |
|
||||
| [Zero()](zero.md) | `Matrix3` | 零矩阵 |
|
||||
| [RotationX(radians)](rotationx.md) | `Matrix3` | X 轴旋转矩阵 |
|
||||
| [RotationY(radians)](rotationy.md) | `Matrix3` | Y 轴旋转矩阵 |
|
||||
| [RotationZ(radians)](rotationz.md) | `Matrix3` | Z 轴旋转矩阵 |
|
||||
| [Scale(scale)](scale.md) | `Matrix3` | 缩放矩阵 |
|
||||
## 公共方法
|
||||
|
||||
## 实例方法
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Identity()`](identity.md) | 获取单位矩阵 |
|
||||
| [`Zero()`](zero.md) | 获取零矩阵 |
|
||||
| [`RotationX()`](rotation-x.md) | 创建绕 X 轴旋转矩阵 |
|
||||
| [`RotationY()`](rotation-y.md) | 创建绕 Y 轴旋转矩阵 |
|
||||
| [`RotationZ()`](rotation-z.md) | 创建绕 Z 轴旋转矩阵 |
|
||||
| [`Scale()`](scale.md) | 创建缩放矩阵 |
|
||||
| [`operator*(Matrix3)`](operator-mul-matrix3.md) | 矩阵乘法 |
|
||||
| [`operator*(Vector3)`](operator-mul-vector3.md) | 矩阵-向量乘法 |
|
||||
| [`Transpose()`](transpose.md) | 转置矩阵 |
|
||||
| [`Inverse()`](inverse.md) | 逆矩阵 |
|
||||
| [`Determinant()`](determinant.md) | 行列式 |
|
||||
| [`operator[]`](./operator-subscript.md) | 访问矩阵元素 |
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Transpose()](transpose.md) | `Matrix3` | 转置矩阵 |
|
||||
| [Inverse()](inverse.md) | `Matrix3` | 逆矩阵 |
|
||||
| [Determinant()](determinant.md) | `float` | 行列式 |
|
||||
## 使用示例
|
||||
|
||||
## 运算符
|
||||
```cpp
|
||||
#include <XCEngine/Math/Matrix3.h>
|
||||
#include <XCEngine/Math/Vector3.h>
|
||||
|
||||
| 运算符 | 描述 |
|
||||
|--------|------|
|
||||
| `operator*(Matrix3, Matrix3)` | 矩阵乘法 |
|
||||
| `operator*(Matrix3, Vector3)` | 矩阵-向量乘法 |
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
// 创建绕 Y 轴旋转 45 度的矩阵
|
||||
Matrix3 rotation = Matrix3::RotationY(0.785f); // PI/4
|
||||
|
||||
// 对向量进行变换
|
||||
Vector3 v(1.0f, 0.0f, 0.0f);
|
||||
Vector3 rotated = rotation * v;
|
||||
|
||||
// 矩阵运算
|
||||
Matrix3 m1 = Matrix3::RotationX(0.5f);
|
||||
Matrix3 m2 = Matrix3::RotationY(0.3f);
|
||||
Matrix3 combined = m1 * m2;
|
||||
|
||||
// 求逆矩阵
|
||||
Matrix3 inv = combined.Inverse();
|
||||
float det = combined.Determinant();
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Matrix4](../matrix4/matrix4.md) - 4x4 矩阵
|
||||
- [Vector3](../vector3/vector3.md) - 三维向量
|
||||
- [Math 模块总览](../math.md) - 返回模块总览
|
||||
24
docs/api/math/matrix3/operator-mul-matrix3.md
Normal file
24
docs/api/math/matrix3/operator-mul-matrix3.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Matrix3::operator* (Matrix3)
|
||||
|
||||
```cpp
|
||||
Matrix3 operator*(const Matrix3& other) const
|
||||
```
|
||||
|
||||
矩阵乘法运算,将当前矩阵与另一个矩阵相乘。
|
||||
|
||||
**参数:**
|
||||
- `other` - 另一个矩阵
|
||||
|
||||
**返回:** `Matrix3` - 乘积矩阵
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 rot = Matrix3::RotationZ(Math::Radians(45.0f));
|
||||
Matrix3 scale = Matrix3::Scale(Vector3(2.0f, 2.0f, 1.0f));
|
||||
|
||||
// 先缩放后旋转
|
||||
Matrix3 transform = rot * scale;
|
||||
```
|
||||
24
docs/api/math/matrix3/operator-mul-vector3.md
Normal file
24
docs/api/math/matrix3/operator-mul-vector3.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Matrix3::operator* (Vector3)
|
||||
|
||||
```cpp
|
||||
Vector3 operator*(const Vector3& v) const
|
||||
```
|
||||
|
||||
矩阵-向量乘法运算,将矩阵应用于向量。
|
||||
|
||||
**参数:**
|
||||
- `v` - 三维向量
|
||||
|
||||
**返回:** `Vector3` - 变换后的向量
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 rotation = Matrix3::RotationZ(Math::Radians(90.0f));
|
||||
Vector3 v(1.0f, 0.0f, 0.0f);
|
||||
|
||||
Vector3 rotated = rotation * v;
|
||||
// 结果: approximately (0, 1, 0)
|
||||
```
|
||||
27
docs/api/math/matrix3/operator-subscript.md
Normal file
27
docs/api/math/matrix3/operator-subscript.md
Normal file
@@ -0,0 +1,27 @@
|
||||
# Matrix3::operator[]
|
||||
|
||||
```cpp
|
||||
float* operator[](int row)
|
||||
const float* operator[](int row) const
|
||||
```
|
||||
|
||||
访问矩阵指定行的元素。
|
||||
|
||||
**参数:**
|
||||
- `row` - 行索引(0-2)
|
||||
|
||||
**返回:** `float*` / `const float*` - 指向该行首元素的指针
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 m;
|
||||
m[0][0] = 1; m[0][1] = 2; m[0][2] = 3;
|
||||
m[1][0] = 4; m[1][1] = 5; m[1][2] = 6;
|
||||
m[2][0] = 7; m[2][1] = 8; m[2][2] = 9;
|
||||
|
||||
// 访问元素
|
||||
float val = m[1][2]; // 6
|
||||
```
|
||||
24
docs/api/math/matrix3/rotation-x.md
Normal file
24
docs/api/math/matrix3/rotation-x.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Matrix3::RotationX
|
||||
|
||||
```cpp
|
||||
static Matrix3 RotationX(float radians)
|
||||
```
|
||||
|
||||
返回绕 X 轴旋转的 3x3 旋转矩阵。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix3` - 绕 X 轴旋转的矩阵
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 rotX = Matrix3::RotationX(Math::Radians(90.0f));
|
||||
// 结果(绕 X 轴旋转 90 度):
|
||||
// [1 0 0]
|
||||
// [0 0 -1]
|
||||
// [0 1 0]
|
||||
```
|
||||
24
docs/api/math/matrix3/rotation-y.md
Normal file
24
docs/api/math/matrix3/rotation-y.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Matrix3::RotationY
|
||||
|
||||
```cpp
|
||||
static Matrix3 RotationY(float radians)
|
||||
```
|
||||
|
||||
返回绕 Y 轴旋转的 3x3 旋转矩阵。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix3` - 绕 Y 轴旋转的矩阵
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 rotY = Matrix3::RotationY(Math::Radians(90.0f));
|
||||
// 结果(绕 Y 轴旋转 90 度):
|
||||
// [0 0 1]
|
||||
// [0 1 0]
|
||||
// [-1 0 0]
|
||||
```
|
||||
24
docs/api/math/matrix3/rotation-z.md
Normal file
24
docs/api/math/matrix3/rotation-z.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Matrix3::RotationZ
|
||||
|
||||
```cpp
|
||||
static Matrix3 RotationZ(float radians)
|
||||
```
|
||||
|
||||
返回绕 Z 轴旋转的 3x3 旋转矩阵。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix3` - 绕 Z 轴旋转的矩阵
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 rotZ = Matrix3::RotationZ(Math::Radians(45.0f));
|
||||
// 结果(绕 Z 轴旋转 45 度):
|
||||
// [ 0.707 -0.707 0]
|
||||
// [ 0.707 0.707 0]
|
||||
// [ 0 0 1]
|
||||
```
|
||||
@@ -1,20 +0,0 @@
|
||||
# Matrix3::RotationX
|
||||
|
||||
```cpp
|
||||
static Matrix3 RotationX(float radians)
|
||||
```
|
||||
|
||||
创建绕 X 轴旋转的矩阵。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix3` - 旋转矩阵
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 rotX = Matrix3::RotationX(Math::HALF_PI);
|
||||
```
|
||||
@@ -1,20 +0,0 @@
|
||||
# Matrix3::RotationY
|
||||
|
||||
```cpp
|
||||
static Matrix3 RotationY(float radians)
|
||||
```
|
||||
|
||||
创建绕 Y 轴旋转的矩阵。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix3` - 旋转矩阵
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 rotY = Matrix3::RotationY(Math::HALF_PI);
|
||||
```
|
||||
@@ -1,20 +0,0 @@
|
||||
# Matrix3::RotationZ
|
||||
|
||||
```cpp
|
||||
static Matrix3 RotationZ(float radians)
|
||||
```
|
||||
|
||||
创建绕 Z 轴旋转的矩阵。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix3` - 旋转矩阵
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix3 rotZ = Matrix3::RotationZ(Math::HALF_PI);
|
||||
```
|
||||
@@ -1,24 +1,50 @@
|
||||
# Matrix4::Decompose
|
||||
# Matrix4x4::Decompose
|
||||
|
||||
```cpp
|
||||
void Decompose(Vector3& translation, Quaternion& rotation, Vector3& scale) const
|
||||
```
|
||||
|
||||
将矩阵分解为平移、旋转和缩放分量。
|
||||
将变换矩阵分解为平移、旋转和缩放三个独立分量。
|
||||
|
||||
**参数:**
|
||||
- `translation` - 输出平移向量
|
||||
- `rotation` - 输出旋转四元数
|
||||
- `scale` - 输出缩放向量
|
||||
- `translation` - 输出参数,接收平移向量
|
||||
- `rotation` - 输出参数,接收旋转四元数
|
||||
- `scale` - 输出参数,接收缩放向量
|
||||
|
||||
**返回:** (无)
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 m = ...;
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
#include "XCEngine/Math/Quaternion.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 transform = Matrix4::TRS(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Quaternion::FromEuler(45.0f, 0.0f, 0.0f),
|
||||
Vector3(2.0f, 2.0f, 2.0f)
|
||||
);
|
||||
|
||||
Vector3 translation;
|
||||
Quaternion rotation;
|
||||
Vector3 scale;
|
||||
m.Decompose(translation, rotation, scale);
|
||||
transform.Decompose(translation, rotation, scale);
|
||||
// translation = (1.0f, 2.0f, 3.0f)
|
||||
// rotation 表示 45 度 X 轴旋转
|
||||
// scale = (2.0f, 2.0f, 2.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [TRS](trs.md) - 组合变换矩阵
|
||||
- [GetTranslation](gettranslation.md) - 获取平移分量
|
||||
- [GetRotation](getrotation.md) - 获取旋转分量
|
||||
- [GetScale](getscale.md) - 获取缩放分量
|
||||
@@ -1,18 +1,36 @@
|
||||
# Matrix4::Determinant
|
||||
# Matrix4x4::Determinant
|
||||
|
||||
```cpp
|
||||
float Determinant() const
|
||||
```
|
||||
|
||||
计算矩阵的行列式。
|
||||
计算矩阵的行列式。行列式为零的矩阵不可逆。
|
||||
|
||||
**返回:** `float` - 行列式值
|
||||
**参数:** (无)
|
||||
|
||||
**复杂度:** O(1)
|
||||
**返回:** 矩阵的行列式值
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(n³) - O(64)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 m = ...;
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 m = Matrix4::Identity();
|
||||
float det = m.Determinant();
|
||||
// det = 1.0f
|
||||
|
||||
Matrix4 singular;
|
||||
float det2 = singular.Determinant();
|
||||
// det2 = 0.0f
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Inverse](inverse.md) - 矩阵求逆
|
||||
@@ -1,18 +1,42 @@
|
||||
# Matrix4::GetRotation
|
||||
# Matrix4x4::GetRotation
|
||||
|
||||
```cpp
|
||||
Quaternion GetRotation() const
|
||||
```
|
||||
|
||||
从矩阵中提取旋转分量。
|
||||
从变换矩阵中提取旋转分量。将矩阵转换为对应的四元数表示。
|
||||
|
||||
**返回:** `Quaternion` - 旋转四元数
|
||||
**参数:** (无)
|
||||
|
||||
**返回:** 旋转四元数
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 m = ...;
|
||||
Quaternion rotation = m.GetRotation();
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Quaternion.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion expected = Quaternion::FromEuler(0.0f, 90.0f, 0.0f);
|
||||
Matrix4 transform = Matrix4::TRS(
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
expected,
|
||||
Vector3(1.0f, 1.0f, 1.0f)
|
||||
);
|
||||
|
||||
Quaternion rotation = transform.GetRotation();
|
||||
// rotation 表示相同的旋转
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Quaternion](../quaternion/quaternion.md) - 四元数类
|
||||
- [GetTranslation](gettranslation.md) - 获取平移分量
|
||||
- [GetScale](getscale.md) - 获取缩放分量
|
||||
- [Decompose](decompose.md) - 分解矩阵
|
||||
@@ -1,18 +1,40 @@
|
||||
# Matrix4::GetScale
|
||||
# Matrix4x4::GetScale
|
||||
|
||||
```cpp
|
||||
Vector3 GetScale() const
|
||||
```
|
||||
|
||||
从矩阵中提取缩放分量。
|
||||
从变换矩阵中提取缩放分量。计算各列向量的长度作为缩放因子。
|
||||
|
||||
**返回:** `Vector3` - 缩放向量
|
||||
**参数:** (无)
|
||||
|
||||
**返回:** 缩放向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 m = ...;
|
||||
Vector3 scale = m.GetScale();
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 transform = Matrix4::TRS(
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
Quaternion::Identity(),
|
||||
Vector3(2.0f, 3.0f, 4.0f)
|
||||
);
|
||||
|
||||
Vector3 scale = transform.GetScale();
|
||||
// scale = (2.0f, 3.0f, 4.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [GetTranslation](gettranslation.md) - 获取平移分量
|
||||
- [GetRotation](getrotation.md) - 获取旋转分量
|
||||
- [Decompose](decompose.md) - 分解矩阵
|
||||
@@ -1,18 +1,40 @@
|
||||
# Matrix4::GetTranslation
|
||||
# Matrix4x4::GetTranslation
|
||||
|
||||
```cpp
|
||||
Vector3 GetTranslation() const
|
||||
```
|
||||
|
||||
从矩阵中提取平移分量。
|
||||
从变换矩阵中提取平移分量。读取矩阵的最后一列前三个元素。
|
||||
|
||||
**返回:** `Vector3` - 平移向量
|
||||
**参数:** (无)
|
||||
|
||||
**返回:** 平移向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 m = ...;
|
||||
Vector3 translation = m.GetTranslation();
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 transform = Matrix4::TRS(
|
||||
Vector3(5.0f, 3.0f, 2.0f),
|
||||
Quaternion::Identity(),
|
||||
Vector3(1.0f, 1.0f, 1.0f)
|
||||
);
|
||||
|
||||
Vector3 translation = transform.GetTranslation();
|
||||
// translation = (5.0f, 3.0f, 2.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [GetRotation](getrotation.md) - 获取旋转分量
|
||||
- [GetScale](getscale.md) - 获取缩放分量
|
||||
- [Decompose](decompose.md) - 分解矩阵
|
||||
@@ -1,17 +1,31 @@
|
||||
# Matrix4::Identity
|
||||
# Matrix4x4::Identity
|
||||
|
||||
```cpp
|
||||
static Matrix4 Identity()
|
||||
static Matrix4x4 Identity()
|
||||
```
|
||||
|
||||
返回 4x4 单位矩阵。
|
||||
返回单位矩阵。单位矩阵是对角线元素为 1,其他元素为 0 的特殊矩阵。
|
||||
|
||||
**返回:** `Matrix4` - 单位矩阵
|
||||
**参数:** (无)
|
||||
|
||||
**返回:** 单位矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 identity = Matrix4::Identity();
|
||||
// identity.m[0][0] = 1, identity.m[1][1] = 1, identity.m[2][2] = 1, identity.m[3][3] = 1
|
||||
// 所有其他元素为 0
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
@@ -1,18 +1,39 @@
|
||||
# Matrix4::Inverse
|
||||
# Matrix4x4::Inverse
|
||||
|
||||
```cpp
|
||||
Matrix4 Inverse() const
|
||||
Matrix4x4 Inverse() const
|
||||
```
|
||||
|
||||
返回矩阵的逆矩阵。
|
||||
返回矩阵的逆矩阵。如果矩阵的行列式接近零(不可逆),则返回单位矩阵。
|
||||
|
||||
**返回:** `Matrix4` - 逆矩阵
|
||||
**参数:** (无)
|
||||
|
||||
**复杂度:** O(1)
|
||||
**返回:** 逆矩阵;如果矩阵不可逆则返回单位矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(n³),对于 4x4 矩阵固定为 64 次基本运算
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 m = ...;
|
||||
Matrix4 inv = m.Inverse();
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 transform = Matrix4::TRS(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Quaternion::FromEuler(0.0f, 45.0f, 0.0f),
|
||||
Vector3(2.0f, 2.0f, 2.0f)
|
||||
);
|
||||
|
||||
Matrix4 inv = transform.Inverse();
|
||||
Matrix4 identity = transform * inv;
|
||||
// identity 接近单位矩阵
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Determinant](determinant.md) - 计算行列式
|
||||
- [Transpose](transpose.md) - 矩阵转置
|
||||
@@ -1,22 +1,39 @@
|
||||
# Matrix4::LookAt
|
||||
# Matrix4x4::LookAt
|
||||
|
||||
```cpp
|
||||
static Matrix4 LookAt(const Vector3& eye, const Vector3& target, const Vector3& up)
|
||||
static Matrix4x4 LookAt(const Vector3& eye, const Vector3& target, const Vector3& up)
|
||||
```
|
||||
|
||||
创建视图矩阵(观察矩阵)。
|
||||
创建视图矩阵(观察矩阵)。用于将世界空间中的点转换到摄像机视角。
|
||||
|
||||
**参数:**
|
||||
- `eye` - 相机位置
|
||||
- `eye` - 摄像机位置
|
||||
- `target` - 观察目标点
|
||||
- `up` - 世界空间中的上方向
|
||||
- `up` - 摄像机上方向向量
|
||||
|
||||
**返回:** `Matrix4` - 视图矩阵
|
||||
**返回:** 视图矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 view = Matrix4::LookAt(cameraPos, target, Vector3::Up());
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 view = Matrix4::LookAt(
|
||||
Vector3(0.0f, 1.0f, 5.0f),
|
||||
Vector3(0.0f, 0.0f, 0.0f),
|
||||
Vector3(0.0f, 1.0f, 0.0f)
|
||||
);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Perspective](perspective.md) - 透视投影
|
||||
- [Orthographic](orthographic.md) - 正交投影
|
||||
@@ -1,79 +1,77 @@
|
||||
# Matrix4 / Matrix4x4
|
||||
# Matrix4
|
||||
|
||||
4x4 矩阵结构体,用于表示完整的 3D 变换(平移、旋转、缩放)、视图和投影变换。
|
||||
**命名空间**: `XCEngine::Math`
|
||||
|
||||
**头文件:** `#include <XCEngine/Math/Matrix4.h>`
|
||||
**类型**: `struct`
|
||||
|
||||
**命名空间:** `XCEngine::Math`
|
||||
**头文件**: `XCEngine/Math/Matrix4.h`
|
||||
|
||||
## 类型别名
|
||||
**描述**: 4x4 矩阵,用于 3D 变换(平移、旋转、缩放)、视图和投影计算
|
||||
|
||||
## 概述
|
||||
|
||||
`Matrix4` (别名 `Matrix4x4`) 是 XCEngine 中用于表示 4x4 变换矩阵的结构体。它支持标准的 3D 图形变换操作,包括平移、旋转、缩放,以及视图矩阵和投影矩阵的构建。该结构体采用列主序存储方式,适用于 GPU 渲染和物理计算场景。
|
||||
|
||||
## 结构体成员
|
||||
|
||||
| 成员 | 类型 | 描述 |
|
||||
|------|------|------|
|
||||
| `m[4][4]` | `float` | 矩阵元素数组 |
|
||||
|
||||
## 公共方法
|
||||
|
||||
| 方法 | 描述 |
|
||||
|------|------|
|
||||
| [`Identity`](identity.md) | 返回单位矩阵 |
|
||||
| [`Zero`](zero.md) | 返回零矩阵 |
|
||||
| [`Translation`](translation.md) | 创建平移矩阵 |
|
||||
| [`Rotation`](rotation.md) | 从四元数创建旋转矩阵 |
|
||||
| [`Scale`](scale.md) | 创建缩放矩阵 |
|
||||
| [`TRS`](trs.md) | 创建组合变换矩阵 |
|
||||
| [`LookAt`](lookat.md) | 创建视图矩阵 |
|
||||
| [`Perspective`](perspective.md) | 创建透视投影矩阵 |
|
||||
| [`Orthographic`](orthographic.md) | 创建正交投影矩阵 |
|
||||
| [`RotationX`](rotationx.md) | 创建绕 X 轴旋转矩阵 |
|
||||
| [`RotationY`](rotationy.md) | 创建绕 Y 轴旋转矩阵 |
|
||||
| [`RotationZ`](rotationz.md) | 创建绕 Z 轴旋转矩阵 |
|
||||
| [`operator*`](operator_mul.md) | 矩阵乘法 |
|
||||
| [`MultiplyPoint`](multiplypoint.md) | 变换点(w=1) |
|
||||
| [`MultiplyVector`](multiplyvector.md) | 变换向量(w=0) |
|
||||
| [`Transpose`](transpose.md) | 转置矩阵 |
|
||||
| [`Inverse`](inverse.md) | 求逆矩阵 |
|
||||
| [`Determinant`](determinant.md) | 计算行列式 |
|
||||
| [`GetTranslation`](gettranslation.md) | 获取平移分量 |
|
||||
| [`GetRotation`](getrotation.md) | 获取旋转分量 |
|
||||
| [`GetScale`](getscale.md) | 获取缩放分量 |
|
||||
| [`Decompose`](decompose.md) | 分解矩阵为变换分量 |
|
||||
| [`operator[]`](operator_index.md) | 访问矩阵行数据 |
|
||||
|
||||
## 使用示例
|
||||
|
||||
```cpp
|
||||
using Matrix4 = Matrix4x4;
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
#include "XCEngine/Math/Quaternion.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
void MatrixExample() {
|
||||
Matrix4 mat = Matrix4::TRS(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Quaternion::FromEuler(0.0f, 90.0f, 0.0f),
|
||||
Vector3(1.5f, 1.5f, 1.5f)
|
||||
);
|
||||
|
||||
Vector3 point(1.0f, 0.0f, 0.0f);
|
||||
Vector3 transformed = mat.MultiplyPoint(point);
|
||||
|
||||
Matrix4 inv = mat.Inverse();
|
||||
Matrix4 result = mat * inv;
|
||||
}
|
||||
```
|
||||
|
||||
## 存储方式
|
||||
|
||||
行优先存储 (row-major):
|
||||
```
|
||||
m[0][0] m[0][1] m[0][2] m[0][3]
|
||||
m[1][0] m[1][1] m[1][2] m[1][3]
|
||||
m[2][0] m[2][1] m[2][2] m[2][3]
|
||||
m[3][0] m[3][1] m[3][2] m[3][3]
|
||||
```
|
||||
|
||||
## 静态工厂方法
|
||||
|
||||
### 基础变换
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Identity()](identity.md) | `Matrix4` | 单位矩阵 |
|
||||
| [Zero()](zero.md) | `Matrix4` | 零矩阵 |
|
||||
| [Translation(v)](translation.md) | `Matrix4` | 平移矩阵 |
|
||||
| [Scale(v)](scale.md) | `Matrix4` | 缩放矩阵 |
|
||||
| [Rotation(q)](rotation.md) | `Matrix4` | 旋转矩阵(四元数) |
|
||||
| [TRS(translation, rotation, scale)](trs.md) | `Matrix4` | 完整变换 |
|
||||
|
||||
### 旋转
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [RotationX(radians)](rotationx.md) | `Matrix4` | X 轴旋转 |
|
||||
| [RotationY(radians)](rotationy.md) | `Matrix4` | Y 轴旋转 |
|
||||
| [RotationZ(radians)](rotationz.md) | `Matrix4` | Z 轴旋转 |
|
||||
|
||||
### 相机变换
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [LookAt(eye, target, up)](lookat.md) | `Matrix4` | 视图矩阵 |
|
||||
| [Perspective(fov, aspect, near, far)](perspective.md) | `Matrix4` | 透视投影 |
|
||||
| [Orthographic(left, right, bottom, top, near, far)](orthographic.md) | `Matrix4` | 正交投影 |
|
||||
|
||||
## 实例方法
|
||||
|
||||
### 乘法
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| `operator*(Matrix4, Matrix4)` | `Matrix4` | 矩阵乘法 |
|
||||
| `operator*(Matrix4, Vector4)` | `Vector4` | 矩阵-向量乘法 |
|
||||
| [MultiplyPoint(v)](multiplypoint.md) | `Vector3` | 点变换(带平移) |
|
||||
| [MultiplyVector(v)](multiplyvector.md) | `Vector3` | 方向变换(不带平移) |
|
||||
|
||||
### 分解
|
||||
|
||||
| 方法 | 返回值 | 描述 |
|
||||
|------|--------|------|
|
||||
| [Transpose()](transpose.md) | `Matrix4` | 转置矩阵 |
|
||||
| [Inverse()](inverse.md) | `Matrix4` | 逆矩阵 |
|
||||
| [Determinant()](determinant.md) | `float` | 行列式 |
|
||||
| [GetTranslation()](gettranslation.md) | `Vector3` | 获取平移分量 |
|
||||
| [GetRotation()](getrotation.md) | `Quaternion` | 获取旋转分量 |
|
||||
| [GetScale()](getscale.md) | `Vector3` | 获取缩放分量 |
|
||||
| [Decompose(translation, rotation, scale)](decompose.md) | `void` | 分解所有分量 |
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Math 模块总览](../math.md) - 返回 Math 模块总览
|
||||
- [Vector3](../vector3/vector3.md) - 三维向量
|
||||
- [Quaternion](../quaternion/quaternion.md) - 四元数
|
||||
- [Matrix3](../matrix3/matrix3.md) - 3x3 矩阵
|
||||
@@ -1,21 +1,41 @@
|
||||
# Matrix4::MultiplyPoint
|
||||
# Matrix4x4::MultiplyPoint
|
||||
|
||||
```cpp
|
||||
Vector3 MultiplyPoint(const Vector3& v) const
|
||||
```
|
||||
|
||||
使用矩阵变换点(包含平移)。
|
||||
使用矩阵变换一个点。会自动处理 w=1 的齐次坐标变换,适用于位置变换。
|
||||
|
||||
**参数:**
|
||||
- `v` - 要变换的点
|
||||
- `v` - 待变换的三维点
|
||||
|
||||
**返回:** `Vector3` - 变换后的点
|
||||
**返回:** 变换后的三维点
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 model = Matrix4::TRS(pos, rot, scale);
|
||||
Vector3 worldPos = model.MultiplyPoint(localPos);
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 transform = Matrix4::TRS(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Quaternion::Identity(),
|
||||
Vector3(1.0f, 1.0f, 1.0f)
|
||||
);
|
||||
|
||||
Vector3 point(1.0f, 0.0f, 0.0f);
|
||||
Vector3 transformed = transform.MultiplyPoint(point);
|
||||
// transformed = (2.0f, 2.0f, 3.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [MultiplyVector](multiplyvector.md) - 向量变换
|
||||
- [operator*](operator_mul.md) - 矩阵乘法
|
||||
@@ -1,21 +1,36 @@
|
||||
# Matrix4::MultiplyVector
|
||||
# Matrix4x4::MultiplyVector
|
||||
|
||||
```cpp
|
||||
Vector3 MultiplyVector(const Vector3& v) const
|
||||
```
|
||||
|
||||
使用矩阵变换方向向量(不包含平移)。
|
||||
使用矩阵变换一个方向向量。会自动处理 w=0 的齐次坐标变换,适用于方向变换,不受平移影响。
|
||||
|
||||
**参数:**
|
||||
- `v` - 要变换的方向向量
|
||||
- `v` - 待变换的三维方向向量
|
||||
|
||||
**返回:** `Vector3` - 变换后的方向
|
||||
**返回:** 变换后的三维方向向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 model = Matrix4::TRS(pos, rot, scale);
|
||||
Vector3 worldDir = model.MultiplyVector(localDir);
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 rotation = Matrix4::RotationY(3.14159265f / 2.0f);
|
||||
Vector3 direction(1.0f, 0.0f, 0.0f);
|
||||
Vector3 rotated = rotation.MultiplyVector(direction);
|
||||
// rotated = (0.0f, 0.0f, -1.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [MultiplyPoint](multiplypoint.md) - 点变换
|
||||
- [operator*](operator_mul.md) - 矩阵乘法
|
||||
35
docs/api/math/matrix4/operator_index.md
Normal file
35
docs/api/math/matrix4/operator_index.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Matrix4x4::operator[]
|
||||
|
||||
```cpp
|
||||
float* operator[](int row)
|
||||
const float* operator[](int row) const
|
||||
```
|
||||
|
||||
通过行索引访问矩阵元素。返回指向该行第一列元素的指针。
|
||||
|
||||
**参数:**
|
||||
- `row` - 行索引(0-3)
|
||||
|
||||
**返回:** 指向该行数据的指针
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 m = Matrix4::Identity();
|
||||
m[0][0] = 5.0f; // 设置第一行第一列
|
||||
m[1][2] = 3.0f; // 设置第二行第三列
|
||||
|
||||
float val = m[0][1]; // 读取第一行第二列
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
44
docs/api/math/matrix4/operator_mul.md
Normal file
44
docs/api/math/matrix4/operator_mul.md
Normal file
@@ -0,0 +1,44 @@
|
||||
# Matrix4x4::operator*
|
||||
|
||||
```cpp
|
||||
Matrix4x4 operator*(const Matrix4x4& other) const
|
||||
Vector4 operator*(const Vector4& v) const
|
||||
```
|
||||
|
||||
两个重载分别用于矩阵与矩阵乘法,以及矩阵与四维向量的乘法。
|
||||
|
||||
**参数(矩阵乘法):**
|
||||
- `other` - 右侧矩阵
|
||||
|
||||
**参数(向量乘法):**
|
||||
- `v` - 四维向量
|
||||
|
||||
**返回:**
|
||||
- 矩阵乘法:结果矩阵
|
||||
- 向量乘法:变换后的四维向量
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(n²) - 矩阵乘法为 O(4³),向量乘法为 O(4)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 m1 = Matrix4::RotationY(1.0f);
|
||||
Matrix4 m2 = Matrix4::Translation(Vector3(1.0f, 0.0f, 0.0f));
|
||||
Matrix4 combined = m1 * m2;
|
||||
|
||||
Vector4 v(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
Vector4 transformed = m1 * v;
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [MultiplyPoint](multiplypoint.md) - 点变换
|
||||
- [MultiplyVector](multiplyvector.md) - 向量变换
|
||||
@@ -1,25 +1,36 @@
|
||||
# Matrix4::Orthographic
|
||||
# Matrix4x4::Orthographic
|
||||
|
||||
```cpp
|
||||
static Matrix4 Orthographic(float left, float right, float bottom, float top, float near, float far)
|
||||
static Matrix4x4 Orthographic(float left, float right, float bottom, float top, float near, float far)
|
||||
```
|
||||
|
||||
创建正交投影矩阵。
|
||||
创建正交投影矩阵。用于 2D UI 或建筑制图等需要保持物体实际大小的场景。
|
||||
|
||||
**参数:**
|
||||
- `left` - 左裁剪面
|
||||
- `right` - 右裁剪面
|
||||
- `bottom` - 下裁剪面
|
||||
- `top` - 上裁剪面
|
||||
- `near` - 近裁剪面距离
|
||||
- `far` - 远裁剪面距离
|
||||
- `left` - 左裁切面 x 坐标
|
||||
- `right` - 右裁切面 x 坐标
|
||||
- `bottom` - 下裁切面 y 坐标
|
||||
- `top` - 上裁切面 y 坐标
|
||||
- `near` - 近裁切面 z 坐标
|
||||
- `far` - 远裁切面 z 坐标
|
||||
|
||||
**返回:** `Matrix4` - 正交投影矩阵
|
||||
**返回:** 正交投影矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 ortho = Matrix4::Orthographic(-aspect, aspect, -1.0f, 1.0f, 0.1f, 100.0f);
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 ortho = Matrix4::Orthographic(-10.0f, 10.0f, -5.0f, 5.0f, 0.1f, 100.0f);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Perspective](perspective.md) - 透视投影
|
||||
@@ -1,23 +1,37 @@
|
||||
# Matrix4::Perspective
|
||||
# Matrix4x4::Perspective
|
||||
|
||||
```cpp
|
||||
static Matrix4 Perspective(float fov, float aspect, float near, float far)
|
||||
static Matrix4x4 Perspective(float fov, float aspect, float near, float far)
|
||||
```
|
||||
|
||||
创建透视投影矩阵。
|
||||
创建透视投影矩阵。用于将 3D 场景投影到 2D 视口,产生近大远小的效果。
|
||||
|
||||
**参数:**
|
||||
- `fov` - 垂直视野角度(弧度)
|
||||
- `aspect` - 宽高比
|
||||
- `near` - 近裁剪面距离
|
||||
- `far` - 远裁剪面距离
|
||||
- `aspect` - 宽高比(width / height)
|
||||
- `near` - 近裁切面距离
|
||||
- `far` - 远裁切面距离
|
||||
|
||||
**返回:** `Matrix4` - 透视投影矩阵
|
||||
**返回:** 透视投影矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 proj = Matrix4::Perspective(45.0f * DEG_TO_RAD, aspect, 0.1f, 100.0f);
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
float fov = 60.0f * 3.14159265f / 180.0f;
|
||||
float aspect = 16.0f / 9.0f;
|
||||
Matrix4 proj = Matrix4::Perspective(fov, aspect, 0.1f, 100.0f);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Orthographic](orthographic.md) - 正交投影
|
||||
- [LookAt](lookat.md) - 视图矩阵
|
||||
@@ -1,21 +1,39 @@
|
||||
# Matrix4::Rotation
|
||||
# Matrix4x4::Rotation
|
||||
|
||||
```cpp
|
||||
static Matrix4 Rotation(const Quaternion& q)
|
||||
static Matrix4x4 Rotation(const Quaternion& q)
|
||||
```
|
||||
|
||||
从四元数创建旋转矩阵。
|
||||
从四元数创建旋转矩阵。用于将旋转变换应用到点或向量。
|
||||
|
||||
**参数:**
|
||||
- `q` - 四元数
|
||||
- `q` - 表示旋转的四元数
|
||||
|
||||
**返回:** `Matrix4` - 旋转矩阵
|
||||
**返回:** 旋转矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Quaternion rot = Quaternion::FromEulerAngles(0.0f, 90.0f * DEG_TO_RAD, 0.0f);
|
||||
Matrix4 rotation = Matrix4::Rotation(rot);
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Quaternion.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Quaternion q = Quaternion::FromEuler(0.0f, 90.0f, 0.0f);
|
||||
Matrix4 rotate = Matrix4::Rotation(q);
|
||||
|
||||
Vector3 point(1.0f, 0.0f, 0.0f);
|
||||
Vector3 rotated = rotate.MultiplyVector(point);
|
||||
// point 绕 Y 轴旋转 90 度
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Quaternion](../quaternion/quaternion.md) - 四元数类
|
||||
- [TRS](trs.md) - 组合变换矩阵
|
||||
@@ -1,20 +1,36 @@
|
||||
# Matrix4::RotationX
|
||||
# Matrix4x4::RotationX
|
||||
|
||||
```cpp
|
||||
static Matrix4 RotationX(float radians)
|
||||
static Matrix4x4 RotationX(float radians)
|
||||
```
|
||||
|
||||
创建绕 X 轴旋转的矩阵。
|
||||
创建绕 X 轴旋转的矩阵。角度为正时,按右手定则逆时针旋转。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix4` - 旋转矩阵
|
||||
**返回:** 绕 X 轴旋转的矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 rotX = Matrix4::RotationX(Math::HALF_PI);
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 rotX = Matrix4::RotationX(3.14159265f / 2.0f); // 90 度
|
||||
Vector3 point(1.0f, 0.0f, 0.0f);
|
||||
Vector3 rotated = rotX.MultiplyVector(point);
|
||||
// point 绕 X 轴旋转 90 度
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [RotationY](rotationy.md) - 绕 Y 轴旋转
|
||||
- [RotationZ](rotationz.md) - 绕 Z 轴旋转
|
||||
@@ -1,20 +1,36 @@
|
||||
# Matrix4::RotationY
|
||||
# Matrix4x4::RotationY
|
||||
|
||||
```cpp
|
||||
static Matrix4 RotationY(float radians)
|
||||
static Matrix4x4 RotationY(float radians)
|
||||
```
|
||||
|
||||
创建绕 Y 轴旋转的矩阵。
|
||||
创建绕 Y 轴旋转的矩阵。角度为正时,按右手定则逆时针旋转。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix4` - 旋转矩阵
|
||||
**返回:** 绕 Y 轴旋转的矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 rotY = Matrix4::RotationY(Math::HALF_PI);
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 rotY = Matrix4::RotationY(3.14159265f / 2.0f); // 90 度
|
||||
Vector3 point(1.0f, 0.0f, 0.0f);
|
||||
Vector3 rotated = rotY.MultiplyVector(point);
|
||||
// point 绕 Y 轴旋转 90 度
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [RotationX](rotationx.md) - 绕 X 轴旋转
|
||||
- [RotationZ](rotationz.md) - 绕 Z 轴旋转
|
||||
@@ -1,20 +1,36 @@
|
||||
# Matrix4::RotationZ
|
||||
# Matrix4x4::RotationZ
|
||||
|
||||
```cpp
|
||||
static Matrix4 RotationZ(float radians)
|
||||
static Matrix4x4 RotationZ(float radians)
|
||||
```
|
||||
|
||||
创建绕 Z 轴旋转的矩阵。
|
||||
创建绕 Z 轴旋转的矩阵。角度为正时,按右手定则逆时针旋转。
|
||||
|
||||
**参数:**
|
||||
- `radians` - 旋转角度(弧度)
|
||||
|
||||
**返回:** `Matrix4` - 旋转矩阵
|
||||
**返回:** 绕 Z 轴旋转的矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 rotZ = Matrix4::RotationZ(Math::HALF_PI);
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 rotZ = Matrix4::RotationZ(3.14159265f / 2.0f); // 90 度
|
||||
Vector3 point(1.0f, 0.0f, 0.0f);
|
||||
Vector3 rotated = rotZ.MultiplyVector(point);
|
||||
// point 绕 Z 轴旋转 90 度
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [RotationX](rotationx.md) - 绕 X 轴旋转
|
||||
- [RotationY](rotationy.md) - 绕 Y 轴旋转
|
||||
@@ -1,20 +1,35 @@
|
||||
# Matrix4::Scale
|
||||
# Matrix4x4::Scale
|
||||
|
||||
```cpp
|
||||
static Matrix4 Scale(const Vector3& v)
|
||||
static Matrix4x4 Scale(const Vector3& v)
|
||||
```
|
||||
|
||||
创建缩放矩阵。
|
||||
创建缩放矩阵。用于沿各轴方向对点或向量进行缩放变换。
|
||||
|
||||
**参数:**
|
||||
- `v` - 各轴缩放因子
|
||||
- `v` - 缩放向量,指定 x、y、z 方向上的缩放因子
|
||||
|
||||
**返回:** `Matrix4` - 缩放矩阵
|
||||
**返回:** 缩放矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 scale = Matrix4::Scale(Vector3(2.0f, 2.0f, 2.0f));
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 scale = Matrix4::Scale(Vector3(2.0f, 0.5f, 1.0f));
|
||||
Vector3 point(2.0f, 4.0f, 2.0f);
|
||||
Vector3 scaled = scale.MultiplyVector(point);
|
||||
// scaled = (4.0f, 2.0f, 2.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [TRS](trs.md) - 组合变换矩阵
|
||||
@@ -1,20 +1,35 @@
|
||||
# Matrix4::Translation
|
||||
# Matrix4x4::Translation
|
||||
|
||||
```cpp
|
||||
static Matrix4 Translation(const Vector3& v)
|
||||
static Matrix4x4 Translation(const Vector3& v)
|
||||
```
|
||||
|
||||
创建平移矩阵。
|
||||
创建平移矩阵。生成的矩阵用于沿指定方向移动点或向量。
|
||||
|
||||
**参数:**
|
||||
- `v` - 平移向量
|
||||
- `v` - 平移向量 (x, y, z 方向上的平移量)
|
||||
|
||||
**返回:** `Matrix4` - 平移矩阵
|
||||
**返回:** 平移矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 translation = Matrix4::Translation(Vector3(1.0f, 2.0f, 3.0f));
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 translate = Matrix4::Translation(Vector3(5.0f, 3.0f, 2.0f));
|
||||
Vector3 point(1.0f, 1.0f, 1.0f);
|
||||
Vector3 moved = translate.MultiplyPoint(point);
|
||||
// moved = (6.0f, 4.0f, 3.0f)
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [TRS](trs.md) - 组合变换矩阵
|
||||
@@ -1,18 +1,32 @@
|
||||
# Matrix4::Transpose
|
||||
# Matrix4x4::Transpose
|
||||
|
||||
```cpp
|
||||
Matrix4 Transpose() const
|
||||
Matrix4x4 Transpose() const
|
||||
```
|
||||
|
||||
返回矩阵的转置。
|
||||
返回矩阵的转置。转置操作将矩阵的行和列互换。
|
||||
|
||||
**返回:** `Matrix4` - 转置矩阵
|
||||
**参数:** (无)
|
||||
|
||||
**复杂度:** O(1)
|
||||
**返回:** 转置后的矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(n²) - O(16)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 m = ...;
|
||||
Matrix4 transposed = m.Transpose();
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 m = Matrix4::Identity();
|
||||
Matrix4 t = m.Transpose();
|
||||
// 转置后仍为单位矩阵
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Inverse](inverse.md) - 矩阵求逆
|
||||
@@ -1,22 +1,45 @@
|
||||
# Matrix4::TRS
|
||||
# Matrix4x4::TRS
|
||||
|
||||
```cpp
|
||||
static Matrix4 TRS(const Vector3& translation, const Quaternion& rotation, const Vector3& scale)
|
||||
static Matrix4x4 TRS(const Vector3& translation, const Quaternion& rotation, const Vector3& scale)
|
||||
```
|
||||
|
||||
创建完整的 TRS(平移、旋转、缩放)变换矩阵。
|
||||
创建组合变换矩阵。等价于先缩放、再旋转、最后平移的组合效果。
|
||||
|
||||
**参数:**
|
||||
- `translation` - 平移向量
|
||||
- `rotation` - 旋转四元数
|
||||
- `scale` - 缩放向量
|
||||
|
||||
**返回:** `Matrix4` - 组合变换矩阵
|
||||
**返回:** 组合变换矩阵 T * R * S
|
||||
|
||||
**复杂度:** O(1)
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(n²) - 涉及多次 4x4 矩阵运算
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
Matrix4 transform = Matrix4::TRS(position, rotation, Vector3::One());
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
#include "XCEngine/Math/Vector3.h"
|
||||
#include "XCEngine/Math/Quaternion.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 transform = Matrix4::TRS(
|
||||
Vector3(1.0f, 2.0f, 3.0f),
|
||||
Quaternion::FromEuler(0.0f, 90.0f, 0.0f),
|
||||
Vector3(2.0f, 2.0f, 2.0f)
|
||||
);
|
||||
|
||||
Vector3 point(1.0f, 0.0f, 0.0f);
|
||||
Vector3 transformed = transform.MultiplyPoint(point);
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
- [Translation](translation.md) - 平移矩阵
|
||||
- [Rotation](rotation.md) - 旋转矩阵
|
||||
- [Scale](scale.md) - 缩放矩阵
|
||||
- [Decompose](decompose.md) - 分解矩阵
|
||||
@@ -1,17 +1,30 @@
|
||||
# Matrix4::Zero
|
||||
# Matrix4x4::Zero
|
||||
|
||||
```cpp
|
||||
static Matrix4 Zero()
|
||||
static Matrix4x4 Zero()
|
||||
```
|
||||
|
||||
返回零矩阵。
|
||||
返回零矩阵。所有元素初始化为 0 的矩阵。
|
||||
|
||||
**返回:** `Matrix4` - 零矩阵
|
||||
**参数:** (无)
|
||||
|
||||
**返回:** 零矩阵
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "XCEngine/Math/Matrix4.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
Matrix4 zero = Matrix4::Zero();
|
||||
// 所有元素均为 0
|
||||
```
|
||||
|
||||
## 相关文档
|
||||
|
||||
- [Matrix4](matrix4.md) - 返回类总览
|
||||
35
docs/api/math/obb/contains.md
Normal file
35
docs/api/math/obb/contains.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# OBB::Contains
|
||||
|
||||
```cpp
|
||||
bool Contains(const Vector3& point) const;
|
||||
```
|
||||
|
||||
检测给定点是否位于 OBB 包围盒内部。通过将点变换到局部坐标系,然后检查其坐标分量是否在半长向量范围内。
|
||||
|
||||
**参数:**
|
||||
- `point` - 待检测的三维点
|
||||
|
||||
**返回:** 点在包围盒内返回 `true`,否则返回 `false`
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "AABB.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
OBB obb(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 1.0f));
|
||||
|
||||
Vector3 insidePoint(0.0f, 0.0f, 0.0f);
|
||||
Vector3 outsidePoint(2.0f, 0.0f, 0.0f);
|
||||
|
||||
bool isInside = obb.Contains(insidePoint);
|
||||
bool isOutside = obb.Contains(outsidePoint);
|
||||
```
|
||||
33
docs/api/math/obb/get-axis.md
Normal file
33
docs/api/math/obb/get-axis.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# OBB::GetAxis
|
||||
|
||||
```cpp
|
||||
Vector3 GetAxis(int index) const;
|
||||
```
|
||||
|
||||
获取 OBB 在指定索引处的局部轴方向。index 取值为 0、1、2,分别对应局部坐标系的 X、Y、Z 轴。
|
||||
|
||||
**参数:**
|
||||
- `index` - 轴索引(0=X轴,1=Y轴,2=Z轴)
|
||||
|
||||
**返回:** 对应索引处的轴方向向量(已归一化)
|
||||
|
||||
**异常:** 无
|
||||
|
||||
**线程安全:** ✅
|
||||
|
||||
**复杂度:** O(1)
|
||||
|
||||
**示例:**
|
||||
|
||||
```cpp
|
||||
#include "AABB.h"
|
||||
#include "Vector3.h"
|
||||
|
||||
using namespace XCEngine::Math;
|
||||
|
||||
OBB obb(Vector3(0.0f, 0.0f, 0.0f), Vector3(1.0f, 0.5f, 1.0f));
|
||||
|
||||
Vector3 axisX = obb.GetAxis(0);
|
||||
Vector3 axisY = obb.GetAxis(1);
|
||||
Vector3 axisZ = obb.GetAxis(2);
|
||||
```
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user