Files
XCSDD/docs/api/math/vector3/vector3.md
ssdfasd 58a83f445a fix: improve doc link navigation and tree display
- Fix link resolution with proper relative/absolute path handling
- Improve link styling with underline decoration
- Hide leaf nodes from tree, only show directories
- Fix log file path for packaged app
2026-03-19 12:44:08 +08:00

2.3 KiB
Raw Permalink Blame History

Vector3

3D 向量结构体,用于表示 3D 空间中的点、方向、颜色或法线。

头文件: #include <XCEngine/Math/Vector3.h>

命名空间: XCEngine::Math

结构体定义

struct Vector3 {
    float x = 0.0f;
    float y = 0.0f;
    float z = 0.0f;
};

静态工厂方法

方法 返回值 描述
Zero() Vector3 返回 (0, 0, 0)
One() Vector3 返回 (1, 1, 1)
Forward() Vector3 返回 (0, 0, 1)前方向Z+
Back() Vector3 返回 (0, 0, -1),后方向
Up() Vector3 返回 (0, 1, 0),上方向
Down() Vector3 返回 (0, -1, 0),下方向
Right() Vector3 返回 (1, 0, 0),右方向
Left() Vector3 返回 (-1, 0, 0),左方向

静态数学方法

方法 返回值 描述
Dot(a, b) float 点积
Cross(a, b) Vector3 叉积(垂直于 a 和 b
Normalize(v) Vector3 归一化向量
Magnitude(v) float 向量长度
SqrMagnitude(v) float 长度平方
Lerp(a, b, t) Vector3 线性插值
MoveTowards(current, target, maxDistance) Vector3 朝目标移动
Project(vector, onNormal) Vector3 投影到法线上
ProjectOnPlane(vector, planeNormal) Vector3 投影到平面上
Angle(from, to) float 两向量夹角(度)
Reflect(inDirection, inNormal) Vector3 反射

实例方法

方法 返回值 描述
Magnitude() float 获取向量长度
SqrMagnitude() float 获取长度平方
Normalized() Vector3 获取归一化副本

运算符

  • 算术: +, -, * (scalar/memberwise), / (scalar/memberwise)
  • 复合赋值: +=, -=, *=, /=
  • 下标: operator[] (0=x, 1=y, 2=z)
  • 比较: ==, !=

与 Quaternion 的乘法

Vector3 * Quaternion - 用四元数旋转向量

相关文档