From 68c7ad1fe674c9c32765401340001fb77918be6e Mon Sep 17 00:00:00 2001 From: ac-stef Date: Fri, 28 Apr 2017 15:18:00 +0200 Subject: [PATCH] cleanup pi use only one constant for Pi, in case we ever need to change it --- source/src/bot/bot_util.cpp | 7 +++-- source/src/entities.cpp | 2 +- source/src/hudgun.h | 4 +-- source/src/rendergl.cpp | 2 +- source/src/renderhud.cpp | 10 ++++---- source/src/rendermodel.cpp | 51 ------------------------------------- source/src/tools.h | 15 ++++------- source/src/water.cpp | 4 +-- source/src/weapon.cpp | 4 +-- 9 files changed, 21 insertions(+), 78 deletions(-) diff --git a/source/src/bot/bot_util.cpp b/source/src/bot/bot_util.cpp index 8d34eec9..233a4329 100644 --- a/source/src/bot/bot_util.cpp +++ b/source/src/bot/bot_util.cpp @@ -102,7 +102,6 @@ float RandomFloat (float from, float to) void AnglesToVectors(vec angles, vec &forward, vec &right, vec &up) { - static float degrees_to_radians = 2 * PI / 360; float angle; float sin_pitch; float sin_yaw; @@ -117,17 +116,17 @@ void AnglesToVectors(vec angles, vec &forward, vec &right, vec &up) angles.y -= 90; // compute the sin and cosine of the pitch component - angle = angles.x * degrees_to_radians; + angle = angles.x * RAD; sin_pitch = sinf (angle); cos_pitch = cosf (angle); // compute the sin and cosine of the yaw component - angle = angles.y * degrees_to_radians; + angle = angles.y * RAD; sin_yaw = sinf (angle); cos_yaw = cosf (angle); // compute the sin and cosine of the roll component - angle = angles.z * degrees_to_radians; + angle = angles.z * RAD; sin_roll = sinf (angle); cos_roll = cosf (angle); diff --git a/source/src/entities.cpp b/source/src/entities.cpp index 8e58696e..b51fdfb0 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -164,7 +164,7 @@ void renderentarrow(const entity &e, const vec &dir, float radius) loopi(5) { vec p(spoke); - p.rotate(2*M_PI*i/4.0f, dir); + p.rotate(PI2 * i / 4.0f, dir); p.add(arrowbase); glVertex3fv(p.v); } diff --git a/source/src/hudgun.h b/source/src/hudgun.h index b2c29063..3056b8b8 100644 --- a/source/src/hudgun.h +++ b/source/src/hudgun.h @@ -41,7 +41,7 @@ struct weaponmove anim = ANIM_GUN_RELOAD; basetime = p->weaponchanging; float progress = clamp((lastmillis - p->weaponchanging)/(float)weapon::weaponchangetime, 0.0f, 1.0f); - k_rot = -90*sinf(progress*M_PI); + k_rot = -90*sinf(progress*PI); } else if(p->weaponsel->reloading) { @@ -49,7 +49,7 @@ struct weaponmove basetime = p->weaponsel->reloading; float reloadtime = (float)p->weaponsel->info.reloadtime, progress = clamp((lastmillis - p->weaponsel->reloading)/reloadtime, 0.0f, clamp(1.0f - (p->lastaction + p->weaponsel->gunwait - lastmillis)/reloadtime, 0.5f, 1.0f)); - k_rot = -90*sinf(progress*M_PI); + k_rot = -90*sinf(progress*PI); } else { diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index c0792c15..ec2650e9 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -280,7 +280,7 @@ void circle(GLuint tex, float x, float y, float r, float tx, float ty, float tr, glVertex2f(x, y); loopi(subdiv+1) { - float c = cosf(2*M_PI*i/float(subdiv)), s = sinf(2*M_PI*i/float(subdiv)); + float c = cosf(PI2 * i / float(subdiv)), s = sinf(PI2 * i / float(subdiv)); glTexCoord2f(tx + tr*c, ty + tr*s); glVertex2f(x + r*c, y + r*s); } diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index 6f9dc097..ee6759a5 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -114,7 +114,7 @@ void drawscope(bool preload) glVertex2f(x1 + 0.5f*sz, y1 + 0.5f*sz); loopi(8+1) { - float c = 0.5f*(1 + border*cosf(i*2*M_PI/8.0f)), s = 0.5f*(1 + border*sinf(i*2*M_PI/8.0f)); + float c = 0.5f*(1 + border*cosf(i*PI2/8.0f)), s = 0.5f*(1 + border*sinf(i*PI2/8.0f)); glTexCoord2f(c, s); glVertex2f(x1 + c*sz, y1 + s*sz); } @@ -126,7 +126,7 @@ void drawscope(bool preload) glBegin(GL_TRIANGLE_STRIP); loopi(8+1) { - float c = 0.5f*(1 + border*cosf(i*2*M_PI/8.0f)), s = 0.5f*(1 + border*sinf(i*2*M_PI/8.0f)); + float c = 0.5f*(1 + border*cosf(i*PI2/8.0f)), s = 0.5f*(1 + border*sinf(i*PI2/8.0f)); glTexCoord2f(c, s); glVertex2f(x1 + c*sz, y1 + s*sz); c = c < 0.4f ? 0 : (c > 0.6f ? 1 : 0.5f); @@ -628,7 +628,7 @@ void drawradar_vicinity(playerent *p, int w, int h) { cpos.mul(scaled); float flgoff=radarentsize/0.68f; - float ryaw=(camera1->yaw-45)*(2*PI/360); + float ryaw=(camera1->yaw-45)*RAD; float offx=flgoff*cosf(-ryaw); float offy=flgoff*sinf(-ryaw); drawradarent(cpos.x+offx, cpos.y-offy, camera1->yaw, 3, m_ktf ? 2 : f.team, iconsize, false); // draw flag on entity pos or whereever dropped @@ -1155,7 +1155,7 @@ static void bar(float bar, int o, float r, float g, float b) glBegin(GL_TRIANGLE_STRIP); loopk(10) { - float c = 1.2f*cosf(M_PI/2 + k/9.0f*M_PI), s = 1 + 1.2f*sinf(M_PI/2 + k/9.0f*M_PI); + float c = 1.2f*cosf(PI/2 + k/9.0f*PI), s = 1 + 1.2f*sinf(PI/2 + k/9.0f*PI); glVertex2f(x2 - c*FONTH, y1 + s*FONTH); glVertex2f(x1 + c*FONTH, y1 + s*FONTH); } @@ -1165,7 +1165,7 @@ static void bar(float bar, int o, float r, float g, float b) glBegin(GL_TRIANGLE_STRIP); loopk(10) { - float c = cosf(M_PI/2 + k/9.0f*M_PI), s = 1 + sinf(M_PI/2 + k/9.0f*M_PI); + float c = cosf(PI/2 + k/9.0f*PI), s = 1 + sinf(PI/2 + k/9.0f*PI); glVertex2f(x2 - c*FONTH, y1 + s*FONTH); glVertex2f(x1 + c*FONTH, y1 + s*FONTH); } diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index ebf7147e..5fa0dac5 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -963,57 +963,6 @@ bool preload_mapmodels(bool trydl) return !missing; } -inline void renderhboxpart(playerent *d, vec top, vec bottom, vec up) -{ - if(d->state==CS_ALIVE && d->head.x >= 0) - { - glBegin(GL_LINE_LOOP); - loopi(8) - { - vec pos(camright); - pos.rotate(2*M_PI*i/8.0f, camdir).mul(HEADSIZE).add(d->head); - glVertex3fv(pos.v); - } - glEnd(); - - glBegin(GL_LINES); - glVertex3fv(bottom.v); - glVertex3fv(d->head.v); - glEnd(); - } - - vec spoke; - spoke.orthogonal(up); - spoke.normalize().mul(d->radius); - - glBegin(GL_LINE_LOOP); - loopi(8) - { - vec pos(spoke); - pos.rotate(2*M_PI*i/8.0f, up).add(top); - glVertex3fv(pos.v); - } - glEnd(); - glBegin(GL_LINE_LOOP); - loopi(8) - { - vec pos(spoke); - pos.rotate(2*M_PI*i/8.0f, up).add(bottom); - glVertex3fv(pos.v); - } - glEnd(); - glBegin(GL_LINES); - loopi(8) - { - vec pos(spoke); - pos.rotate(2*M_PI*i/8.0f, up).add(bottom); - glVertex3fv(pos.v); - pos.sub(bottom).add(top); - glVertex3fv(pos.v); - } - glEnd(); -} - void renderclient(playerent *d, const char *mdlname, const char *vwepname, int tex) { int varseed = (int)(size_t)d; diff --git a/source/src/tools.h b/source/src/tools.h index 7fabb537..c902703a 100644 --- a/source/src/tools.h +++ b/source/src/tools.h @@ -76,18 +76,13 @@ inline int iabs(int n) { return labs(n); } #define DELETEP(p) if(p) { delete p; p = 0; } #define DELETEA(p) if(p) { delete[] p; p = 0; } -#define PI (3.1415927f) -#define PI2 (2*PI) -#define SQRT2 (1.4142136f) -#define SQRT3 (1.7320508f) -#define RAD (PI / 180.0f) +#define PI (3.141592654f) +#define PI2 (6.283185307f) /* 2 * PI */ +#define SQRT2 (1.414213562f) +#define SQRT3 (1.732050808f) +#define RAD (0.01745329252f) /* PI / 180 */ #ifdef WIN32 -#ifdef M_PI -#undef M_PI -#endif -#define M_PI 3.14159265 - #ifndef __GNUC__ #pragma warning (3: 4189) // local variable is initialized but not referenced #pragma warning (disable: 4244) // conversion from 'int' to 'float', possible loss of data diff --git a/source/src/water.cpp b/source/src/water.cpp index 1ad1ec9c..edd7efbb 100644 --- a/source/src/water.cpp +++ b/source/src/water.cpp @@ -69,7 +69,7 @@ COMMAND(setwatercolour, "si"); } \ inline void vertw(float v1, float v2, float v3, float t) \ { \ - float angle = v1*v2*0.1f/(2*M_PI) + t; \ + float angle = v1*v2*0.1f/PI2 + t; \ float s = angle - int(angle) - 0.5f; \ s *= 8 - fabs(s)*16; \ float h = effective_waveheight*0.5f*s; \ @@ -201,7 +201,7 @@ int renderwater(float hf, GLuint reflecttex, GLuint refracttex) wx1 -= wx1%watersubdiv; wy1 -= wy1%watersubdiv; - float t = fmod(float(lastmillis/300.0f/(2*M_PI)), 1.0f); + float t = fmod(float(lastmillis/300.0f/PI2), 1.0f); if(mtwater && maxtmus>=2 && reflecttex) { diff --git a/source/src/weapon.cpp b/source/src/weapon.cpp index f8c1f3eb..c56a02d5 100644 --- a/source/src/weapon.cpp +++ b/source/src/weapon.cpp @@ -182,7 +182,7 @@ void createrays(const vec &from, const vec &to) // create random spread of rays case 2: default: base = SGCCbase / 100.0f; wrange = SGCCrange; break; } - float rnddir = rndscale(2*M_PI); + float rnddir = rndscale(PI2); loopi(SGRAYS) { int j = k * SGRAYS + i; @@ -192,7 +192,7 @@ void createrays(const vec &from, const vec &to) // create random spread of rays float veclen = base + rndmul/100.0f; p.mul(veclen); - p.rotate(2 * M_PI / SGRAYS * i + rnddir, dir); + p.rotate(PI2 / SGRAYS * i + rnddir, dir); vec rray = vec(to); rray.add(p); sgr[j].rv = rray;