summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-03-19 01:24:25 +0100
committerkdx <kikoodx@paranoici.org>2023-03-19 01:24:25 +0100
commita9952fb4912ff7dc7f4a26137316dfa1df01c599 (patch)
tree5ba97fc54489f9a91bbc386d80178f51b0132962
parent72e8a34ff3dccb8eb9c94f8e12a670ac84ae89c9 (diff)
downloadhyperultra-a9952fb4912ff7dc7f4a26137316dfa1df01c599.tar.gz
move rotating rect code out of background
-rw-r--r--src/background.c38
-rw-r--r--src/rotrect.c43
-rw-r--r--src/rotrect.h3
3 files changed, 49 insertions, 35 deletions
diff --git a/src/background.c b/src/background.c
index 4d17af3..c3b7e62 100644
--- a/src/background.c
+++ b/src/background.c
@@ -1,45 +1,13 @@
#include "lzy.h"
#include "cfg.h"
-#include <math.h>
+#include "rotrect.h"
static long tick = 0;
static void
-rotate(double *x, double *y, double angle)
+draw_square(double size, double angle)
{
- const double s = sin(angle);
- const double c = cos(angle);
- const double ox = *x;
- const double oy = *y;
-
- *x = ox * c - oy * s;
- *y = ox * s + oy * c;
-}
-
-static void
-draw_square(int size, double angle)
-{
- double x[4] = {
- size / 2.0,
- size / 2.0,
- -size / 2.0,
- -size / 2.0,
- };
- double y[4] = {
- -size / 2.0,
- size / 2.0,
- size / 2.0,
- -size / 2.0,
- };
- for (int i = 0; i < 4; i++) {
- rotate(&x[i], &y[i], angle);
- x[i] += DISPLAY_WIDTH / 2.0;
- y[i] += DISPLAY_HEIGHT / 2.0;
- }
- LZY_DrawLine(x[0], y[0], x[1], y[1]);
- LZY_DrawLine(x[1], y[1], x[2], y[2]);
- LZY_DrawLine(x[2], y[2], x[3], y[3]);
- LZY_DrawLine(x[3], y[3], x[0], y[0]);
+ rotrect(DISPLAY_WIDTH / 2.0, DISPLAY_HEIGHT / 2.0, size, size, angle);
}
void
diff --git a/src/rotrect.c b/src/rotrect.c
new file mode 100644
index 0000000..5abae13
--- /dev/null
+++ b/src/rotrect.c
@@ -0,0 +1,43 @@
+#include "rotrect.h"
+#include "cfg.h"
+#include "lzy.h"
+#include <math.h>
+
+static void
+rotate(double *x, double *y, double angle)
+{
+ const double s = sin(angle);
+ const double c = cos(angle);
+ const double ox = *x;
+ const double oy = *y;
+
+ *x = ox * c - oy * s;
+ *y = ox * s + oy * c;
+}
+
+void
+rotrect(double x, double y, double width, double height, double angle)
+{
+ double xs[4] = {
+ width / 2.0,
+ width / 2.0,
+ -width / 2.0,
+ -width / 2.0,
+ };
+ double ys[4] = {
+ -height / 2.0,
+ height / 2.0,
+ height / 2.0,
+ -height / 2.0,
+ };
+ for (int i = 0; i < 4; i++) {
+ rotate(&xs[i], &ys[i], angle);
+ xs[i] = round(xs[i] + x);
+ ys[i] = round(ys[i] + y);
+ }
+ LZY_DrawLine(xs[0], ys[0], xs[1], ys[1]);
+ LZY_DrawLine(xs[1], ys[1], xs[2], ys[2]);
+ LZY_DrawLine(xs[2], ys[2], xs[3], ys[3]);
+ LZY_DrawLine(xs[3], ys[3], xs[0], ys[0]);
+}
+
diff --git a/src/rotrect.h b/src/rotrect.h
new file mode 100644
index 0000000..db0f426
--- /dev/null
+++ b/src/rotrect.h
@@ -0,0 +1,3 @@
+#pragma once
+
+void rotrect(double x, double y, double width, double height, double angle);