Replace M_PI with C++ numbers

C++20 added π (pi) to the standard, replace the C macro globally.

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
This commit is contained in:
Ralph Sennhauser 2026-06-04 19:46:01 +02:00
parent 4379194255
commit 0c0552a428
No known key found for this signature in database
26 changed files with 99 additions and 81 deletions

View file

@ -44,7 +44,7 @@
#include <SDL_events.h>
#include <algorithm>
#include <cmath>
#include <numbers>
#include <functional>
#include <string>
@ -258,7 +258,7 @@ void CCameraController::Update(const float deltaRealTime)
cmpPosition->GetInterpolatedPosition2D(frameOffset, x, z, angle);
float height = 4.f;
m_Camera.m_Orientation.SetIdentity();
m_Camera.m_Orientation.RotateX(static_cast<float>(M_PI) / 24.f);
m_Camera.m_Orientation.RotateX(std::numbers::pi_v<float> / 24.f);
m_Camera.m_Orientation.RotateY(angle);
m_Camera.m_Orientation.Translate(pos.X, pos.Y + height, pos.Z);
@ -305,7 +305,7 @@ void CCameraController::Update(const float deltaRealTime)
if (m_ConstrainCamera)
{
if (m_BirdsEyeView)
m_RotateX.ClampSmoothly(static_cast<float>(M_PI_2), static_cast<float>(M_PI_2));
m_RotateX.ClampSmoothly(std::numbers::pi_v<float> / 2.f, std::numbers::pi_v<float> / 2.f);
else
m_RotateX.ClampSmoothly(DEGTORAD(m_ViewRotateXMin), DEGTORAD(m_ViewRotateXMax));
}
@ -423,7 +423,7 @@ void CCameraController::Update(const float deltaRealTime)
}
*/
m_RotateY.Wrap(-static_cast<float>(M_PI), static_cast<float>(M_PI));
m_RotateY.Wrap(-std::numbers::pi_v<float>, std::numbers::pi_v<float>);
// Update the camera matrix
SetCameraProjection();
@ -567,7 +567,7 @@ void CCameraController::ResetCameraAngleZoom()
void CCameraController::ToggleBirdsEyeView()
{
m_BirdsEyeView = !m_BirdsEyeView;
float angle = m_BirdsEyeView ? M_PI / 2 : DEGTORAD(m_ViewRotateXDefault);
float angle = m_BirdsEyeView ? std::numbers::pi_v<float> / 2.f : DEGTORAD(m_ViewRotateXDefault);
m_RotateX.SetValueSmoothly(angle);
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -104,14 +104,14 @@ private:
/**
* Height of sun above the horizon, in radians.
* For example, an elevation of M_PI/2 means the sun is straight up.
* For example, an elevation of PI/2 means the sun is straight up.
*/
float m_Elevation;
/**
* Direction of sun on the compass, in radians.
* For example, a rotation of zero means the sun is in the direction (0,0,-1)
* and a rotation of M_PI/2 means the sun is in the direction (1,0,0) (not taking
* and a rotation of PI/2 means the sun is in the direction (1,0,0) (not taking
* elevation into account).
*/
float m_Rotation;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -63,6 +63,7 @@
#include <cmath>
#include <cstddef>
#include <map>
#include <numbers>
#include <string>
#include <utility>
@ -307,7 +308,7 @@ void CMapWriter::WriteXML(const VfsPath& filename,
CVector3D in = pCamera->GetOrientation().GetIn();
// Convert to spherical coordinates
float rotation = atan2(in.X, in.Z);
float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - static_cast<float>(M_PI / 2);
float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - std::numbers::pi_v<float> / 2.f;
{
XMLWriter_Element rotationTag(xmlMapFile, "Rotation");

View file

@ -72,6 +72,7 @@
#include <cmath>
#include <cstdint>
#include <iterator>
#include <numbers>
#include <utility>
namespace
@ -282,8 +283,8 @@ CMiniMapTexture::CMiniMapTexture(Renderer::Backend::IDevice* device, CSimulation
m_InstanceAttributePosition.GetIterator<float[2]>();
for (size_t segment = 0; segment < numberOfCircleSegments; ++segment)
{
const float currentAngle = static_cast<float>(segment) / numberOfCircleSegments * 2.0f * M_PI;
const float nextAngle = static_cast<float>(segment + 1) / numberOfCircleSegments * 2.0f * M_PI;
const float currentAngle = static_cast<float>(segment) / numberOfCircleSegments * 2.0f * std::numbers::pi_v<float>;
const float nextAngle = static_cast<float>(segment + 1) / numberOfCircleSegments * 2.0f * std::numbers::pi_v<float>;
(*attributePosition)[0] = 0.0f;
(*attributePosition)[1] = 0.0f;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -36,13 +36,14 @@
#include <boost/token_functions.hpp>
#include <boost/tokenizer.hpp>
#include <cmath>
#include <numbers>
#include <string>
CTerrainProperties::CTerrainProperties(CTerrainPropertiesPtr parent):
m_pParent(parent),
m_BaseColor(0),
m_HasBaseColor(false),
m_TextureAngle((float)M_PI / 4.f),
m_TextureAngle(std::numbers::pi_v<float> / 4.f),
m_TextureSize(32.f)
{
if (m_pParent)

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -60,12 +60,6 @@ int setenv(const char* envname, const char* envval, int overwrite);
//
// (missing on MSVC)
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_PI_2
#define M_PI_2 1.57079632679489661923
#endif
#ifndef INFINITY
#define INFINITY (std::numeric_limits<float>::infinity())
#endif

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2022 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -18,8 +18,10 @@
#ifndef INCLUDED_MATHUTIL
#define INCLUDED_MATHUTIL
#define DEGTORAD(a) ((a) * ((float)M_PI/180.0f))
#define RADTODEG(a) ((a) * (180.0f/(float)M_PI))
#include <numbers>
#define DEGTORAD(a) ((a) * (std::numbers::pi_v<float> / 180.0f))
#define RADTODEG(a) ((a) * (180.0f / std::numbers::pi_v<float>))
#define SQR(x) ((x) * (x))
template<typename T>

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -24,6 +24,7 @@
#include "maths/Vector3D.h"
#include <cmath>
#include <numbers>
const float EPSILON=0.0001f;
@ -136,13 +137,13 @@ CVector3D CQuaternion::ToEulerAngles()
if (test > (.5f-EPSILON)*unit)
{ // singularity at north pole
heading = 2 * atan2( m_V.X, m_W);
attitude = (float)M_PI/2;
attitude = std::numbers::pi_v<float> / 2.f;
bank = 0;
}
else if (test < (-.5f+EPSILON)*unit)
{ // singularity at south pole
heading = -2 * atan2(m_V.X, m_W);
attitude = -(float)M_PI/2;
attitude = -std::numbers::pi_v<float> / 2.f;
bank = 0;
}
else

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -23,6 +23,7 @@
#include "maths/Vector3D.h"
#include <cmath>
#include <numbers>
#define TS_ASSERT_VEC_DELTA(v, x, y, z, delta) \
TS_ASSERT_DELTA(v.X, x, delta); \
@ -107,7 +108,7 @@ public:
CBoundingBoxAligned aabb(CVector3D(3, -1.5f, -1.5f), CVector3D(7, 1.5f, 1.5f));
CMatrix3D rotation;
rotation.SetZRotation(float(M_PI)/2.f);
rotation.SetZRotation(std::numbers::pi_v<float> / 2.f);
CBoundingBoxOriented result;
aabb.Transform(rotation, result);
@ -128,7 +129,7 @@ public:
CMatrix3D rotate;
CMatrix3D translateBack;
translate.SetTranslation(-2.f, 0, 0);
rotate.SetZRotation(-float(M_PI)/4.f);
rotate.SetZRotation(-std::numbers::pi_v<float> / 4.f);
translateBack.SetTranslation(2.f, 0, 0);
CMatrix3D transform;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -30,6 +30,7 @@
#include <algorithm>
#include <cmath>
#include <limits>
#include <numbers>
class TestFixed : public CxxTest::TestSuite
{
@ -254,10 +255,10 @@ public:
void test_Atan2()
{
// Special cases from atan2 man page:
TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(0), fixed::FromInt(-1)).ToDouble(), M_PI, 0.01);
TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(0), fixed::FromInt(-1)).ToDouble(), std::numbers::pi, 0.01);
TS_ASSERT_EQUALS(atan2_approx(fixed::FromInt(0), fixed::FromInt(+1)).ToDouble(), 0);
TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(-1), fixed::FromInt(0)).ToDouble(), -M_PI_2, 0.01);
TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(+1), fixed::FromInt(0)).ToDouble(), +M_PI_2, 0.01);
TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(-1), fixed::FromInt(0)).ToDouble(), -std::numbers::pi / 2., 0.01);
TS_ASSERT_DELTA(atan2_approx(fixed::FromInt(+1), fixed::FromInt(0)).ToDouble(), +std::numbers::pi / 2., 0.01);
TS_ASSERT_EQUALS(atan2_approx(fixed::FromInt(0), fixed::FromInt(0)).ToDouble(), 0);
// Test that it approximately matches libc's atan2
@ -308,15 +309,15 @@ public:
TS_ASSERT_DELTA(s.ToDouble(), 0.0, 0.00005);
TS_ASSERT_EQUALS(c, fixed::FromInt(-1));
sincos_approx(fixed::FromDouble(M_PI*2.0), s, c);
sincos_approx(fixed::FromDouble(std::numbers::pi * 2.0), s, c);
TS_ASSERT_DELTA(s.ToDouble(), 0.0, 0.0001);
TS_ASSERT_DELTA(c.ToDouble(), 1.0, 0.0001);
sincos_approx(fixed::FromDouble(M_PI*100.0), s, c);
sincos_approx(fixed::FromDouble(std::numbers::pi * 100.0), s, c);
TS_ASSERT_DELTA(s.ToDouble(), 0.0, 0.004);
TS_ASSERT_DELTA(c.ToDouble(), 1.0, 0.004);
sincos_approx(fixed::FromDouble(M_PI*-100.0), s, c);
sincos_approx(fixed::FromDouble(std::numbers::pi * -100.0), s, c);
TS_ASSERT_DELTA(s.ToDouble(), 0.0, 0.004);
TS_ASSERT_DELTA(c.ToDouble(), 1.0, 0.004);

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -23,6 +23,7 @@
#include "maths/Vector3D.h"
#include <cmath>
#include <numbers>
#include <random>
class TestMatrix : public CxxTest::TestSuite
@ -285,7 +286,7 @@ public:
for (int j = 0; j < 16; ++j)
{
float a = 2 * M_PI * distribution01(m_Engine) - M_PI;
float a = 2 * std::numbers::pi * distribution01(m_Engine) - std::numbers::pi;
m.SetYRotation(a);
TS_ASSERT_DELTA(m.GetYRotation(), a, m_Epsilon);
}

