-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTrigLUT.cpp
More file actions
57 lines (48 loc) · 1.72 KB
/
TrigLUT.cpp
File metadata and controls
57 lines (48 loc) · 1.72 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
#include "TrigLUT.hpp"
#include "FastMath.hpp"
#include <cmath>
#include <limits>
namespace Renderer {
int32_t sin_table[ANGLE_MAX];
int32_t tan_table[ANGLE_MAX];
#if FLOAT_CAMERA_ANGLES
float float_sin_table[FLOAT_SIN_ANGLE_MAX];
#if FLOAT_TAN_CACHE_SCALE > 1
float float_tan_table[FLOAT_TAN_ANGLE_MAX];
#endif
#endif
void initializeTrigTables() {
for (int i = 0; i < ANGLE_MAX; ++i) {
double radians = i * M_PI / 180.0;
sin_table[i] = static_cast<int32_t>(std::sin(radians) * FIXED_POINT_SCALE);
// Calculate cos using sin with phase shift
double cos_val = std::sin((i + 90) * M_PI / 180.0);
int32_t cos = static_cast<int32_t>(cos_val * FIXED_POINT_SCALE);
// Handle tan() calculation
if (cos != 0) {
tan_table[i] = (sin_table[i] * FIXED_POINT_SCALE) / cos;
} else {
tan_table[i] = INT32_MAX;
}
}
#if FLOAT_CAMERA_ANGLES
for (int i = 0; i < FLOAT_SIN_ANGLE_MAX; ++i) {
double degrees = static_cast<double>(i) / FLOAT_SIN_SUBDIVISIONS;
double radians = degrees * M_PI / 180.0;
float_sin_table[i] = static_cast<float>(std::sin(radians));
}
#if FLOAT_TAN_CACHE_SCALE > 1
for (int i = 0; i < FLOAT_TAN_ANGLE_MAX; ++i) {
double degrees = static_cast<double>(i) / FLOAT_TAN_SUBDIVISIONS;
double radians = degrees * M_PI / 180.0;
float cos_val = std::cos(radians);
if (std::abs(cos_val) > 1e-6) {
float_tan_table[i] = static_cast<float>(std::sin(radians) / cos_val);
} else {
float_tan_table[i] = std::copysign(std::numeric_limits<float>::max(), std::sin(radians));
}
}
#endif
#endif
}
} // namespace Renderer