Removed SDL_stdinc.h dependency on HAVE_M_PI, added SDL_M_PIl (double) and SDL_M_PIf (float) instead

This commit is contained in:
Sam Lantinga
2022-11-25 10:33:37 -08:00
parent 8733927e35
commit 670f1df469
16 changed files with 38 additions and 44 deletions

View File

@@ -304,9 +304,9 @@ static float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ)
-TRANSLATED DIRECTLY FROM PSUDEO-CODE AVAILABLE AT-
-"http://depts.washington.edu/aimgroup/proj/dollar/"
*/
double ta = -M_PI/4;
double tb = M_PI/4;
double dt = M_PI/90;
double ta = -SDL_M_PIl/4;
double tb = SDL_M_PIl/4;
double dt = SDL_M_PIl/90;
float x1 = (float)(PHI*ta + (1-PHI)*tb);
float f1 = dollarDifference(points,templ,x1);
float x2 = (float)((1-PHI)*ta + PHI*tb);

View File

@@ -37,11 +37,6 @@
#include <errno.h> /* errno, strerror */
#include <sys/stat.h> /* stat */
/* Just in case. */
#ifndef M_PI
# define M_PI 3.14159265358979323846
#endif
#define MAX_HAPTICS 32 /* It's doubtful someone has more then 32 evdev */
@@ -721,7 +716,7 @@ SDL_SYS_ToDirection(Uint16 *dest, SDL_HapticDirection * src)
--> add 45000 in total
--> finally convert to [0,0xFFFF] as in case SDL_HAPTIC_POLAR.
*/
tmp = (((Sint32) (f * 18000. / M_PI)) + 45000) % 36000;
tmp = (((Sint32) (f * 18000.0 / SDL_M_PIl)) + 45000) % 36000;
tmp = (tmp * 0x8000) / 18000; /* convert to range [0,0xFFFF] */
*dest = (Uint16) tmp;
}

View File

@@ -567,7 +567,7 @@ HIDAPI_DriverPS4_ApplyCalibrationData(SDL_DriverPS4_Context *ctx, int index, Sin
/* Convert the raw data to the units expected by SDL */
if (index < 3) {
result = (result / GYRO_RES_PER_DEGREE) * (float)M_PI / 180.0f;
result = (result / GYRO_RES_PER_DEGREE) * SDL_M_PIf / 180.0f;
} else {
result = (result / ACCEL_RES_PER_G) * SDL_STANDARD_GRAVITY;
}

View File

@@ -612,7 +612,7 @@ HIDAPI_DriverPS5_ApplyCalibrationData(SDL_DriverPS5_Context *ctx, int index, Sin
/* Convert the raw data to the units expected by SDL */
if (index < 3) {
result = (result / GYRO_RES_PER_DEGREE) * (float)M_PI / 180.0f;
result = (result / GYRO_RES_PER_DEGREE) * SDL_M_PIf / 180.0f;
} else {
result = (result / ACCEL_RES_PER_G) * SDL_STANDARD_GRAVITY;
}

View File

@@ -1260,9 +1260,9 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
ctx->timestamp_us += ctx->update_rate_in_us;
values[0] = (ctx->m_state.sGyroX / 32768.0f) * (2000.0f * ((float)M_PI / 180.0f));
values[1] = (ctx->m_state.sGyroZ / 32768.0f) * (2000.0f * ((float)M_PI / 180.0f));
values[2] = (ctx->m_state.sGyroY / 32768.0f) * (2000.0f * ((float)M_PI / 180.0f));
values[0] = (ctx->m_state.sGyroX / 32768.0f) * (2000.0f * (SDL_M_PIf / 180.0f));
values[1] = (ctx->m_state.sGyroZ / 32768.0f) * (2000.0f * (SDL_M_PIf / 180.0f));
values[2] = (ctx->m_state.sGyroY / 32768.0f) * (2000.0f * (SDL_M_PIf / 180.0f));
SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, ctx->timestamp_us, values, 3);
values[0] = (ctx->m_state.sAccelX / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;

View File

@@ -805,7 +805,7 @@ static SDL_bool LoadIMUCalibration(SDL_DriverSwitch_Context* ctx)
if (!WriteSubcommand(ctx, k_eSwitchSubcommandIDs_SPIFlashRead, (uint8_t*)&readParams, sizeof(readParams), &reply)) {
const float accelScale = SDL_STANDARD_GRAVITY / SWITCH_ACCEL_SCALE;
const float gyroScale = (float)M_PI / 180.0f / SWITCH_GYRO_SCALE;
const float gyroScale = SDL_M_PIf / 180.0f / SWITCH_GYRO_SCALE;
ctx->m_IMUScaleData.fAccelScaleX = accelScale;
ctx->m_IMUScaleData.fAccelScaleY = accelScale;
@@ -850,9 +850,9 @@ static SDL_bool LoadIMUCalibration(SDL_DriverSwitch_Context* ctx)
ctx->m_IMUScaleData.fAccelScaleZ = SWITCH_ACCEL_SCALE_MULT / (float)(SWITCH_ACCEL_SCALE_OFFSET - (float)sAccelRawZ) * SDL_STANDARD_GRAVITY;
/* Gyro scale */
ctx->m_IMUScaleData.fGyroScaleX = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawX) * (float)M_PI / 180.0f;
ctx->m_IMUScaleData.fGyroScaleY = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawY) * (float)M_PI / 180.0f;
ctx->m_IMUScaleData.fGyroScaleZ = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawZ) * (float)M_PI / 180.0f;
ctx->m_IMUScaleData.fGyroScaleX = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawX) * SDL_M_PIf / 180.0f;
ctx->m_IMUScaleData.fGyroScaleY = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawY) * SDL_M_PIf / 180.0f;
ctx->m_IMUScaleData.fGyroScaleZ = SWITCH_GYRO_SCALE_MULT / (float)(SWITCH_GYRO_SCALE_OFFSET - (float)sGyroRawZ) * SDL_M_PIf / 180.0f;
return SDL_TRUE;
}

