1
0
forked from 0ad/0ad

move M_PI etc. to wposix.h to ensure they're always present on Windows (previously required MathUtil.h)

use M_PI instead of nonstandard PI

This was SVN commit r7380.
This commit is contained in:
janwas 2010-03-20 20:54:03 +00:00
parent d1c5119694
commit 0bbb99c3cd
19 changed files with 76 additions and 78 deletions

View File

@ -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--;

View File

@ -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;

View File

@ -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);

View File

@ -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");

View File

@ -68,4 +68,23 @@ LIB_API int setenv(const char* envname, const char* envval, int overwrite);
LIB_API long sysconf(int name);
//
// <math.h>
//
// (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
#ifndef NAN
#define NAN (std::numeric_limits<float>::quiet_NaN())
#endif
#endif // #ifndef INCLUDED_WPOSIX

View File

@ -18,29 +18,8 @@
#ifndef INCLUDED_MATHUTIL
#define INCLUDED_MATHUTIL
// C99 math constants (missing on MSVC):
#ifndef INFINITY
#define INFINITY (std::numeric_limits<float>::infinity())
#endif
#ifndef NAN
#define NAN (std::numeric_limits<float>::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 <typename T>

View File

@ -54,7 +54,7 @@ Noise2D::Noise2D(int f)
grads[i] = new CVector2D_Maths[freq];
for(int j=0; j<freq; j++)
{
float a = randFloat() * 2 * PI;
float a = randFloat() * 2 * M_PI;
grads[i][j] = CVector2D_Maths(cos(a), sin(a));
}
}

View File

@ -132,13 +132,13 @@ CVector3D CQuaternion::ToEulerAngles()
if (test > (.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

View File

@ -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 );
*/

View File

@ -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 );

View File

@ -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 );

View File

@ -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<CStr8>& actorSelections, const CStrW* building )
{
@ -235,7 +235,7 @@ void CEntity::initAuraData()
for ( int j=0; j<AURA_CIRCLE_POINTS; ++j )
{
float val = j * 2*PI / (float)AURA_CIRCLE_POINTS;
float val = j * 2*M_PI / (float)AURA_CIRCLE_POINTS;
m_unsnappedPoints[i][j] = CVector2D( cosf(val)*radius,
sinf(val)*radius );
}
@ -460,14 +460,14 @@ void CEntity::Update( int timestep )
// Calculate smoothed rotation: rotate around Y by at most MAX_ROTATION_RATE per second
float delta = m_orientation.Y - m_orientation_smoothed.Y;
// 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, -MAX_ROTATION_RATE*timestep/1000.f, +MAX_ROTATION_RATE*timestep/1000.f);
// 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)
float newY = m_orientation.Y + deltaClamped - delta;
// Apply the smoothed rotation
m_orientation_smoothed = CVector3D(
@ -1039,24 +1039,24 @@ void CEntity::Interpolate( float relativeoffset )
// Avoid wraparound glitches for interpolating angles.
m_orientation.X = fmodf(m_orientation.X, 2*PI); // (ensure the following loops can't take forever)
m_orientation.Y = fmodf(m_orientation.Y, 2*PI);
m_orientation.Z = fmodf(m_orientation.Z, 2*PI);
m_orientation.X = fmodf(m_orientation.X, 2*M_PI); // (ensure the following loops can't take forever)
m_orientation.Y = fmodf(m_orientation.Y, 2*M_PI);
m_orientation.Z = fmodf(m_orientation.Z, 2*M_PI);
while( m_orientation.Y < m_orientation_previous.Y - PI )
m_orientation_previous.Y -= 2 * PI;
while( m_orientation.Y > 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();

View File

@ -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

View File

@ -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 )
{

View File

@ -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;
}

View File

@ -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;

View File

@ -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();

View File

@ -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();

View File

@ -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);