summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-07-17 21:29:29 +1000
committerquou <quou@disroot.org>2024-07-17 21:29:41 +1000
commitc67b409dd32e4aa795e5aa9868202c910fc9ffd0 (patch)
treed97724dee6a2e1369474403af6b0e00abe81e058
parentb8d2cf5610f0e0ef96ded0a5de5bda54c10c9552 (diff)
simple mouse look
-rw-r--r--3de.c20
-rw-r--r--Makefile1
-rw-r--r--player.c33
-rw-r--r--player.h16
-rw-r--r--services.h9
5 files changed, 74 insertions, 5 deletions
diff --git a/3de.c b/3de.c
index 23e4d13..6197321 100644
--- a/3de.c
+++ b/3de.c
@@ -3,7 +3,9 @@
#include "maths.h"
#include "memory.h"
#include "plat.h"
+#include "player.h"
#include "render.h"
+#include "services.h"
#include "tile.h"
#include <stdio.h>
@@ -21,13 +23,13 @@ void draw_monkey(Renderer* r) {
static int a = 0;
const Mesh* m = get_mesh(asset_id_monkey);
Bitmap tex = { (Colour*)tile_pixels, 16, 16 };
- int p[] = { 0, 0, 5 << fbits, f1 };
+ int p[] = { 0, 0, 0, f1 };
mtx_push_trans(p);
- mtx_push_rot_x(a);
+ /*mtx_push_rot_x(a);
mtx_push_rot_y(a);
- mtx_push_rot_z(a);
+ mtx_push_rot_z(a);*/
ren_mesh(r, m, &tex);
- mtx_popn(4);
+ mtx_popn(1);
a++;
}
@@ -50,6 +52,8 @@ int entrypoint(int argc, const char** argv, Arena* a) {
int* depth = 0;
Arena preload;
Colour blue = make_aliceblue();
+ Player p;
+ Services s;
(void)argc;
(void)argv;
init_maths();
@@ -72,11 +76,15 @@ int entrypoint(int argc, const char** argv, Arena* a) {
return error_out_of_memory;
}
preload_assets(&preload);
+ s.a = app;
+ s.r = &r;
cfg_mouse(app, 0);
+ init_player(&p);
while (app->o) {
fps_begin(&f);
while (f.now >= f.next) {
app_begin(app);
+ update_player(&p, &s);
ren_begin(&r, app->fb, depth, app->w, app->h);
ren_clear(&r);
ren_cleard(&r, f1 * 300);
@@ -86,8 +94,10 @@ int entrypoint(int argc, const char** argv, Arena* a) {
ren_texts(&r, blue, 3, 8, buf);
sprintf(buf, "MOUSE: %d, %d", app->mx, app->my);
ren_texts(&r, blue, 3, 13, buf);
+ push_player_cam(&p);
draw_monkey(&r);
- draw_tri(&r, app->mx, app->my);
+ pop_player_cam();
+ /*draw_tri(&r, app->mx, app->my);*/
ren_end(&r);
app_end(app);
fps_update(&f);
diff --git a/Makefile b/Makefile
index d183d38..33c0c01 100644
--- a/Makefile
+++ b/Makefile
@@ -18,6 +18,7 @@ sources = \
maths.c \
memory.c \
plat.c \
+ player.c \
rect.c \
render.c \
standard.c
diff --git a/player.c b/player.c
new file mode 100644
index 0000000..2ba3885
--- /dev/null
+++ b/player.c
@@ -0,0 +1,33 @@
+#include "maths.h"
+#include "plat.h"
+#include "player.h"
+#include "services.h"
+
+void init_player(Player* p) {
+ int ip[] = { 0, 0, -(5 << fbits) };
+ vec_cpy(p->p, ip, 3);
+ p->r[0] = 0;
+ p->r[1] = 0;
+}
+
+void update_player(Player* p, struct Services* s) {
+ App* a = s->a;
+/* p->r[0] -= a->dmy;*/
+ p->r[1] -= a->dmx;
+/* p->p[0] -= sin_table[p->r[1] & sin_table_mask] / 3;
+ p->p[2] += cos_table[p->r[1] & sin_table_mask] / 3;*/
+}
+
+void push_player_cam(const Player* p) {
+ int v[3];
+ v[0] = -p->p[0];
+ v[1] = -p->p[1];
+ v[2] = -p->p[2];
+ mtx_push_rot_y(p->r[1] / 10);
+ mtx_push_rot_x(p->r[0] / 10);
+ mtx_push_trans(v);
+}
+
+void pop_player_cam(void) {
+ mtx_popn(3);
+}
diff --git a/player.h b/player.h
new file mode 100644
index 0000000..5c26b9d
--- /dev/null
+++ b/player.h
@@ -0,0 +1,16 @@
+#ifndef player_h
+#define player_h
+
+struct Services;
+
+typedef struct {
+ int p[3];
+ int r[2];
+} Player;
+
+void init_player(Player* p);
+void update_player(Player* p, struct Services* s);
+void push_player_cam(const Player* p);
+void pop_player_cam(void);
+
+#endif
diff --git a/services.h b/services.h
new file mode 100644
index 0000000..86adee2
--- /dev/null
+++ b/services.h
@@ -0,0 +1,9 @@
+#ifndef services_h
+#define services_h
+
+typedef struct Services {
+ App* a;
+ Renderer* r;
+} Services;
+
+#endif