View file

@ -40,6 +40,7 @@
#include <array>
#include <cmath>
#include <numbers>
void CDebugRenderer::Initialize()
{
@ -156,9 +157,9 @@ void CDebugRenderer::DrawCircle(
constexpr size_t segments = 16;
for (size_t idx = 0; idx <= segments; ++idx)
{
const float angle = M_PI * 2.0f * idx / segments;
const float angle = std::numbers::pi_v<float> * 2.0f * idx / segments;
const CVector3D offset = cameraUp * sin(angle) - cameraLeft * cos(angle);
const float nextAngle = M_PI * 2.0f * (idx + 1) / segments;
const float nextAngle = std::numbers::pi_v<float> * 2.0f * (idx + 1) / segments;
const CVector3D nextOffset = cameraUp * sin(nextAngle) - cameraLeft * cos(nextAngle);
ADD(origin)
ADD(origin + offset * radius)

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -58,6 +58,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <numbers>
#include <string>
#include <utility>
@ -262,7 +263,7 @@ void SkyManager::RenderSky(
// each skymap, is in the direction of the sun from our light
// environment.
CMatrix3D rotate;
rotate.SetYRotation(M_PI + g_Renderer.GetSceneRenderer().GetLightEnv().GetRotation());
rotate.SetYRotation(std::numbers::pi_v<float> + g_Renderer.GetSceneRenderer().GetLightEnv().GetRotation());
const CMatrix3D transform = camera.GetViewProjection() * translate * rotate * scale;
deviceCommandContext->SetUniform(

View file

@ -600,7 +600,7 @@ bool TerrainRenderer::RenderFancyWater(
// TODO: check that this rotates in the right direction.
CMatrix3D skyBoxRotation;
skyBoxRotation.SetIdentity();
skyBoxRotation.RotateY(M_PI + lightEnv.GetRotation());
skyBoxRotation.RotateY(std::numbers::pi_v<float> + lightEnv.GetRotation());
deviceCommandContext->SetUniform(
fancyWaterShader->GetBindingSlot(str_skyBoxRot),
skyBoxRotation.AsFloatArray());

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -43,6 +43,7 @@
#include <cmath>
#include <cstddef>
#include <cstdint>
#include <numbers>
/* Note: this implementation uses CVertexBufferManager directly rather than access it through the nicer VertexArray interface,
* because it allows you to work with variable amounts of vertices and indices more easily. New code should prefer
@ -410,7 +411,7 @@ void CTexturedLineRData::CreateLineCap(const SOverlayTexturedLine& line, const C
// To please OpenGL's winding order, this angle needs to be negated depending on whether we start rotating from
// the (center -> corner1) or (center -> corner2) vector. For the (center -> corner2) vector, we apparently need to use
// the negated angle.
float stepAngle = -(float)(M_PI/(roundCapPoints-1));
float stepAngle = -std::numbers::pi_v<float> / (roundCapPoints-1);
// Push the vertices in triangle fan order (easy to generate GL_TRIANGLES indices for afterwards)
// Note that we're manually adding the corner vertices instead of having them be generated by the rotating vector.

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -43,6 +43,7 @@
#include <algorithm>
#include <cmath>
#include <numbers>
#include <set>
#include <string>
#include <utility>
@ -748,7 +749,7 @@ public:
pos.Y += GetConstructionProgressOffset(pos);
m.RotateY(rotY + (float)M_PI);
m.RotateY(rotY + std::numbers::pi_v<float>);
m.Translate(pos);
return m;
@ -808,14 +809,14 @@ public:
{
float rotYSpeed = m_RotYSpeed.ToFloat();
float delta = rotY - m_InterpolatedRotY;
// Wrap delta to -M_PI..M_PI
delta = fmodf(delta + (float)M_PI, 2*(float)M_PI); // range -2PI..2PI
if (delta < 0) delta += 2*(float)M_PI; // range 0..2PI
delta -= (float)M_PI; // range -M_PI..M_PI
// Wrap delta to -PI..PI
delta = fmodf(delta + std::numbers::pi_v<float>, 2.f * std::numbers::pi_v<float>); // range -2PI..2PI
if (delta < 0) delta += 2.f * std::numbers::pi_v<float>; // range 0..2PI
delta -= std::numbers::pi_v<float>; // range -PI..PI
// Clamp to max rate
float deltaClamped = Clamp(delta, -rotYSpeed*msgData.deltaSimTime, +rotYSpeed*msgData.deltaSimTime);
// Calculate new orientation, in a peculiar way in order to make sure the
// result gets close to m_orientation (rather than being n*2*M_PI out)
// result gets close to m_orientation (rather than being n*2*PI out)
m_InterpolatedRotY = rotY + deltaClamped - delta;
// update the visual XZ rotation

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -63,6 +63,7 @@
#include <cmath>
#include <cstddef>
#include <map>
#include <numbers>
#include <queue>
#include <string>
#include <type_traits>
@ -747,7 +748,7 @@ void CCmpTerritoryManager::Interpolate(float frameTime, float /*frameOffset*/)
if (m_BoundaryLines[i].blinking)
{
CColor c = m_BoundaryLines[i].color;
c.a *= 0.2f + 0.8f * fabsf((float)cos(m_AnimTime * M_PI)); // TODO: should let artists tweak this
c.a *= 0.2f + 0.8f * fabsf(static_cast<float>(cos(m_AnimTime * std::numbers::pi))); // TODO: should let artists tweak this
m_BoundaryLines[i].overlay.m_Color = c;
}
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -32,6 +32,7 @@
#include <cstddef>
#include <cstdint>
#include <memory>
#include <numbers>
#include <optional>
#include <string>
#include <vector>
@ -413,7 +414,7 @@ public:
ent4z = fixed::Zero(),
ent4w = fixed::FromInt(1),
ent4h = fixed::FromInt(1);
entity_angle_t ent4a = fixed::FromDouble(M_PI/3);
entity_angle_t ent4a = fixed::FromDouble(std::numbers::pi / 3.);
cmp->AddStaticShape(ent4, ent4x, ent4z, ent4a, ent4w, ent4h, ICmpObstructionManager::FLAG_BLOCK_PATHFINDING, ent4g1, ent4g2);
cmp->SetStaticControlGroup(shape1, ent1g1, ent1g2_new);
@ -470,7 +471,7 @@ public:
// Collision-test a shape that is perfectly adjacent to shape3. This should be counted as a hit according to
// the code at the time of writing.
entity_angle_t ent4a = fixed::FromDouble(M_PI); // rotated 180 degrees, should not affect collision test
entity_angle_t ent4a = fixed::FromDouble(std::numbers::pi); // rotated 180 degrees, should not affect collision test
entity_pos_t ent4w = fixed::FromInt(2),
ent4h = fixed::FromInt(1),
ent4x = ent3x + ent3c + ent4w/2, // make ent4 adjacent to ent3

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -29,6 +29,7 @@
#include "ps/CStr.h"
#include <cmath>
#include <numbers>
#include <string>
#include <vector>
@ -196,7 +197,7 @@ float CCinemaPath::EaseCircle(float t) const
float CCinemaPath::EaseSine(float t) const
{
t = 1.0f - cos(t * (float)M_PI/2);
t = 1.0f - cos(t * std::numbers::pi_v<float> / 2.f);
if (m_GrowthCount > 1.0f)
{
--m_GrowthCount;

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -39,6 +39,7 @@
#include <algorithm>
#include <cmath>
#include <numbers>
#include <utility>
void SimRender::ConstructLineOnGround(const CSimContext& context, const std::vector<float>& xz,
@ -128,7 +129,7 @@ void SimRender::ConstructCircleOnGround(
const CSimContext& context, float x, float z, float radius,
SOverlayLine& overlay, bool floating, float heightOffset)
{
ConstructCircleOrClosedArc(context, x, z, radius, true, 0.0f, 2.0f*(float)M_PI, overlay, floating, heightOffset);
ConstructCircleOrClosedArc(context, x, z, radius, true, 0.0f, 2.0f * std::numbers::pi_v<float>, overlay, floating, heightOffset);
}
void SimRender::ConstructClosedArcOnGround(
@ -260,7 +261,7 @@ void SimRender::ConstructGimbal(const CVector3D& center, float radius, SOverlayL
out.m_Coords.clear();
size_t fullCircleSteps = numSteps;
const float angleIncrement = 2.f*M_PI/fullCircleSteps;
const float angleIncrement = 2.f * std::numbers::pi_v<float> / fullCircleSteps;
const CVector3D X_UNIT(1, 0, 0);
const CVector3D Y_UNIT(0, 1, 0);
@ -625,10 +626,10 @@ void SimRender::ConstructTexturedLineCircle(SOverlayTexturedLine& overlay, const
{
const float radius = overlay_radius + overlay.m_Thickness / 3.f;
size_t numSteps = ceilf(float(2 * M_PI) * radius / (TERRAIN_TILE_SIZE / 3.f));
size_t numSteps = ceilf(2.f * std::numbers::pi_v<float> * radius / (TERRAIN_TILE_SIZE / 3.f));
for (size_t i = 0; i < numSteps; ++i)
{
float angle = i * float(2 * M_PI) / numSteps;
float angle = i * 2.f * std::numbers::pi_v<float> / numSteps;
float px = origin.X + radius * sinf(angle);
float pz = origin.Y + radius * cosf(angle);

View file

@ -51,6 +51,7 @@
#include <cmath>
#include <cstddef>
#include <mutex>
#include <numbers>
#include <queue>
namespace
@ -975,7 +976,8 @@ void VertexPathfinderDebugOverlay::DebugRenderGraph(const CSimContext& simContex
m_DebugOverlayShortPathLines.back(), true);
else
SimRender::ConstructClosedArcOnGround(simContext, x, z, 0.5f,
a0 * ((float)M_PI*2.0f), a1 * ((float)M_PI*2.0f),
a0 * (2.0f * std::numbers::pi_v<float>),
a1 * (2.0f * std::numbers::pi_v<float>),
m_DebugOverlayShortPathLines.back(), true);
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -54,6 +54,7 @@ extern CGame *g_Game;
#include <AL/al.h>
#include <cmath>
#include <numbers>
#include <utility>
constexpr ALfloat DEFAULT_ROLLOFF = 0.5f;
@ -123,7 +124,7 @@ void CSoundGroup::SetDefaultValues()
m_MinDist = CConfigDB::GetIfInitialised("sound.mindistance", 1.f);
m_MaxDist = CConfigDB::GetIfInitialised("sound.maxdistance", 350.f);
// This is more than the default camera FOV: for now, our soundscape is not realistic anyways.
m_MaxStereoAngle = CConfigDB::GetIfInitialised("sound.maxstereoangle", static_cast<float>(M_PI / 6));
m_MaxStereoAngle = CConfigDB::GetIfInitialised("sound.maxstereoangle", std::numbers::pi_v<float> / 6.f);
}
CSoundGroup::CSoundGroup()

View file

@ -32,6 +32,7 @@
#include <cmath>
#include <cstddef>
#include <list>
#include <numbers>
#include <string>
#include <vector>
#include <wx/arrstr.h>
@ -267,7 +268,7 @@ EnvironmentSidebar::EnvironmentSidebar(
waterSizer->Add(new VariableSliderBox(
waterBox, _("Water murkiness"), g_EnvironmentSettings.watermurkiness, 0.f, 1.f), wxSizerFlags().Expand());
waterSizer->Add(new VariableSliderBox(
waterBox, _("Wind angle"), g_EnvironmentSettings.windangle, -static_cast<float>(M_PI), static_cast<float>(M_PI)), wxSizerFlags().Expand());
waterBox, _("Wind angle"), g_EnvironmentSettings.windangle, -std::numbers::pi_v<float>, std::numbers::pi_v<float>), wxSizerFlags().Expand());
waterSizer->Add(new VariableColorBox(
waterBox, _("Water color"), g_EnvironmentSettings.watercolor), wxSizerFlags().Expand());
waterSizer->Add(new VariableColorBox(
@ -286,9 +287,9 @@ EnvironmentSidebar::EnvironmentSidebar(
sunBoxSizer->Add(sunSizer, wxSizerFlags().Expand().Border(wxALL, 5));
sunSizer->Add(new VariableSliderBox(
sunBox, _("Sun rotation"), g_EnvironmentSettings.sunrotation, -static_cast<float>(M_PI), static_cast<float>(M_PI)), wxSizerFlags().Expand());
sunBox, _("Sun rotation"), g_EnvironmentSettings.sunrotation, -std::numbers::pi_v<float>, std::numbers::pi_v<float>), wxSizerFlags().Expand());
sunSizer->Add(new VariableSliderBox(
sunBox, _("Sun elevation"), g_EnvironmentSettings.sunelevation, -static_cast<float>(M_PI) / 2.0f, static_cast<float>(M_PI) / 2.0f), wxSizerFlags().Expand());
sunBox, _("Sun elevation"), g_EnvironmentSettings.sunelevation, -std::numbers::pi_v<float> / 2.0f, std::numbers::pi_v<float> / 2.0f), wxSizerFlags().Expand());
sunSizer->Add(new VariableSliderBox(
sunBox, _("Sun overbrightness"), g_EnvironmentSettings.sunoverbrightness, 1.0f, 3.0f), wxSizerFlags().Expand());
sunSizer->Add(new LightControl(

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -29,6 +29,7 @@
#include <algorithm>
#include <cmath>
#include <list>
#include <numbers>
#include <vector>
#include <wx/defs.h>
#include <wx/event.h>
@ -56,7 +57,7 @@ class ActorViewerTool : public StateDrivenTool<ActorViewerTool>
public:
ActorViewerTool() :
m_Distance(20.f), m_Angle(0.f), m_Elevation((float)M_PI / 6.f),
m_Distance(20.f), m_Angle(0.f), m_Elevation(std::numbers::pi_v<float> / 6.f),
m_LastIsValid(false)
{
}
@ -132,12 +133,12 @@ public:
obj->m_LastX = evt.GetX();
obj->m_LastY = evt.GetY();
obj->m_Angle += dx * M_PI/256.f * ScenarioEditor::GetSpeedModifier();
obj->m_Angle += dx * std::numbers::pi_v<float> / 256.f * ScenarioEditor::GetSpeedModifier();
if (evt.ButtonIsDown(wxMOUSE_BTN_LEFT))
obj->m_Distance += dy / 8.f * ScenarioEditor::GetSpeedModifier();
else // evt.ButtonIsDown(wxMOUSE_BTN_RIGHT))
obj->m_Elevation += dy * M_PI/256.f * ScenarioEditor::GetSpeedModifier();
obj->m_Elevation += dy * std::numbers::pi_v<float> / 256.f * ScenarioEditor::GetSpeedModifier();
camera_changed = true;
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -28,6 +28,7 @@
#include <cmath>
#include <ctime>
#include <list>
#include <numbers>
#include <random>
#include <string>
#include <wx/chartype.h>
@ -39,7 +40,7 @@
using AtlasMessage::Position;
static float g_DefaultAngle = (float)(M_PI*3.0/4.0);
static float g_DefaultAngle = std::numbers::pi_v<float> * 3.f / 4.f;
class PlaceObject : public StateDrivenTool<PlaceObject>
{
@ -150,7 +151,7 @@ public:
{
if (m_RotationDirection)
{
float speed = M_PI/2.f * ScenarioEditor::GetSpeedModifier(); // radians per second
float speed = std::numbers::pi_v<float> / 2.f * ScenarioEditor::GetSpeedModifier(); // radians per second
g_DefaultAngle += (m_RotationDirection * dt * speed);
SendObjectMsg(true);
}

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2025 Wildfire Games.
/* Copyright (C) 2026 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -42,6 +42,7 @@
#include "tools/atlas/GameInterface/SharedTypes.h"
#include <cmath>
#include <numbers>
#include <string>
#include <vector>
@ -69,8 +70,8 @@ sEnvironmentSettings GetSettings()
#undef COLOR
float sunrotation = g_LightEnv.GetRotation();
if (sunrotation > (float)M_PI)
sunrotation -= (float)M_PI*2;
if (sunrotation > std::numbers::pi_v<float>)
sunrotation -= 2.f * std::numbers::pi_v<float>;
s.sunrotation = sunrotation;
s.sunelevation = g_LightEnv.GetElevation();