-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathTrigLUT.hpp
More file actions
78 lines (64 loc) · 2.45 KB
/
Copy pathTrigLUT.hpp
File metadata and controls
78 lines (64 loc) · 2.45 KB
1
2
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#ifndef TRIGLUT_HPP
#define TRIGLUT_HPP
#include <cstdint>
#include "FastMath.hpp"
#include "JetConfig.hpp"
namespace Renderer
{
const int ANGLE_MAX = 360;
const int FIXED_POINT_SCALE = 1 << 10; // Adjusted for better precision
constexpr int32_t FIXED_POINT_SHIFT = 10; // Use a fixed-point scale factor of 2^10
#define M_PI 3.14159265358979323846
extern int32_t sin_table[ANGLE_MAX];
extern int32_t tan_table[ANGLE_MAX];
void initializeTrigTables();
// Integer lookup functions
inline int32_t lookupSinI(int angle) {
int idx = angle % ANGLE_MAX;
if (idx < 0) idx += ANGLE_MAX;
return sin_table[idx];
}
inline int32_t lookupCosI(int angle) {
int idx = (angle + 90) % ANGLE_MAX;
if (idx < 0) idx += ANGLE_MAX;
return sin_table[idx];
}
inline int32_t lookupTanI(int angle) {
int idx = angle % ANGLE_MAX;
if (idx < 0) idx += ANGLE_MAX;
return tan_table[idx];
}
#if FLOAT_CAMERA_ANGLES
// Number of subdivisions based on respective scales
const int FLOAT_SIN_SUBDIVISIONS = FLOAT_SIN_CACHE_SCALE;
const int FLOAT_TAN_SUBDIVISIONS = FLOAT_TAN_CACHE_SCALE;
const int FLOAT_SIN_ANGLE_MAX = 360 * FLOAT_SIN_SUBDIVISIONS;
const int FLOAT_TAN_ANGLE_MAX = 360 * FLOAT_TAN_SUBDIVISIONS;
extern float float_sin_table[FLOAT_SIN_ANGLE_MAX];
#if FLOAT_TAN_CACHE_SCALE > 1
extern float float_tan_table[FLOAT_TAN_ANGLE_MAX];
#endif
// Helper functions for float angle lookups
inline float lookupSin(float angle) {
int idx = static_cast<int>((angle * FLOAT_SIN_SUBDIVISIONS)) % FLOAT_SIN_ANGLE_MAX;
if (idx < 0) idx += FLOAT_SIN_ANGLE_MAX;
return float_sin_table[idx];
}
inline float lookupCos(float angle) {
int idx = static_cast<int>((angle + 90.0f) * FLOAT_SIN_SUBDIVISIONS) % FLOAT_SIN_ANGLE_MAX;
if (idx < 0) idx += FLOAT_SIN_ANGLE_MAX;
return float_sin_table[idx];
}
inline float lookupTan(float angle) {
#if FLOAT_TAN_CACHE_SCALE > 1
int idx = static_cast<int>((angle * FLOAT_TAN_SUBDIVISIONS)) % FLOAT_TAN_ANGLE_MAX;
if (idx < 0) idx += FLOAT_TAN_ANGLE_MAX;
return float_tan_table[idx];
#else
// Use integer lookup when scale is 1
return static_cast<float>(lookupTanI(static_cast<int>(angle))) / FIXED_POINT_SCALE;
#endif
}
#endif
} // namespace Renderer
#endif // TRIGLUT_HPP