cepheid

An Aurora 4X clone
Log | Files | Refs | README

commit f522707e3c4958b0a90ac6376623bb59d4d36a11
parent 3f0e6475dd2dd06e821de038bab8ce7d0edd409b
Author: hhvn <dev@hhvn.uk>
Date:   Mon,  3 Oct 2022 12:47:22 +0100

_d functions to replace radians with degrees

Diffstat:
Msrc/main.h | 5+++++
Asrc/maths.c | 21+++++++++++++++++++++
Msrc/maths.h | 8++++----
Msrc/system.c | 6+++---
4 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/src/main.h b/src/main.h @@ -186,3 +186,8 @@ float dbgetfloat(char *dir, char *group, char *key); Loader *loading_open(int steps, char *initstr); void loading_update(Loader *hand, char *str); void loading_close(Loader *hand); + +/* maths.c */ +float cosf_d(float x); +float sinf_d(float x); +float atan2f_d(float y, float x); diff --git a/src/maths.c b/src/maths.c @@ -0,0 +1,21 @@ +#include <raylib.h> /* RAD2DEG, DEG2RAD */ +#include <math.h> +#include "maths.h" + +#undef cosf +float +cosf_d(float x) { + return cosf(RAD(x)); +} + +#undef sinf +float +sinf_d(float x) { + return sinf(RAD(x)); +} + +#undef atan2f +float +atan2f_d(float y, float x) { + return DEG(atan2f(y, x)); +} diff --git a/src/maths.h b/src/maths.h @@ -22,9 +22,9 @@ /* eugh. raylib uses degrees, libm uses radians. * Let's make everything degrees. */ -#define COSF(n) cosf(RAD(n)) -#define SINF(n) sinf(RAD(n)) -#define ATAN2F(y, x) DEG(atan2f(y, x)) - +#define cosf(...) deprecated() +#define sinf(...) deprecated() +#define atan2f(...) deprecated() +/* see main.h for _d versions */ #define SQUARE(a) (a * a) diff --git a/src/system.c b/src/system.c @@ -7,8 +7,8 @@ Vector2 sys_vectorize(Polar polar) { return (Vector2) { - polar.r * COSF(polar.theta), - polar.r * SINF(polar.theta) + polar.r * cosf_d(polar.theta), + polar.r * sinf_d(polar.theta) }; } @@ -25,7 +25,7 @@ Polar sys_polarize(Vector2 vector) { return (Polar) { hypotf(vector.x, vector.y), - ATAN2F(vector.y, vector.x) + atan2f_d(vector.y, vector.x) }; }