View File

@@ -1192,9 +1192,9 @@ static void HandleMotionPlusData(SDL_DriverWii_Context *ctx, SDL_Joystick *joyst
z *= 2000;
}
values[0] = -((float)z / GYRO_RES_PER_DEGREE) * (float)M_PI / 180.0f;
values[1] = ((float)x / GYRO_RES_PER_DEGREE) * (float)M_PI / 180.0f;
values[2] = ((float)y / GYRO_RES_PER_DEGREE) * (float)M_PI / 180.0f;
values[0] = -((float)z / GYRO_RES_PER_DEGREE) * SDL_M_PIf / 180.0f;
values[1] = ((float)x / GYRO_RES_PER_DEGREE) * SDL_M_PIf / 180.0f;
values[2] = ((float)y / GYRO_RES_PER_DEGREE) * SDL_M_PIf / 180.0f;
SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, 0, values, 3);
}
}

View File

@@ -3679,7 +3679,7 @@ SDL_RenderCopyExF(SDL_Renderer * renderer, SDL_Texture * texture,
float s_minx, s_miny, s_maxx, s_maxy;
float c_minx, c_miny, c_maxx, c_maxy;
const float radian_angle = (float)((M_PI * angle) / 180.0);
const float radian_angle = (float)((SDL_M_PIl * angle) / 180.0);
const float s = SDL_sinf(radian_angle);
const float c = SDL_cosf(radian_angle);

View File

@@ -1821,13 +1821,13 @@ D3D11_UpdateViewport(SDL_Renderer * renderer)
projection = MatrixIdentity();
break;
case DXGI_MODE_ROTATION_ROTATE270:
projection = MatrixRotationZ(SDL_static_cast(float, M_PI * 0.5f));
projection = MatrixRotationZ(SDL_M_PIf * 0.5f);
break;
case DXGI_MODE_ROTATION_ROTATE180:
projection = MatrixRotationZ(SDL_static_cast(float, M_PI));
projection = MatrixRotationZ(SDL_M_PIf);
break;
case DXGI_MODE_ROTATION_ROTATE90:
projection = MatrixRotationZ(SDL_static_cast(float, -M_PI * 0.5f));
projection = MatrixRotationZ(-SDL_M_PIf * 0.5f);
break;
default:
return SDL_SetError("An unknown DisplayOrientation is being used");

View File

@@ -2366,13 +2366,13 @@ D3D12_UpdateViewport(SDL_Renderer * renderer)
projection = MatrixIdentity();
break;
case DXGI_MODE_ROTATION_ROTATE270:
projection = MatrixRotationZ(SDL_static_cast(float, M_PI * 0.5f));
projection = MatrixRotationZ(SDL_M_PIf * 0.5f);
break;
case DXGI_MODE_ROTATION_ROTATE180:
projection = MatrixRotationZ(SDL_static_cast(float, M_PI));
projection = MatrixRotationZ(SDL_M_PIf);
break;
case DXGI_MODE_ROTATION_ROTATE90:
projection = MatrixRotationZ(SDL_static_cast(float, -M_PI * 0.5f));
projection = MatrixRotationZ(-SDL_M_PIf * 0.5f);
break;
default:
return SDL_SetError("An unknown DisplayOrientation is being used");

View File

@@ -122,7 +122,7 @@ SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, const SDL_FP
double sinangle;
double cosangle;
radangle = angle * (M_PI / 180.0);
radangle = angle * (SDL_M_PIl / 180.0);
sinangle = SDL_sin(radangle);
cosangle = SDL_cos(radangle);

View File

@@ -180,7 +180,7 @@ static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnDataUpdated(ISensorEvents *
hrZ = ISensorDataReport_GetSensorValue(pNewData, &SDL_SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, &valueZ);
if (SUCCEEDED(hrX) && SUCCEEDED(hrY) && SUCCEEDED(hrZ) &&
valueX.vt == VT_R8 && valueY.vt == VT_R8 && valueZ.vt == VT_R8) {
const float DEGREES_TO_RADIANS = (float)(M_PI / 180.0f);
const float DEGREES_TO_RADIANS = (SDL_M_PIf / 180.0f);
float values[3];
values[0] = (float)valueX.dblVal * DEGREES_TO_RADIANS;

View File

@@ -79,12 +79,12 @@ SDL_acos(double val)
#else
double result;
if (val == -1.0) {
result = M_PI;
result = SDL_M_PIl;
} else {
result = SDL_atan(SDL_sqrt(1.0 - val * val) / val);
if (result < 0.0)
{
result += M_PI;
result += SDL_M_PIl;
}
}
return result;
@@ -109,9 +109,9 @@ SDL_asin(double val)
#else
double result;
if (val == -1.0) {
result = -(M_PI / 2.0);
result = -(SDL_M_PIl / 2.0);
} else {
result = (M_PI / 2.0) - SDL_acos(val);
result = (SDL_M_PIl / 2.0) - SDL_acos(val);
}
return result;
#endif