Skip to content

Commit

Permalink
Use our DEG2RAD and DEG2RADf macros instead of dividing M_PI by 180.
Browse files Browse the repository at this point in the history
  • Loading branch information
JMakey committed Jun 28, 2015
1 parent 467ba23 commit a3cfdcb
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 47 deletions.
2 changes: 1 addition & 1 deletion include/vectors.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class vec3 {
}
vec3 normalize() const { vec3 v(*this); normalize(v); return v; }

static T toRadians(T value) {return value * (T)(M_PI/180.0);}
static T toRadians(T value) {return value * (T)(DEG2RAD);}

vec3 rotateX(T radians) const {
const T cv = typed_cos(radians);
Expand Down
4 changes: 2 additions & 2 deletions src/bzflag/BackgroundRenderer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ void BackgroundRenderer::makeCelestialLists(const SceneRenderer& renderer)
coverage = (coverage < 0.0f) ? -sqrtf(-coverage) : coverage * coverage;
float worldSize = BZDBCache::worldSize;
const float moonRadius = 2.0f * worldSize *
atanf((float)((60.0 * M_PI / 180.0) / 60.0));
atanf((float)((60.0 * DEG2RAD) / 60.0));
// limbAngle is dependent on moon position but sun is so much farther
// away that the moon's position is negligible. rotate sun and moon
// so that moon is on the horizon in the +x direction, then compute
Expand Down Expand Up @@ -1600,7 +1600,7 @@ void BackgroundRenderer::doInitDisplayLists()
// sun first. sun is a disk that should be about a half a degree wide
// with a normal (60 degree) perspective.
const float worldSize = BZDBCache::worldSize;
const float sunRadius = (float)(2.0 * worldSize * atanf((float)(60.0*M_PI/180.0)) / 60.0);
const float sunRadius = (float)(2.0 * worldSize * atanf((float)(60.0*DEG2RAD)) / 60.0);
sunList = glGenLists(1);
glNewList(sunList, GL_COMPILE);
{
Expand Down
2 changes: 1 addition & 1 deletion src/bzflag/CommandsImplementation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ bool RoamPosCommand::operator() (const char *commandLine)
} else {
const float degrees = parseFloatExpr(tokens[0], true);
const float ws = BZDB.eval(StateDatabase::BZDB_WORLDSIZE);
const float radians = degrees * ((float)M_PI/180.0f);
const float radians = degrees * DEG2RADf;
cam.pos[0] = cosf(radians)* 0.5f * ws * (float)M_SQRT2;
cam.pos[1] = sinf(radians)* 0.5f * ws * (float)M_SQRT2;
cam.pos[2] = +0.25f * ws;
Expand Down
6 changes: 3 additions & 3 deletions src/bzflag/Roaming.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ void Roaming::updatePosition(RoamingCamera* dc, float dt) {

// modify X and Y coords
if (!tracking) {
const float c = cosf(camera.theta * (float)(M_PI / 180.0f));
const float s = sinf(camera.theta * (float)(M_PI / 180.0f));
const float c = cosf(camera.theta * DEG2RADf);
const float s = sinf(camera.theta * DEG2RADf);
camera.pos[0] += dt * (c * dc->pos[0] - s * dc->pos[1]);
camera.pos[1] += dt * (c * dc->pos[1] + s * dc->pos[0]);
camera.theta += dt * dc->theta;
Expand Down Expand Up @@ -378,7 +378,7 @@ void Roaming::updatePosition(RoamingCamera* dc, float dt) {
dy = dy * scale;
if (fabsf(dx) < 0.001f) dx = 0.001f;
if (fabsf(dy) < 0.001f) dy = 0.001f;
const float dtheta = -(dt * dc->theta * (float)(M_PI / 180.0f));
const float dtheta = -(dt * dc->theta * DEG2RADf);
const float c = cosf(dtheta);
const float s = sinf(dtheta);
camera.pos[0] = trackPos[0] + ((c * dx) - (s * dy));
Expand Down
2 changes: 1 addition & 1 deletion src/bzflag/TrackMarks.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ static void updateList(TrackList& list, float dt)
// cull the track marks if they aren't supported
float markPos[3];
markPos[2] = te.pos[2] - TextureHeightOffset;
const float radians = (float)(te.angle * (M_PI / 180.0));
const float radians = te.angle * DEG2RADf;
const float dx = -sinf(radians) * TreadMiddle;
const float dy = +cosf(radians) * TreadMiddle;
// left tread
Expand Down
14 changes: 7 additions & 7 deletions src/bzflag/daylight.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "StateDatabase.h"
#include "ParseColor.h"

static const double radPerDeg = M_PI / 180.0;
static const double radPerDeg = DEG2RAD;
static const double radPerHour = M_PI / 12.0;
static const double siderealHoursPerHour = 1.002737908;
static const double epoch = 2415020.0;
Expand Down Expand Up @@ -49,7 +49,7 @@ static void gettruePosition(double julianDay,
{
// get local sidereal time
const float localSidereal = (float)(getGreenwichSideral(julianDay) -
longitude * M_PI / 180.0);
longitude * DEG2RAD);

// rotate around polar axis (y-axis) by local sidereal time
float tx = float(sx * cosf(localSidereal) - sz * sinf(localSidereal));
Expand All @@ -58,8 +58,8 @@ static void gettruePosition(double julianDay,

// rotate by latitude to local position
pos[0] = tx;
pos[1] = ty * cosf((float)(latitude*M_PI/180.0)) - tz * sinf((float)(latitude*M_PI/180.0));
pos[2] = tz * cosf((float)(latitude*M_PI/180.0)) + ty * sinf((float)(latitude*M_PI/180.0));
pos[1] = ty * cosf(latitude * DEG2RADf) - tz * sinf(latitude * DEG2RADf);
pos[2] = tz * cosf(latitude * DEG2RADf) + ty * sinf(latitude * DEG2RADf);
}

void getCelestialTransform(double julianDay,
Expand All @@ -68,7 +68,7 @@ void getCelestialTransform(double julianDay,
{
// get local sidereal time
const float localSidereal = (float)(getGreenwichSideral(julianDay) -
longitude * M_PI / 180.0);
longitude * DEG2RAD);

// localSidereal is the amount the celestial sphere should be
// rotated from the vernal equinox about the celestial axis.
Expand All @@ -79,8 +79,8 @@ void getCelestialTransform(double julianDay,
// north.
const float cls = cosf(localSidereal);
const float sls = sinf(localSidereal);
const float cla = cosf((float)(latitude * M_PI / 180.0));
const float sla = sinf((float)(latitude * M_PI / 180.0));
const float cla = cosf(latitude * DEG2RADf);
const float sla = sinf(latitude * DEG2RADf);

// constant stuff
xform[0][3] = xform[1][3] = xform[2][3] = 0.0f;
Expand Down
20 changes: 10 additions & 10 deletions src/bzflag/playing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -4988,7 +4988,7 @@ void leaveGame()
targetPoint[0] = eyePoint[0] - 1.0f;
targetPoint[1] = eyePoint[1] + 0.0f;
targetPoint[2] = eyePoint[2] + 0.0f;
sceneRenderer->getViewFrustum().setProjection((float)(60.0 * M_PI / 180.0),
sceneRenderer->getViewFrustum().setProjection(60.0f * DEG2RADf,
NearPlaneNormal,
FarPlaneDefault,
FarDeepPlaneDefault,
Expand Down Expand Up @@ -5532,7 +5532,7 @@ void drawFrame(const float dt)
fov *= 0.75f;
}
}
fov *= (float)(M_PI / 180.0);
fov *= DEG2RADf;

// set projection and view
eyePoint[0] = myTankPos[0];
Expand Down Expand Up @@ -5625,9 +5625,9 @@ void drawFrame(const float dt)
// free Roaming
else {
float dir[3];
dir[0] = cosf((float)(roam->phi * M_PI / 180.0)) * cosf((float)(roam->theta * M_PI / 180.0));
dir[1] = cosf((float)(roam->phi * M_PI / 180.0)) * sinf((float)(roam->theta * M_PI / 180.0));
dir[2] = sinf((float)(roam->phi * M_PI / 180.0));
dir[0] = cosf(roam->phi * DEG2RADf) * cosf(roam->theta * DEG2RADf);
dir[1] = cosf(roam->phi * DEG2RADf) * sinf(roam->theta * DEG2RADf);
dir[2] = sinf(roam->phi * DEG2RADf);
eyePoint[0] = roam->pos[0];
eyePoint[1] = roam->pos[1];
eyePoint[2] = roam->pos[2];
Expand All @@ -5639,10 +5639,10 @@ void drawFrame(const float dt)
if (!devDriving) {
float virtPos[] = {eyePoint[0], eyePoint[1], 0};
if (myTank) {
myTank->move(virtPos, (float)(roamViewAngle * M_PI / 180.0));
myTank->move(virtPos, roamViewAngle * DEG2RADf);
}
}
fov = (float)(roam->zoom * M_PI / 180.0);
fov = roam->zoom * DEG2RADf;
moveSoundReceiver(eyePoint[0], eyePoint[1], eyePoint[2], 0.0, false);
}

Expand Down Expand Up @@ -6111,8 +6111,8 @@ static void roamSmoothFollow(Roaming::RoamingCamera& deltaCamera)
};

const float theta = ROAM.getCamera()->theta;
const float c = cosf(theta * (float)(M_PI / 180.0f));
const float s = sinf(theta * (float)(M_PI / 180.0f));
const float c = cosf(theta * DEG2RADf);
const float s = sinf(theta * DEG2RADf);
const float f[2] = { +c, +s };
const float r[2] = { +s, -c };

Expand Down Expand Up @@ -7042,7 +7042,7 @@ static void findFastConfiguration()
float muzzleHeight = BZDB.eval(StateDatabase::BZDB_MUZZLEHEIGHT);
static const GLfloat eyePoint[3] = { 0.0f, 0.0f, muzzleHeight };
static const GLfloat targetPoint[3] = { 0.0f, 10.0f, muzzleHeight };
sceneRenderer->getViewFrustum().setProjection((float)(45.0 * M_PI / 180.0),
sceneRenderer->getViewFrustum().setProjection(45.0f * DEG2RADf,
NearPlaneNormal,
FarPlaneDefault,
FarDeepPlaneDefault,
Expand Down
2 changes: 1 addition & 1 deletion src/bzfs/CustomWeapon.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ bool CustomWeapon::read(const char *cmd, std::istream& input) {
std::cout << "weapon tilt requires a value" << std::endl;
}
// convert to radians
tilt = (float)(tilt * (M_PI / 180.0));
tilt *= DEG2RADf;
}
else if (strcmp(cmd, "trigger") == 0) {
std::string triggerName;
Expand Down
2 changes: 1 addition & 1 deletion src/bzfs/WorldFileLocation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool WorldFileLocation::read(const char *cmd, std::istream& input)
return false;
}
// convert to radians
rotation = (float)(rotation * (M_PI / 180.0));
rotation *= DEG2RADf;
}

//
Expand Down
10 changes: 4 additions & 6 deletions src/bzfs/bzfs.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1010,9 +1010,7 @@ void makeWalls ( void )
double startAngle = -angleDelta*0.5;
double radius = sqrt(halfSize*halfSize + halfSize*halfSize);

float degToRad = (float)(M_PI/180.0);

double segmentLen = (sin(angleDelta*0.5*(degToRad)) * radius)*2;
double segmentLen = (sin(angleDelta*0.5*DEG2RAD) * radius)*2;

if(0)
{
Expand All @@ -1021,10 +1019,10 @@ void makeWalls ( void )
float midpointRad = sqrtf((float)radius*(float)radius-((float)segmentLen*0.5f)*((float)segmentLen*0.5f));
float midpointAngle = (float)startAngle + ((float)angleDelta*0.5f) + ((float)angleDelta*w);

float x = sinf(midpointAngle*degToRad)*midpointRad;
float y = cosf(midpointAngle*degToRad)*midpointRad;
float x = sinf(midpointAngle*DEG2RADf)*midpointRad;
float y = cosf(midpointAngle*DEG2RADf)*midpointRad;

world->addWall(x, y, 0.0f, (270.0f-midpointAngle)*degToRad, (float)segmentLen, wallHeight);
world->addWall(x, y, 0.0f, (270.0f-midpointAngle)*DEG2RADf, (float)segmentLen, wallHeight);

}
}
Expand Down
2 changes: 1 addition & 1 deletion src/game/MeshTransform.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ void MeshTransform::addShear(const float shear[3])

void MeshTransform::addSpin(const float degrees, const float normal[3])
{
const float radians = (float)(degrees * (M_PI / 180.0));
const float radians = degrees * DEG2RADf;
TransformData transform;
memcpy(transform.data, normal, sizeof(float[3]));
transform.data[3] = radians;
Expand Down
2 changes: 1 addition & 1 deletion src/game/TextureMatrix.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ void TextureMatrix::finalize()

if (useStatic) {
// setup the staticMatrix
const float radians = rotation * (float)(M_PI / 180.0);
const float radians = rotation * DEG2RADf;

shift(staticMatrix, -(uFixedShift + uFixedCenter),
-(vFixedShift + vFixedCenter));
Expand Down
4 changes: 2 additions & 2 deletions src/geometry/FlagSceneNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ void FlagSceneNode::setWind(const GLfloat wind[3], float dt)
hscl = 1.0f;
} else {
// the angle points from the end of the flag to the pole
const float cos_val = cosf(angle * (float)(M_PI / 180.0f));
const float sin_val = sinf(angle * (float)(M_PI / 180.0f));
const float cos_val = cosf(angle * DEG2RADf);
const float sin_val = sinf(angle * DEG2RADf);
const float force = (wind[0] * sin_val) - (wind[1] * cos_val);
const float angleScale = 25.0f;
angle = fmodf(angle + (force * dt * angleScale), 360.0f);
Expand Down
8 changes: 4 additions & 4 deletions src/geometry/TankSceneNode.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void TankSceneNode::addRenderNodes(SceneRenderer& renderer)
const GLfloat* eye = view.getEye();
GLfloat dx = eye[0] - mySphere[0];
GLfloat dy = eye[1] - mySphere[1];
const float radians = (float)(azimuth * M_PI / 180.0);
const float radians = (float)(azimuth * DEG2RAD);
const float cos_val = cosf(radians);
const float sin_val = sinf(radians);

Expand Down Expand Up @@ -399,7 +399,7 @@ void TankSceneNode::setJumpJets(float scale)

// set the jet ground-light and model positions
for (int i = 0; i < 4; i++) {
const float radians = (float)(azimuth * (M_PI / 180.0));
const float radians = (float)(azimuth * DEG2RAD);
const float cos_val = cosf(radians);
const float sin_val = sinf(radians);
const float* scaleFactor = TankGeometryMgr::getScaleFactor(tankSize);
Expand Down Expand Up @@ -732,8 +732,8 @@ void TankIDLSceneNode::IDLRenderNode::render()
const GLfloat* sphere = sceneNode->tank->getSphere();
const GLfloat* _plane = sceneNode->plane;
const GLfloat azimuth = sceneNode->tank->azimuth;
const GLfloat ca = cosf(-azimuth * (float)M_PI / 180.0f);
const GLfloat sa = sinf(-azimuth * (float)M_PI / 180.0f);
const GLfloat ca = cosf(-azimuth * DEG2RAD);
const GLfloat sa = sinf(-azimuth * DEG2RAD);
GLfloat tankPlane[4];
tankPlane[0] = ca * _plane[0] - sa * _plane[1];
tankPlane[1] = sa * _plane[0] + ca * _plane[1];
Expand Down
2 changes: 1 addition & 1 deletion src/obstacle/ArcObstacle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ MeshObstacle* ArcObstacle::makeMesh()
if (a < -360.0f) {
a = -360.0f;
}
a = a * (float)(M_PI / 180.0); // convert to radians
a *= DEG2RADf; // convert to radians
if (a < 0.0f) {
r = r + a;
a = -a;
Expand Down
2 changes: 1 addition & 1 deletion src/obstacle/ConeObstacle.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ MeshObstacle* ConeObstacle::makeMesh()
if (a < -360.0f) {
a = -360.0f;
}
a = a * (float)(M_PI / 180.0); // convert to radians
a *= DEG2RADf; // convert to radians
if (a < 0.0f) {
r = r + a;
a = -a;
Expand Down
2 changes: 1 addition & 1 deletion src/obstacle/MeshDrawInfo.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ void MeshDrawInfo::updateAnimation(double time)
{
if (animInfo != NULL) {
const float angle = (float)fmod((double)animInfo->angvel * time, 360.0);
const float radians = angle * (float)(M_PI / 180.0);
const float radians = angle * DEG2RADf;
animInfo->angle = angle;
animInfo->cos_val = cosf(radians);
animInfo->sin_val = sinf(radians);
Expand Down
2 changes: 1 addition & 1 deletion src/obstacle/MeshSceneNodeGenerator.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/

#include <math.h>
#include "vectors.h"
#include "MeshSceneNodeGenerator.h"
#include "vectors.h"
#include "MeshObstacle.h"
#include "MeshFace.h"
#include "bzfgl.h"
Expand Down
4 changes: 2 additions & 2 deletions src/platform/DXJoystick.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ void DXJoystick::getJoyHat(int hat, float &hatX, float &hatY)
// can be fed into sinf() and cosf() which start counting from east
float angle = (float)hatPos/100.0f - 90;

hataxes[i * 2] = hatX = cosf(angle * ((float)M_PI/180.0f));
hataxes[i * 2 + 1] = hatY = sinf(angle * ((float)M_PI/180.0f));
hataxes[i * 2] = hatX = cosf(angle * DEG2RADf);
hataxes[i * 2 + 1] = hatY = sinf(angle * DEG2RADf);
}
}

Expand Down

0 comments on commit a3cfdcb

Please sign in to comment.