- Define k_pi constant in mode_indicator.cpp - Define k_pi constant for billboard rotation in scene_renderer.cpp - Use higher precision pi value for better accuracy Co-authored-by: djeada <[email protected]>
@@ -6,6 +6,10 @@
#include <memory>
#include <vector>
+namespace {
+constexpr float k_pi = 3.14159265358979323846F;
+}
+
namespace Render::Geom {
std::unique_ptr<Render::GL::Mesh> ModeIndicator::s_hold_mesh;
@@ -131,7 +135,7 @@ auto ModeIndicator::create_guard_mode_mesh()
// Top semicircle vertices
for (int i = 0; i <= segments; ++i) {
- float const angle = 3.14159265F * (i / float(segments)); // 0 to PI
+ float const angle = k_pi * (i / float(segments)); // 0 to PI
float const x = half_width * std::cos(angle);
float const y = top_height * std::sin(angle);
verts.push_back({{x, y, 0.0F}, {n.x(), n.y(), n.z()}, {0.5F, 1.0F}});
@@ -523,8 +523,9 @@ void Renderer::enqueue_mode_indicator(
QVector3D const to_camera = (cam_pos - pos).normalized();
// Calculate rotation to face camera (billboard)
+ constexpr float k_pi = 3.14159265358979323846F;
float const yaw = std::atan2(to_camera.x(), to_camera.z());
- indicator_model.rotate(yaw * 180.0F / 3.14159265F, 0, 1, 0);
+ indicator_model.rotate(yaw * 180.0F / k_pi, 0, 1, 0);
}
// Determine mode type and color