cepheid

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

commit 750ed049e5a3e77712389fc848ea5bd29ce03997
parent b47747cd7e322292fc65e24858b2bac6839652fa
Author: hhvn <dev@hhvn.uk>
Date:   Fri, 19 Aug 2022 16:03:43 +0100

(In/out)ward comet tails

Diffstat:
Mdata/worlds-parse.awk | 1+
Msrc/main.h | 1-
Msrc/maths.h | 10++++++++++
Msrc/struct.h | 8--------
Msrc/system.c | 17+++--------------
Msrc/ui.c | 4++--
6 files changed, 16 insertions(+), 25 deletions(-)

diff --git a/data/worlds-parse.awk b/data/worlds-parse.awk @@ -133,6 +133,7 @@ BEGIN { printf("maxdist\t%d\n", maxorb) > file printf("curdist\t%d\n", (rand() * (maxorb - minorb)) + minorb) > file printf("theta\t%d\n", rand() * 360) > file + printf("inward\t%d\n", int(rand() * 2)) > file } else { printf("dist\t%d\n", (minorb + maxorb) / 2) > file printf("curtheta\t%d\n", rand() * 360) > file diff --git a/src/main.h b/src/main.h @@ -82,7 +82,6 @@ Polar sys_polarize_around(Vector2 around, Vector2 vector); Polar sys_sum_polar(Polar absolute, Polar relative); Vector2 sys_get_vector(Body *body); Polar sys_get_polar(Body *body); -float sys_add_theta(float theta, float add); System *sys_init(char *name); System *sys_load(System *s, char *name); System *sys_get(char *name); diff --git a/src/maths.h b/src/maths.h @@ -17,4 +17,14 @@ #define YEAR_LEN (365.25 * DAY_LEN) #define MONTH_APPROX (YEAR_LEN / 12) +#define DEG(n) (n * RAD2DEG) +#define RAD(n) (n * DEG2RAD) + +/* 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 SQUARE(a) (a * a) diff --git a/src/struct.h b/src/struct.h @@ -132,11 +132,3 @@ typedef struct { } Clickable; #include "views.h" /* unique structures */ - -/* maths.c */ -typedef struct { - float median; - float uquart; - float lquart; - size_t elems; -} Nstats; diff --git a/src/system.c b/src/system.c @@ -44,8 +44,8 @@ bodytype_strify(Body *body) { Vector2 sys_vectorize(Polar polar) { return (Vector2) { - polar.r * cosf(polar.theta), - polar.r * sinf(polar.theta) + polar.r * COSF(polar.theta), + polar.r * SINF(polar.theta) }; } @@ -62,7 +62,7 @@ Polar sys_polarize(Vector2 vector) { return (Polar) { hypotf(vector.x, vector.y), - atan2f(vector.y, vector.x) + ATAN2F(vector.y, vector.x) }; } @@ -112,17 +112,6 @@ sys_get_polar(Body *body) { return polar; } -float -sys_add_theta(float theta, float add) { - float ret; - ret = theta + add; - while (ret > 360) - ret -= 360; - while (ret < 0) - ret += 360; - return ret; -} - System * sys_init(char *name) { System *ret = malloc(sizeof(System)); diff --git a/src/ui.c b/src/ui.c @@ -342,7 +342,7 @@ ui_draw_ring(int x, int y, float r, Color col) { return; p = sys_polarize_around(v, screen.centre); - deg = p.theta * RAD2DEG; + deg = p.theta; /* Draw the section of the ring (+ wriggle room) that will be onscreen * be (start/end)ing prec degrees before/after the screen's centre @@ -661,7 +661,7 @@ ui_draw_body(Body *body) { if (body->type == BODY_COMET && view_main.infobox.comettail.val && 10 * view_main.kmperpx < body->curdist) DrawLineV(body->pxloc, sys_vectorize_around(body->pxloc, - (Polar){11, body->theta} /* I have no fucking clue what is going on here. How does this end up correct, but not when I add 180? That theta isn't even pointing away from the sun!!! WHAT?!? */), COL_COMET); + (Polar){11, body->inward ? body->theta : body->theta + 180}), COL_COMET); if (ui_should_draw_body(body, 0)) ui_print(body->pxloc.x + w + 2, body->pxloc.y + w + 2, COL_FG, "%s", body->name);