shithub: tinyrend

Download patch

ref: de87611a25e3ce983d5bbd0e7173d8bfb131cc2a
parent: 9afe489f2612d54d4ecf21cf426f908d7140992a
author: rodri <rgl@antares-labs.eu>
date: Thu Dec 28 16:06:21 EST 2023

add keys to move the camera around.

--- a/main.c
+++ b/main.c
@@ -165,6 +165,7 @@
 	z = normvec3(subpt3(eye, o));
 	x = normvec3(crossvec3(up, z));
 	y = normvec3(crossvec3(z, x));
+	identity3(rota);
 	rota[0][0] = x.x; rota[0][1] = x.y; rota[0][2] = x.z; rota[0][3] = -o.x;
 	rota[1][0] = y.x; rota[1][1] = y.y; rota[1][2] = y.z; rota[1][3] = -o.y;
 	rota[2][0] = z.x; rota[2][1] = z.y; rota[2][2] = z.z; rota[2][3] = -o.z;
@@ -714,6 +715,30 @@
 	case Kdel:
 	case 'q':
 		threadexitsall(nil);
+	case 'w':
+	case 's':
+		camera.z += r == 'w'? -1: 1;
+		viewport(screenfb->r);
+		projection(-1.0/vec3len(subpt3(camera, center)));
+		lookat(camera, center, up);
+		mulm3(view, proj);
+		break;
+	case 'a':
+	case 'd':
+		camera.x += r == 'a'? -1: 1;
+		viewport(screenfb->r);
+		projection(-1.0/vec3len(subpt3(camera, center)));
+		lookat(camera, center, up);
+		mulm3(view, proj);
+		break;
+	case Kdown:
+	case Kup:
+		camera.y += r == Kdown? -1: 1;
+		viewport(screenfb->r);
+		projection(-1.0/vec3len(subpt3(camera, center)));
+		lookat(camera, center, up);
+		mulm3(view, proj);
+		break;
 	}
 }
 
@@ -720,7 +745,7 @@
 void
 usage(void)
 {
-	fprint(2, "usage: %s [-n nprocs] [-m objfile] [-t texfile] [-a yrotangle] [-z camzpos] [-s shader] [-w width] [-h height] [-S scale]\n", argv0);
+	fprint(2, "usage: %s [-n nprocs] [-m objfile] [-t texfile] [-a yrotangle] [-s shader] [-w width] [-h height] [-S scale]\n", argv0);
 	exits("usage");
 }
 
@@ -759,9 +784,6 @@
 	case 'v':
 		ω = strtod(EARGF(usage()), nil)*DEG;
 		break;
-	case 'z':
-		camera.z = strtod(EARGF(usage()), nil);
-		break;
 	case 's':
 		sname = EARGF(usage());
 		break;
@@ -823,7 +845,6 @@
 
 	viewport(screenfb->r);
 	projection(-1.0/vec3len(subpt3(camera, center)));
-	identity3(rota);
 	lookat(camera, center, up);
 	mulm3(view, proj);
 	light = normvec3(subpt3(light, center));