diff --git a/source/graphics/CinemaTrack.cpp b/source/graphics/CinemaTrack.cpp index 3107ed7257..1be4f6b9bd 100644 --- a/source/graphics/CinemaTrack.cpp +++ b/source/graphics/CinemaTrack.cpp @@ -205,7 +205,7 @@ float CCinemaPath::EaseCircle(float t) const float CCinemaPath::EaseSine(float t) const { - t = 1.0f - cos(t * PI/2); + t = 1.0f - cos(t * M_PI/2); if(m_GrowthCount > 1.0f) { m_GrowthCount--; diff --git a/source/graphics/LightEnv.h b/source/graphics/LightEnv.h index 169dd0fa45..dd23ed3709 100644 --- a/source/graphics/LightEnv.h +++ b/source/graphics/LightEnv.h @@ -40,14 +40,14 @@ friend class CXMLReader; private: /** * m_Elevation: Height of sun above the horizon, in radians. - * For example, an elevation of PI/2 means the sun is straight up. + * For example, an elevation of M_PI/2 means the sun is straight up. */ float m_Elevation; /** * m_Rotation: 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 PI/2 means the sun is in the direction (1,0,0) (not taking + * and a rotation of M_PI/2 means the sun is in the direction (1,0,0) (not taking * elevation into account). */ float m_Rotation; diff --git a/source/graphics/MapReader.cpp b/source/graphics/MapReader.cpp index 5128b96fd5..c176b10166 100644 --- a/source/graphics/MapReader.cpp +++ b/source/graphics/MapReader.cpp @@ -1110,7 +1110,7 @@ int CXMLReader::ReadNonEntities(XMBElement parent, double end_time) if (unit) { CMatrix3D m; - m.SetYRotation(Orientation + PI); + m.SetYRotation(Orientation + M_PI); m.Translate(Position); unit->GetModel()->SetTransform(m); diff --git a/source/graphics/MapWriter.cpp b/source/graphics/MapWriter.cpp index b168191e74..76961b66f9 100644 --- a/source/graphics/MapWriter.cpp +++ b/source/graphics/MapWriter.cpp @@ -265,7 +265,7 @@ void CMapWriter::WriteXML(const VfsPath& filename, CVector3D in = pCamera->m_Orientation.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) - PI/2; + float declination = atan2(sqrt(in.X*in.X + in.Z*in.Z), in.Y) - M_PI/2; { XML_Element("Rotation"); diff --git a/source/lib/sysdep/os/win/wposix/wposix.h b/source/lib/sysdep/os/win/wposix/wposix.h index 352ccf6013..e15c26b4b6 100644 --- a/source/lib/sysdep/os/win/wposix/wposix.h +++ b/source/lib/sysdep/os/win/wposix/wposix.h @@ -68,4 +68,23 @@ LIB_API int setenv(const char* envname, const char* envval, int overwrite); LIB_API long sysconf(int name); + +// +// +// + +// (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::infinity()) +#endif +#ifndef NAN +#define NAN (std::numeric_limits::quiet_NaN()) +#endif + #endif // #ifndef INCLUDED_WPOSIX diff --git a/source/maths/MathUtil.h b/source/maths/MathUtil.h index 3ea54fdc55..f564807ea1 100644 --- a/source/maths/MathUtil.h +++ b/source/maths/MathUtil.h @@ -18,29 +18,8 @@ #ifndef INCLUDED_MATHUTIL #define INCLUDED_MATHUTIL - -// C99 math constants (missing on MSVC): -#ifndef INFINITY -#define INFINITY (std::numeric_limits::infinity()) -#endif -#ifndef NAN -#define NAN (std::numeric_limits::quiet_NaN()) -#endif - -// POSIX math constants (missing on MSVC): -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#ifndef M_PI_2 -#define M_PI_2 1.57079632679489661923 -#endif - -#ifndef PI -#define PI 3.14159265358979323846f -#endif - -#define DEGTORAD(a) ((a) * (PI/180.0f)) -#define RADTODEG(a) ((a) * (180.0f/PI)) +#define DEGTORAD(a) ((a) * (M_PI/180.0f)) +#define RADTODEG(a) ((a) * (180.0f/M_PI)) #define SQR(x) ((x) * (x)) template diff --git a/source/maths/Noise.cpp b/source/maths/Noise.cpp index 89eb6b8547..2701508e77 100644 --- a/source/maths/Noise.cpp +++ b/source/maths/Noise.cpp @@ -54,7 +54,7 @@ Noise2D::Noise2D(int f) grads[i] = new CVector2D_Maths[freq]; for(int j=0; j (.5f-EPSILON)*unit) { // singularity at north pole heading = 2 * atan2( m_V.X, m_W); - attitude = PI/2; + attitude = M_PI/2; bank = 0; } else if (test < (-.5f+EPSILON)*unit) { // singularity at south pole heading = -2 * atan2(m_V.X, m_W); - attitude = -PI/2; + attitude = -M_PI/2; bank = 0; } else diff --git a/source/ps/CStr.h b/source/ps/CStr.h index abac68dd8a..16d31f7702 100644 --- a/source/ps/CStr.h +++ b/source/ps/CStr.h @@ -29,11 +29,11 @@ Examples: In order to use both, most of the standard library functions come in T form. The following shows several examples of traditional ANSI vs UNICODE. // ANSI - LPCSTR str = "PI"; + LPCSTR str = "M_PI"; printf( "%s = %fn", str, 3.1459f ); // UNICODE - LPCWSTR str = L"PI"; + LPCWSTR str = L"M_PI"; wprintf( L"%ls = %fn", str, 3.1459f ); */ diff --git a/source/ps/Interact.cpp b/source/ps/Interact.cpp index c510a5fd7a..3cf6f57dc9 100644 --- a/source/ps/Interact.cpp +++ b/source/ps/Interact.cpp @@ -1371,7 +1371,7 @@ void ResetInteraction() customSelectionMode = false; } -static const float angleBias = 3*PI/4; // Atlas does the same +static const float angleBias = 3*M_PI/4; // Atlas does the same bool CBuildingPlacer::Activate(CStrW& templateName) { @@ -1480,7 +1480,7 @@ void CBuildingPlacer::Update( float timeStep ) if(x*x + z*z < 3*3) { if(m_dragged || m_timeSinceClick > 0.2f) - m_angle += timeStep * PI; + m_angle += timeStep * M_PI; } else { @@ -1517,7 +1517,7 @@ void CBuildingPlacer::Update( float timeStep ) // Set position and angle to the location we decided on CMatrix3D m; - m.SetYRotation(m_angle + PI); + m.SetYRotation(m_angle + M_PI); m.Translate(pos); m_actor->GetModel()->SetTransform( m ); m_bounds->SetPosition(pos.X, pos.Z); @@ -1540,7 +1540,7 @@ void CBuildingPlacer::Update( float timeStep ) } else { - float add = ( sin(4*PI*m_totalTime) + 1.0f ) * 0.08f; + float add = ( sin(4*M_PI*m_totalTime) + 1.0f ) * 0.08f; col = CColor( 1.4f+add, 0.4f+add, 0.4f+add, 1.0f ); } m_actor->GetModel()->SetShadingColor( col ); diff --git a/source/simulation/BoundingObjects.cpp b/source/simulation/BoundingObjects.cpp index 678907aa05..d1a9b460c6 100644 --- a/source/simulation/BoundingObjects.cpp +++ b/source/simulation/BoundingObjects.cpp @@ -96,7 +96,7 @@ void CBoundingCircle::Render( float height ) for( int i = 0; i < 10; i++ ) { - float ang = i * 2 * PI / 10.0f; + float ang = i * 2 * M_PI / 10.0f; float x = m_pos.x + m_radius * sin( ang ); float y = m_pos.y + m_radius * cos( ang ); glVertex3f( x, height, y ); diff --git a/source/simulation/Entity.cpp b/source/simulation/Entity.cpp index 81f9907e7a..910a83c384 100644 --- a/source/simulation/Entity.cpp +++ b/source/simulation/Entity.cpp @@ -53,7 +53,7 @@ #include "ps/GameSetup/Config.h" -const float MAX_ROTATION_RATE = 2*PI; // radians per second +const float MAX_ROTATION_RATE = 2*M_PI; // radians per second CEntity::CEntity( CEntityTemplate* base, CVector3D position, float orientation, const std::set& actorSelections, const CStrW* building ) { @@ -235,7 +235,7 @@ void CEntity::initAuraData() for ( int j=0; j m_orientation_previous.Y + PI ) - m_orientation_previous.Y += 2 * PI; + while( m_orientation.Y < m_orientation_previous.Y - M_PI ) + m_orientation_previous.Y -= 2 * M_PI; + while( m_orientation.Y > m_orientation_previous.Y + M_PI ) + m_orientation_previous.Y += 2 * M_PI; - while( m_orientation.X < m_orientation_previous.X - PI ) - m_orientation_previous.X -= 2 * PI; - while( m_orientation.X > m_orientation_previous.X + PI ) - m_orientation_previous.X += 2 * PI; + while( m_orientation.X < m_orientation_previous.X - M_PI ) + m_orientation_previous.X -= 2 * M_PI; + while( m_orientation.X > m_orientation_previous.X + M_PI ) + m_orientation_previous.X += 2 * M_PI; - while( m_orientation.Z < m_orientation_previous.Z - PI ) - m_orientation_previous.Z -= 2 * PI; - while( m_orientation.Z > m_orientation_previous.Z + PI ) - m_orientation_previous.Z += 2 * PI; + while( m_orientation.Z < m_orientation_previous.Z - M_PI ) + m_orientation_previous.Z -= 2 * M_PI; + while( m_orientation.Z > m_orientation_previous.Z + M_PI ) + m_orientation_previous.Z += 2 * M_PI; UpdateXZOrientation(); diff --git a/source/simulation/EntityRendering.cpp b/source/simulation/EntityRendering.cpp index d8fb8e5ef3..b5412a1f8a 100644 --- a/source/simulation/EntityRendering.cpp +++ b/source/simulation/EntityRendering.cpp @@ -162,7 +162,7 @@ void CEntity::RenderSelectionOutline( float alpha ) float radius = ((CBoundingCircle*)m_bounds)->m_radius; for( int i = 0; i < SELECTION_CIRCLE_POINTS; i++ ) { - float ang = i * 2 * PI / (float)SELECTION_CIRCLE_POINTS; + float ang = i * 2 * M_PI / (float)SELECTION_CIRCLE_POINTS; float x = pos.X + radius * sin( ang ); float y = pos.Z + radius * cos( ang ); #ifdef SELECTION_TERRAIN_CONFORMANCE diff --git a/source/simulation/EntityScriptInterface.cpp b/source/simulation/EntityScriptInterface.cpp index 6df0f7e7cb..5349ddd256 100644 --- a/source/simulation/EntityScriptInterface.cpp +++ b/source/simulation/EntityScriptInterface.cpp @@ -154,7 +154,7 @@ JSBool CEntity::Construct( JSContext* cx, JSObject* UNUSED(obj), uintN argc, jsv debug_assert( argc >= 2 ); CVector3D position; - float orientation = g_Game->GetSimulation()->RandFloat() * 2 * PI; + float orientation = g_Game->GetSimulation()->RandFloat() * 2 * M_PI; JSObject* jsEntityTemplate = JSVAL_TO_OBJECT( argv[0] ); CStrW templateName; @@ -502,10 +502,10 @@ jsval_t CEntity::GetSpawnPoint( JSContext* UNUSED(cx), uintN argc, jsval* argv ) else if( m_bounds->m_type == CBoundingObject::BOUND_CIRCLE ) { float ang; - ang = g_Game->GetSimulation()->RandFloat() * 2 * PI; + ang = g_Game->GetSimulation()->RandFloat() * 2 * M_PI; float radius = m_bounds->m_radius + 1.0f + spawn_clearance; float d_ang = spawn_clearance / ( 2.0f * radius ); - float ang_end = ang + 2.0f * PI; + float ang_end = ang + 2.0f * M_PI; float x = 0.0f, y = 0.0f; // make sure they're initialized for( ; ang < ang_end; ang += d_ang ) { diff --git a/source/simulation/EntityStateProcessing.cpp b/source/simulation/EntityStateProcessing.cpp index 980afa26a9..63cf949671 100644 --- a/source/simulation/EntityStateProcessing.cpp +++ b/source/simulation/EntityStateProcessing.cpp @@ -84,7 +84,7 @@ float CEntity::ChooseMovementSpeed( float distance ) // Modify the speed based on the slope of the terrain in our direction (obtained from our x orientation) float angle = m_orientation_unclamped.x; - int sector = rintf( angle / (PI/2) * m_base->m_pitchDivs ); + int sector = rintf( angle / (M_PI/2) * m_base->m_pitchDivs ); speed -= sector * m_base->m_pitchValue; entf_set_to(ENTF_IS_RUNNING, should_run); @@ -130,8 +130,8 @@ int CEntity::ProcessGotoHelper( CEntityOrder* current, int timestep_millis, HEnt m_targetorientation = atan2( delta.x, delta.y ); float deltatheta = m_targetorientation - (float)m_orientation.Y; - while( deltatheta > PI ) deltatheta -= 2 * PI; - while( deltatheta < -PI ) deltatheta += 2 * PI; + while( deltatheta > M_PI ) deltatheta -= 2 * M_PI; + while( deltatheta < -M_PI ) deltatheta += 2 * M_PI; if( fabs( deltatheta ) > 0.01f ) { @@ -336,7 +336,7 @@ bool CEntity::ProcessGotoNoPathing( CEntityOrder* current, int timestep_millis ) { delta = interval / r; theta += delta; - r += ( interval * delta ) / ( 2 * PI ); + r += ( interval * delta ) / ( 2 * M_PI ); destinationObs.SetPosition( _x + r * cosf( theta ), _y + r * sinf( theta ) ); if( !GetCollisionObject( &destinationObs ) ) break; } diff --git a/source/simulation2/components/CCmpPosition.cpp b/source/simulation2/components/CCmpPosition.cpp index 5eb1dcef85..86974ddd55 100644 --- a/source/simulation2/components/CCmpPosition.cpp +++ b/source/simulation2/components/CCmpPosition.cpp @@ -333,14 +333,14 @@ public: float rotY = m_RotY.ToFloat(); float delta = rotY - m_InterpolatedRotY; - // Wrap delta to -PI..PI - delta = fmod(delta + PI, 2*PI); // range -2PI..2PI - if (delta < 0) delta += 2*PI; // range 0..2PI - delta -= PI; // range -PI..PI + // Wrap delta to -M_PI..M_PI + delta = fmod(delta + M_PI, 2*M_PI); // range -2PI..2PI + if (delta < 0) delta += 2*M_PI; // range 0..2PI + delta -= M_PI; // range -M_PI..M_PI // Clamp to max rate float deltaClamped = clamp(delta, -m_RotYSpeed*msgData.frameTime, +m_RotYSpeed*msgData.frameTime); // Calculate new orientation, in a peculiar way in order to make sure the - // result gets close to m_orientation (rather than being n*2*PI out) + // result gets close to m_orientation (rather than being n*2*M_PI out) m_InterpolatedRotY = rotY + deltaClamped - delta; break; diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index 3204b7cfe5..5067424531 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -184,9 +184,9 @@ void ActorViewer::SetActor(const CStrW& name, const CStrW& animation) if (! m.Unit) return; - float angle = PI; + float angle = M_PI; CMatrix3D mat; - mat.SetYRotation(angle + PI); + mat.SetYRotation(angle + M_PI); mat.Translate(CELL_SIZE * PATCH_SIZE/2, 0.f, CELL_SIZE * PATCH_SIZE/2); m.Unit->GetModel()->SetTransform(mat); m.Unit->GetModel()->ValidatePosition(); diff --git a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp index 8691f7788b..c7d2a61b1a 100644 --- a/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp +++ b/source/tools/atlas/GameInterface/Handlers/EnvironmentHandlers.cpp @@ -50,8 +50,8 @@ sEnvironmentSettings GetSettings() #undef COLOUR float sunrotation = g_LightEnv.GetRotation(); - if (sunrotation > PI) - sunrotation -= PI*2; + if (sunrotation > M_PI) + sunrotation -= M_PI*2; s.sunrotation = sunrotation; s.sunelevation = g_LightEnv.GetElevation(); diff --git a/source/tools/atlas/GameInterface/SimState.cpp b/source/tools/atlas/GameInterface/SimState.cpp index fa33fc4d8e..85dccafaed 100644 --- a/source/tools/atlas/GameInterface/SimState.cpp +++ b/source/tools/atlas/GameInterface/SimState.cpp @@ -85,7 +85,7 @@ CUnit* SimState::Nonentity::Thaw() if (! unit) return NULL; CMatrix3D m; - m.SetYRotation(angle + PI); + m.SetYRotation(angle + M_PI); m.Translate(position); unit->GetModel()->SetTransform(m);