From c408b0425f8646103d28f0ae61e732424e34ab47 Mon Sep 17 00:00:00 2001 From: rodri Date: Thu, 8 Feb 2024 11:27:02 +0000 Subject: add inception mode. improve the navigation. also don't rotate by default. --- main.c | 63 ++++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 42 insertions(+), 21 deletions(-) diff --git a/main.c b/main.c index bb9937f..c35d738 100644 --- a/main.c +++ b/main.c @@ -45,34 +45,35 @@ int kdown; OBJ *model; Memimage *modeltex; Shader *shader; -double θ, ω = 2*DEG; +double θ, ω = 0; Camera cams[4], *maincam; Camcfg camcfgs[4] = { 2,0,-4,1, 0,0,0,1, 0,1,0,0, - 0, 0.1, 100, ORTHOGRAPHIC, + 0, 0.01, 100, ORTHOGRAPHIC, -2,0,-4,1, 0,0,0,1, 0,1,0,0, - 120*DEG, 0.1, 100, PERSPECTIVE, + 120*DEG, 0.01, 100, PERSPECTIVE, -2,0,4,1, 0,0,0,1, 0,1,0,0, - 0, 0.1, 100, ORTHOGRAPHIC, + 0, 0.01, 100, ORTHOGRAPHIC, 2,0,4,1, 0,0,0,1, 0,1,0,0, - 120*DEG, 0.1, 100, PERSPECTIVE + 120*DEG, 0.01, 100, PERSPECTIVE }; Point3 center = {0,0,0,1}; Point3 light = {0,1,1,1}; /* global point light */ static int doprof; +static int inception; static int min(int a, int b) @@ -321,17 +322,35 @@ redraw(void) void drawproc(void *) { + Memimage *scrtex; uvlong t0, Δt; + int fd; threadsetname("drawproc"); + scrtex = nil; + fd = -1; + if(inception){ + fd = open("/dev/screen", OREAD); + if(fd < 0) + sysfatal("open: %r"); + if((scrtex = readmemimage(fd)) == nil) + sysfatal("readmemimage: %r"); + } + t0 = nsec(); for(;;){ - shootcamera(maincam, model, modeltex, shader); + shootcamera(maincam, model, inception? scrtex: modeltex, shader); Δt = nsec() - t0; if(Δt > HZ2MS(60)*1000000ULL){ nbsend(drawc, nil); t0 += Δt; + if(inception){ + freememimage(scrtex); + seek(fd, 0, 0); + if((scrtex = readmemimage(fd)) == nil) + sysfatal("readmemimage: %r"); + } } } } @@ -340,11 +359,11 @@ void mouse(void) { if((mctl->buttons & 8) != 0){ - maincam->fov = fclamp(maincam->fov - 5*DEG, 1*DEG, 359*DEG); + maincam->fov = fclamp(maincam->fov - 1*DEG, 1*DEG, 359*DEG); reloadcamera(maincam); } if((mctl->buttons & 16) != 0){ - maincam->fov = fclamp(maincam->fov + 5*DEG, 1*DEG, 359*DEG); + maincam->fov = fclamp(maincam->fov + 1*DEG, 1*DEG, 359*DEG); reloadcamera(maincam); } } @@ -409,29 +428,29 @@ void handlekeys(void) { if(kdown & 1<p, maincam->bz), maincam->bz, maincam->by); + placecamera(maincam, subpt3(maincam->p, mulpt3(maincam->bz, 0.1)), maincam->bz, maincam->by); if(kdown & 1<p, maincam->bz), maincam->bz, maincam->by); + placecamera(maincam, addpt3(maincam->p, mulpt3(maincam->bz, 0.1)), maincam->bz, maincam->by); if(kdown & 1<p, maincam->bx), maincam->bz, maincam->by); + placecamera(maincam, subpt3(maincam->p, mulpt3(maincam->bx, 0.1)), maincam->bz, maincam->by); if(kdown & 1<p, maincam->bx), maincam->bz, maincam->by); + placecamera(maincam, addpt3(maincam->p, mulpt3(maincam->bx, 0.1)), maincam->bz, maincam->by); if(kdown & 1<p, maincam->by), maincam->bz, maincam->by); + placecamera(maincam, addpt3(maincam->p, mulpt3(maincam->by, 0.1)), maincam->bz, maincam->by); if(kdown & 1<p, maincam->by), maincam->bz, maincam->by); + placecamera(maincam, subpt3(maincam->p, mulpt3(maincam->by, 0.1)), maincam->bz, maincam->by); if(kdown & 1<bz, maincam->bx, 5*DEG)); + aimcamera(maincam, qrotate(maincam->bz, maincam->bx, 1*DEG)); if(kdown & 1<bz, maincam->bx, -5*DEG)); + aimcamera(maincam, qrotate(maincam->bz, maincam->bx, -1*DEG)); if(kdown & 1<bz, maincam->by, 5*DEG)); + aimcamera(maincam, qrotate(maincam->bz, maincam->by, 1*DEG)); if(kdown & 1<bz, maincam->by, -5*DEG)); + aimcamera(maincam, qrotate(maincam->bz, maincam->by, -1*DEG)); if(kdown & 1<p, maincam->bz, qrotate(maincam->by, maincam->bz, 5*DEG)); + placecamera(maincam, maincam->p, maincam->bz, qrotate(maincam->by, maincam->bz, 1*DEG)); if(kdown & 1<p, maincam->bz, qrotate(maincam->by, maincam->bz, -5*DEG)); + placecamera(maincam, maincam->p, maincam->bz, qrotate(maincam->by, maincam->bz, -1*DEG)); if(kdown & 1<