1. 常用数学常量
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 
 | const float kPi = 3.14159265f;
 const float k2Pi = kPi * 2.0f;
 const float kPiOver2 = kPi / 2.0f;
 const float k1OverPi = 1.0f / kPi;
 const float k1Over2Pi = 1.0f / k2Pi;
 const float kPiOver180 = kPi / 180.0f;
 const float k180OverPi = 180.0f / kPi;
 
 
 const Vector3 kZeroVector(0.0f, 0.0f, 0.0f);
 
 | 
 2. 成员函数
| 12
 3
 4
 5
 6
 7
 
 | float wrapPi(float theta) {
 theta += kPi;
 theta -= floor(theta * k1Over2Pi) * k2Pi;
 theta -= kPi;
 return theta;
 }
 
 | 
- θ 减去向下取 2π 的整数倍,使得 θ∈[−π,π]
θ=θ−⌊2πθ+π⌋∗2π−π
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 
 | 
 
 
 
 float safeAcos(float x) {
 
 
 
 if (x <= -1.0f) {
 return kPi;
 }
 if (x >= 1.0f) {
 return 0.0f;
 }
 
 
 
 return acos(x);
 }
 
 
 
 inline float	degToRad(float deg) { return deg * kPiOver180; }
 inline float	radToDeg(float rad) { return rad * k180OverPi; }
 
 
 
 
 inline void sinCos(float* returnSin, float* returnCos, float theta) {
 
 
 *returnSin = sin(theta);
 *returnCos = cos(theta);
 }
 
 
 
 
 inline float	fovToZoom(float fov) { return 1.0f / tan(fov * .5f); }
 inline float	zoomToFov(float zoom) { return 2.0f * atan(1.0f / zoom); }
 
 |