summaryrefslogtreecommitdiff
path: root/3de.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-07-03 21:20:02 +1000
committerquou <quou@disroot.org>2024-07-03 21:20:35 +1000
commit2da353ada0685a4a8780bf8d2f5aa63252c3f0a5 (patch)
tree736037aa53ea14e77a17526a12579cd572d37126 /3de.c
parent39100e7292d3ee12d387fddfa0f0d7b712e31e1c (diff)
Spinning torus
Diffstat (limited to '3de.c')
-rw-r--r--3de.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/3de.c b/3de.c
index 1b88ae3..6bf9e33 100644
--- a/3de.c
+++ b/3de.c
@@ -1,10 +1,42 @@
#include "config.h"
+#include "maths.h"
#include "memory.h"
#include "plat.h"
#include "render.h"
+#include "torus.h"
#include <stdio.h>
+void draw_spinny(Renderer* r, Colour c) {
+ static int a = 0;
+ int y; int x = y = 100 << fbits;
+ x -= sin_table[a & sin_table_mask] * 10;
+ y += cos_table[a & sin_table_mask] * 10;
+ ren_point(r, c, x >> fbits, y >> fbits);
+ a += 20;
+}
+
+void draw_torus(Renderer* r, Colour c) {
+ static int a = 0;
+ const int pc = sizeof torus_points / sizeof *torus_points;
+ int asp = (r->clip.w << fbits) / r->clip.h;
+ int p[4] = { 0, 0, 5 << fbits, f1 };
+ int i;
+ mtx_push_trans(p);
+ mtx_push_rot_x(a);
+ mtx_push_rot_y(a);
+ mtx_push_rot_z(a);
+ for (i = 0; i < pc; i += 3) {
+ vec_cpy(p, &torus_points[i], 3);
+ mtx_apply(mtx_peek(), p);
+ persp(p, asp);
+ ndc2clip((int*)&r->clip, p);
+ ren_point(r, c, p[0], p[1]);
+ }
+ mtx_popn(4);
+ a += 3;
+}
+
int entrypoint(int argc, const char** argv, Arena* a) {
App* app;
Renderer r;
@@ -14,6 +46,7 @@ int entrypoint(int argc, const char** argv, Arena* a) {
Colour blue = make_aliceblue();
(void)argc;
(void)argv;
+ init_maths();
init_heap(
&h,
arena_alloc(a, app_memory_size),
@@ -34,6 +67,7 @@ int entrypoint(int argc, const char** argv, Arena* a) {
ren_text(&r, blue, 3, 13, buf);
sprintf(buf, "MOUSE: %d, %d", app->mx, app->my);
ren_text(&r, blue, 3, 23, buf);
+ draw_torus(&r, blue);
ren_end(&r);
app_end(app);
fps_update(&f);