Fixed broken references: - texture-import-settings: Fix 16 files referencing wrong overview filename - math/rectint: Fix 9 method links (rectint-* → get*, contains, intersects) - rhi/opengl/device: Fix 8 cross-references (opengl-* → */**) - resources/mesh: Fix meshsection and vertexattribute links - rhi/d3d12/sampler: Fix RHISampler reference path - math/vector3: Fix projectonplane → project-on-plane - rhi/opengl/command-list: Remove broken ClearFlag enum ref - rhi/opengl/device: Create 2 new method docs (MakeContextCurrent, GetNativeContext) - rhi/device: Fix device-info types reference All 0 broken references remaining.
3.1 KiB
3.1 KiB
Math 模块概览
命名空间: XCEngine::Math
类型: module
描述: XCEngine 的数学库模块,提供图形引擎常用的数学类型和函数。
概述
Math 模块提供了一套完整的图形数学库,包括向量、矩阵、四元数、变换和几何类型等。
模块内容
向量类型
| 组件 | 文件 | 描述 |
|---|---|---|
| Vector2 | Vector2.h |
二维向量 |
| Vector3 | Vector3.h |
三维向量 |
| Vector4 | Vector4.h |
四维向量 |
矩阵类型
| 组件 | 文件 | 描述 |
|---|---|---|
| Matrix3 | Matrix3.h |
3x3 矩阵 |
| Matrix4 | Matrix4.h |
4x4 矩阵 |
旋转/变换
| 组件 | 文件 | 描述 |
|---|---|---|
| Quaternion | Quaternion.h |
四元数 |
| Transform | Transform.h |
变换组件 |
几何类型
| 组件 | 文件 | 描述 |
|---|---|---|
| Color | Color.h |
颜色 |
| Ray | Ray.h |
射线 |
| Plane | Plane.h |
平面 |
| Sphere | Sphere.h |
球体 |
| Box | Box.h |
盒子 |
| Bounds | Bounds.h |
轴对齐包围盒 |
| OBB | AABB.h |
有向包围盒 |
| Frustum | Frustum.h |
视锥体 |
| Rect | Rect.h |
二维矩形 |
| RectInt | Rect.h |
整数矩形 |
常量定义
| 常量 | 值 | 描述 |
|---|---|---|
PI |
3.14159265358979323846f | 圆周率 |
TWO_PI |
6.28318530717958647692f | 2π |
HALF_PI |
1.57079632679489661923f | π/2 |
DEG_TO_RAD |
PI / 180.0f | 度到弧度 |
RAD_TO_DEG |
180.0f / PI | 弧度到度 |
EPSILON |
1e-6f | 浮点精度 |
FLOAT_MAX |
3.402823466e+38f | 浮点最大值 |
详细文档: Math.h - 常量和辅助函数
辅助函数
| 函数 | 描述 |
|---|---|
Radians(float degrees) |
度转弧度 |
Degrees(float radians) |
弧度转度 |
使用示例
#include <XCEngine/Core/Math/Math.h>
#include <XCEngine/Core/Math/Vector3.h>
#include <XCEngine/Core/Math/Matrix4.h>
#include <XCEngine/Core/Math/Quaternion.h>
using namespace XCEngine::Math;
// 向量运算
Vector3 a(1.0f, 0.0f, 0.0f);
Vector3 b(0.0f, 1.0f, 0.0f);
float dot = Vector3::Dot(a, b);
Vector3 cross = Vector3::Cross(a, b);
Vector3 normalized = Vector3::Normalize(a);
// 矩阵运算
Matrix4 model = Matrix4::TRS(position, rotation, scale);
Matrix4 view = Matrix4::LookAt(eye, target, up);
Matrix4 projection = Matrix4::Perspective(fov, aspect, near, far);
Matrix4 mvp = projection * view * model;
// 四元数运算
Quaternion q1 = Quaternion::FromEulerAngles(0, 90 * DEG_TO_RAD, 0);
Quaternion q2 = Quaternion::FromAxisAngle(Vector3::Up(), Math::Radians(45.0f));
Quaternion combined = q1 * q2;
Vector3 rotated = q2 * Vector3::Forward();