1. 向量
1.1 成员变量
成 员 |
含 义 |
float x |
x 分量 |
float y |
y 分量 |
float z |
z 分量 |
1.2 构造函数
构造函数 |
含 义 |
Vector3(); |
默认构造函数,不执行任何操作 |
Vector3(const Vector3& a); |
复制构造函数 |
Vector3(float nx, float ny, float nz); |
带参数的构造函数,用三个值完成初始化 |
1.3 成员函数
1.3.1 重载函数
重载操作符 |
重载函数 |
含 义 |
v = a |
Vector3& operator =(const Vector3& a); |
赋值 |
v == a |
bool operator ==(const Vector3& a) const; |
重载 “==” 操作符 |
v != a |
bool operator !=(const Vector3& a) const; |
|
- v |
Vector3 operator -() const; |
重载一元“-”运算符 |
v + a |
Vector3 operator +(const Vector3& a) const; |
重载二元“+”和“-”运算符 |
v - a |
Vector3 operator -(const Vector3& a) const; |
|
v * k |
Vector3 operator *(float a) const; |
与标量的乘、除法 |
v / k |
Vector3 operator /(float a) const; |
|
v += a |
Vector3& operator +=(const Vector3& a); |
重载自反运算符 |
v -= a |
Vector3& operator -=(const Vector3& a); |
|
v *= a |
Vector3& operator *=(float a); |
|
v /= a |
Vector3& operator /=(float a); |
|
v * a |
float operator *(const Vector3& a) const; |
向量点乘 |
1.3.2 其他函数
函 数 |
含 义 |
void zero(); |
置为零向量 |
void normalize(); |
向量标准化 |
1.4 全局变量
全局变量 |
含 义 |
extern const Vector3 kZeroVector; |
提供一个全局零向量 |
1.5 非成员函数
非成员函数 |
含 义 |
inline float vectorMag(const Vector3& a); |
求向量模 |
inline Vector3 crossProduct(const Vector3& a, const Vector3& b); |
计算两向量的叉乘 |
inline Vector3 operator *(float k, const Vector3& v); |
实现标量左乘 |
inline float distance(const Vector3& a, const Vector3& b); |
计算两点间的距离 |
inline float distanceSquared(const Vector3& a, const Vector3& b); |
计算两点之间的距离的平方 |
2. 数据计算工具类
2.1 常量
2.1.1 定义和 π 有关的常量
常 量 |
含 义 |
const float kPi |
π |
const float k2Pi |
2π |
const float kPiOver2 |
2π |
const float k1OverPi |
π1 |
const float k1Over2Pi |
2π1 |
const float kPiOver180 |
180π |
const float k180OverPi |
π180 |
2.1.2 定义和向量有关的常量
常 量 |
含 义 |
const Vector3 kZeroVector |
定义零向量 |
2.2 成员函数
函 数 |
含 义 |
float wrapPi(float theta); |
通过加上适当的 2π 倍数,将角度限制在 −π 到 π 的区间内 |
float safeAcos(float x); |
“安全”反三角函数 |
inline float degToRad(float deg); |
在度数和弧度之间转换 |
inline float radToDeg(float rad); |
|
inline void sinCos(float* returnSin, float* returnCos, float theta); |
同时计算角度的 sin 和 cos 值 |
inline float fovToZoom(float fov); |
“视野”和“缩放”之间的转换,视场角度以弧度表示。 |
inline float zoomToFov(float zoom); |
|
3. 三维射线类
3.1 成员变量
变 量 |
含 义 |
Vector3 start |
起点向量 |
Vector3 dir |
使用一个单位向量表示射线的方向 |
float len |
表示射线的长度 |
float t |
射线参数,从 0 到 len |
4. AABB 类
4.1 成员变量
变 量 |
含 义 |
Vector3 min |
三个分量均最小的点 |
Vector3 max |
三个分量均最大的点 |
5. 欧拉角类
5.1 成员变量
成员变量 |
含 义 |
float heading |
航向角,绕 y 轴的旋转量 |
float pitch |
俯仰角,绕 x 轴的旋转量 |
float bank |
倾斜角,绕 z 轴的旋转量 |
5.2 全局变量
全局变量 |
含 义 |
extern const EulerAngles kEulerAnglesIdentity; |
全局的 “单位” 欧拉角 |
5.3 构造函数
构造函数 |
含 义 |
EulerAngles(); |
默认构造函数,不执行任何操作 |
EulerAngles(float h, float p, float b); |
带参数的构造函数,用三个值完成初始化 |
5.4 成员函数
成员函数 |
含 义 |
void identity(); |
设置单位三元组 (全部置零) |
void canonize(); |
变换为“限制集”欧拉角 |
5.4.1 从四元数转到欧拉角
成员函数 |
含 义 |
void fromObjectToInertialQuaternion(const Quaternion& q); |
四元数(物体 - 惯性)转换为欧拉角 |
void fromInertialToObjectQuaternion(const Quaternion& q); |
四元数(惯性 - 物体)转换为欧拉角 |
- 四元数(物体 - 惯性) :代表从物体坐标系到惯性坐标系旋转的四元数
- 四元数(惯性 - 物体) :代表从惯性坐标系到物体坐标系旋转的四元数
5.4.2 从矩阵转换到欧拉角
成员函数 |
含 义 |
void fromObjectToWorldMatrix(const Matrix4x3& m); |
变换矩阵(物体 - 世界)转换为欧拉角 |
void fromWorldToObjectMatrix(const Matrix4x3& m); |
变换矩阵(世界 - 物体)转换为欧拉角 |
void fromRotationMatrix(const RotationMatrix& m); |
从旋转矩阵转换到欧拉角 |
将矩阵的旋转部分的方位转换为欧拉角,假设这个被转换的矩阵是正交的。