ALL: Eliminate LOCAL_PI macro

This commit is contained in:
Pawel Kolodziejski 2020-09-23 23:20:23 +02:00
parent ada0dd648c
commit 27e12d8a96
22 changed files with 35 additions and 45 deletions

View file

@ -514,7 +514,7 @@ WMACodec::HuffmanDecoder *WMACodec::initCoefHuffman(uint16 *&runTable, float *&l
}
void WMACodec::initLSPToCurve() {
float wdel = M_PI / _frameLen;
float wdel = (float)M_PI / _frameLen;
for (int i = 0; i < _frameLen; i++)
_lspCosTable[i] = 2.0f * cosf(wdel * i);

View file

@ -50,7 +50,7 @@ MDCT::MDCT(int bits, bool inverse, double scale) : _bits(bits), _fft(0) {
scale = sqrt(ABS(scale));
for (int i = 0; i < size4; i++) {
const double alpha = 2 * M_PI * (i + theta) / _size;
const double alpha = 2 * (float)M_PI * (i + theta) / _size;
_tCos[i] = -cos(alpha) * scale;
_tSin[i] = -sin(alpha) * scale;

View file

@ -404,11 +404,6 @@
#else
#define STRINGBUFLEN 1024
#endif
// ResidualVM specific:
#ifndef LOCAL_PI
#define LOCAL_PI 3.14159265358979323846
#endif
#endif
#ifndef MAXPATHLEN

View file

@ -142,7 +142,7 @@ Math::Matrix4 GfxBase::makeLookMatrix(const Math::Vector3d& pos, const Math::Vec
}
Math::Matrix4 GfxBase::makeProjMatrix(float fov, float nclip, float fclip) {
float right = nclip * tan(fov / 2 * (LOCAL_PI / 180));
float right = nclip * tan(fov / 2 * ((float)M_PI / 180));
float left = -right;
float top = right * 0.75;
float bottom = -right * 0.75;

View file

@ -231,7 +231,7 @@ void GfxOpenGL::setupCameraFrustum(float fov, float nclip, float fclip) {
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
float right = nclip * tan(fov / 2 * (LOCAL_PI / 180));
float right = nclip * tan(fov / 2 * ((float)M_PI / 180));
glFrustum(-right, right, -right * 0.75, right * 0.75, nclip, fclip);
glMatrixMode(GL_MODELVIEW);

View file

@ -441,7 +441,7 @@ void GfxOpenGLS::setupCameraFrustum(float fov, float nclip, float fclip) {
_fov = fov; _nclip = nclip; _fclip = fclip;
float right = nclip * tan(fov / 2 * (LOCAL_PI / 180));
float right = nclip * tan(fov / 2 * ((float)M_PI / 180));
float top = right * 0.75;
_projMatrix = makeFrustumMatrix(-right, right, -top, top, nclip, fclip);

View file

@ -117,7 +117,7 @@ void GfxTinyGL::setupCameraFrustum(float fov, float nclip, float fclip) {
tglMatrixMode(TGL_PROJECTION);
tglLoadIdentity();
float right = nclip * tan(fov / 2 * (LOCAL_PI / 180));
float right = nclip * tan(fov / 2 * ((float)M_PI / 180));
tglFrustum(-right, right, -right * 0.75, right * 0.75, nclip, fclip);
tglMatrixMode(TGL_MODELVIEW);

View file

@ -6,18 +6,16 @@
#define FORBIDDEN_SYMBOL_EXCEPTION_rand
#define FORBIDDEN_SYMBOL_EXCEPTION_srand
#include "common/scummsys.h"
#include "engines/grim/lua/lauxlib.h"
#include "engines/grim/lua/lua.h"
#include "engines/grim/lua/lualib.h"
namespace Grim {
#ifndef LOCAL_PI
#define LOCAL_PI (3.14159265358979323846)
#endif
#define FROMRAD(a) ((a) * (180.0 / LOCAL_PI))
#define TORAD(a) ((a) * (LOCAL_PI / 180.0))
#define FROMRAD(a) ((a) * (180.0 / (float)M_PI))
#define TORAD(a) ((a) * ((float)M_PI / 180.0))
static void math_abs() {
float d = luaL_check_number(1);
@ -71,11 +69,11 @@ static void math_pow() {
}
static void math_deg() {
lua_pushnumber(luaL_check_number(1) * (180.0/LOCAL_PI));
lua_pushnumber(luaL_check_number(1) * (180.0 / (float)M_PI));
}
static void math_rad() {
lua_pushnumber(luaL_check_number(1) * (LOCAL_PI / 180.0));
lua_pushnumber(luaL_check_number(1) * ((float)M_PI / 180.0));
}
static void math_min() {
@ -148,7 +146,7 @@ void lua_mathlibopen() {
lua_pushcfunction(math_pow);
lua_pushnumber(0); // to get its tag
lua_settagmethod(lua_tag(lua_pop()), "pow");
lua_pushnumber((float)LOCAL_PI);
lua_pushnumber((float)M_PI);
lua_setglobal("PI");
}

View file

@ -277,7 +277,7 @@ void Lua_V1::GetAngleBetweenVectors() {
vec2.normalize();
float dot = vec1.dotProduct(vec2);
float angle = 90.0f - (180.0f * asin(dot)) / LOCAL_PI;
float angle = 90.0f - (180.0f * asin(dot)) / (float)M_PI;
if (angle < 0)
angle = -angle;
lua_pushnumber(angle);

View file

@ -541,12 +541,12 @@ void Set::Setup::setRoll(Math::Angle roll) {
void Light::setUmbra(float angle) {
_umbraangle = angle;
_cosumbraangle = cosf(angle * M_PI / 180.0f);
_cosumbraangle = cosf(angle * (float)M_PI / 180.0f);
}
void Light::setPenumbra(float angle) {
_penumbraangle = angle;
_cospenumbraangle = cosf(angle * M_PI / 180.0f);
_cospenumbraangle = cosf(angle * (float)M_PI / 180.0f);
}
void Light::setIntensity(float intensity) {
@ -1053,7 +1053,7 @@ void Set::calculateSoundPosition(const Math::Vector3d &pos, int minVol, int maxV
Math::Vector3d up(0, 0, 1);
Math::Vector3d right;
cameraVector.normalize();
float roll = -_currSetup->_roll * LOCAL_PI / 180.f;
float roll = -_currSetup->_roll * (float)M_PI / 180.f;
float cosr = cos(roll);
// Rotate the up vector by roll.
up = up * cosr + Math::Vector3d::crossProduct(cameraVector, up) * sin(roll) +

View file

@ -63,7 +63,7 @@ void WorldToFilm(const PXvector_PC &worldpos, const PCcamera &camera, bool8 &is_
PXreal AngleOfVector(PXreal x, PXreal y) {
if (fabs(x) > 0.0001f) { /*smallest value safe for atan2*/
return (float)atan2(y, x) / M_PI / 2;
return (float)atan2(y, x) / (float)M_PI / 2;
} else {
// atan2's y/x would be infinite, so treat as special case
if (y > 0.0f)

View file

@ -1816,7 +1816,7 @@ void _set::HackMakeCamera() {
float fpan;
int scrnPan;
if (ctheta != 0) {
fpan = (float)atan((float)stheta / (float)ctheta) / (2.0f * M_PI);
fpan = (float)atan((float)stheta / (float)ctheta) / (2.0f * (float)M_PI);
scrnPan = (int)(fpan * ONE);
// second & third quadrant (90-270 degrees) : pan += 180 (pan is -ve(90-180), (180-270)+ve)
if (ctheta < 0)

View file

@ -479,8 +479,8 @@ ProjectorMovie::ProjectorMovie(Myst3Engine *vm, uint16 id, Graphics::Surface *ba
_enabled = true;
for (uint i = 0; i < kBlurIterations; i++) {
_blurTableX[i] = (uint8)(sin(2 * LOCAL_PI * i / (float)kBlurIterations) * 256.0);
_blurTableY[i] = (uint8)(cos(2 * LOCAL_PI * i / (float)kBlurIterations) * 256.0);
_blurTableX[i] = (uint8)(sin(2 * (float)M_PI * i / (float)kBlurIterations) * 256.0);
_blurTableY[i] = (uint8)(cos(2 * (float)M_PI * i / (float)kBlurIterations) * 256.0);
}
}

View file

@ -922,7 +922,7 @@ void Script::polarToRectSimple(Context &c, const Opcode &cmd) {
debugC(kDebugScript, "Opcode %d: Polar to rect transformation for angle in var %d", cmd.op, cmd.args[5]);
int32 angleDeg = _vm->_state->getVar(cmd.args[5]);
float angleRad = 2 * LOCAL_PI / cmd.args[6] * angleDeg;
float angleRad = 2 * (float)M_PI / cmd.args[6] * angleDeg;
float angleSin = sin(angleRad);
float angleCos = cos(angleRad);
@ -946,7 +946,7 @@ void Script::polarToRect(Context &c, const Opcode &cmd) {
debugC(kDebugScript, "Opcode %d: Complex polar to rect transformation for angle in var %d", cmd.op, cmd.args[8]);
int32 angleDeg = _vm->_state->getVar(cmd.args[8]);
float angleRad = 2 * LOCAL_PI / cmd.args[9] * angleDeg;
float angleRad = 2 * (float)M_PI / cmd.args[9] * angleDeg;
float angleSin = sin(angleRad);
float angleCos = cos(angleRad);

View file

@ -114,7 +114,7 @@ void Location::onGameLoop() {
_floatPosition -= 1.0;
}
float floatOffset = sinf(_floatPosition * 2.0f * M_PI) * _floatAmplitude;
float floatOffset = sinf(_floatPosition * 2.0f * (float)M_PI) * _floatAmplitude;
StarkScene->setFloatOffset(floatOffset);
}
@ -124,7 +124,7 @@ void Location::onGameLoop() {
_swayPosition -= 1.0;
}
float sway = sinf((_swayOffset + _swayPosition) * 2.0f * M_PI) * _swayAmplitude;
float sway = sinf((_swayOffset + _swayPosition) * 2.0f * (float)M_PI) * _swayAmplitude;
StarkScene->setSwayAngle(_swayAngle * sway);
}

View file

@ -88,7 +88,7 @@ void Scene::scrollCamera(const Common::Rect &viewport) {
void Scene::computeClippingRect(float *xmin, float *xmax, float *ymin, float *ymax) {
float aspectRatio = _viewSize.width() / (float) _viewSize.height();
float xmaxValue = _nearClipPlane * tan(_fov * M_PI / 360.0);
float xmaxValue = _nearClipPlane * tan(_fov * (float)M_PI / 360.0);
float ymaxValue = xmaxValue / aspectRatio;
float xminValue = xmaxValue - 2 * xmaxValue * (_viewport.width() / (float) _viewSize.width());

View file

@ -112,8 +112,8 @@ void VisualExplodingImage::ExplosionUnit::setPosition(int x, int y) {
void VisualExplodingImage::ExplosionUnit::setExplosionSettings(const Common::Point &center, const Common::Point &amplitude, float scale) {
_center = Math::Vector2d(center.x, center.y);
_speed.setX(cos(StarkRandomSource->getRandomNumber(M_PI * 100)) * (float)amplitude.x);
_speed.setY(sin(StarkRandomSource->getRandomNumber(M_PI * 100)) * (float)amplitude.y);
_speed.setX(cos(StarkRandomSource->getRandomNumber((float)M_PI * 100)) * (float)amplitude.x);
_speed.setY(sin(StarkRandomSource->getRandomNumber((float)M_PI * 100)) * (float)amplitude.y);
// WTF, ensuring all fragments go in the same direction?
float magnitude = _position.getDistanceTo(_speed);

View file

@ -128,7 +128,7 @@ void BaseRenderOpenGL3D::setLightParameters(int index, const Math::Vector3d &pos
glLightf(GL_LIGHT0 + index, GL_SPOT_EXPONENT, 0.0f);
// wme sets the phi angle to 1.0 (in radians)
// so either 180/pi or (180/pi)/2 should give the same result
glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, (180.0f / M_PI));
glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, (180.0f / (float)M_PI));
} else {
glLightf(GL_LIGHT0 + index, GL_SPOT_CUTOFF, 180.0f);
}

View file

@ -131,7 +131,7 @@ void glopLight(GLContext *c, GLParam *p) {
assert(a == 180 || (a >= 0 && a <= 90));
l->spot_cutoff = a;
if (a != 180)
l->cos_spot_cutoff = (float)(cos(a * LOCAL_PI / 180.0));
l->cos_spot_cutoff = (float)(cos(a * (float)M_PI / 180.0));
}
break;
case TGL_CONSTANT_ATTENUATION:

View file

@ -129,7 +129,7 @@ void glopRotate(GLContext *c, GLParam *p) {
float angle;
int dir_code;
angle = (float)(p[1].f * LOCAL_PI / 180.0);
angle = (float)(p[1].f * (float)M_PI / 180.0);
u[0] = p[2].f;
u[1] = p[3].f;
u[2] = p[4].f;

View file

@ -552,8 +552,8 @@ FORCEINLINE void BlitImage::tglBlitRotoScale(int dstX, int dstY, int width, int
clampHeight = destinationRectangle.height();
uint32 invAngle = 360 - (rotation % 360);
float invCos = cos(invAngle * M_PI / 180.0f);
float invSin = sin(invAngle * M_PI / 180.0f);
float invCos = cos(invAngle * (float)M_PI / 180.0f);
float invSin = sin(invAngle * (float)M_PI / 180.0f);
int icosx = (int)(invCos * (65536.0f * srcWidth / width));
int isinx = (int)(invSin * (65536.0f * srcWidth / width));
@ -736,7 +736,7 @@ void tglBlitResetScissorRect(void) {
} // end of namespace Internal
Common::Point transformPoint(float x, float y, int rotation) {
float rotateRad = rotation * M_PI / 180.0f;
float rotateRad = rotation * (float)M_PI / 180.0f;
Common::Point newPoint;
newPoint.x = x * cos(rotateRad) - y * sin(rotateRad);
newPoint.y = x * sin(rotateRad) + y * cos(rotateRad);

View file

@ -33,6 +33,7 @@
#include "common/textconsole.h"
#include "common/array.h"
#include "common/list.h"
#include "common/scummsys.h"
#include "graphics/tinygl/gl.h"
#include "graphics/tinygl/zbuffer.h"
@ -448,10 +449,6 @@ void glClose();
#define dprintf
#endif
#ifndef LOCAL_PI
#define LOCAL_PI (3.14159265358979323846)
#endif
// glopXXX functions
#define ADD_OP(a,b,c) void glop ## a (GLContext *, GLParam *);