diff options
author | rodri <rgl@antares-labs.eu> | 2023-12-28 21:06:21 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2023-12-28 21:06:21 +0000 |
commit | de87611a25e3ce983d5bbd0e7173d8bfb131cc2a (patch) | |
tree | 7a354c316885b3a4c0a24b5a37ade3d842ed308f /main.c | |
parent | 9afe489f2612d54d4ecf21cf426f908d7140992a (diff) | |
download | tinyrend-de87611a25e3ce983d5bbd0e7173d8bfb131cc2a.tar.gz tinyrend-de87611a25e3ce983d5bbd0e7173d8bfb131cc2a.tar.bz2 tinyrend-de87611a25e3ce983d5bbd0e7173d8bfb131cc2a.zip |
add keys to move the camera around.
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 31 |
1 files changed, 26 insertions, 5 deletions
@@ -165,6 +165,7 @@ lookat(Point3 eye, Point3 o, Point3 up) 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,13 +715,37 @@ key(Rune r) 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; } } 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 @@ threadmain(int argc, char *argv[]) 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 @@ threadmain(int argc, char *argv[]) viewport(screenfb->r); projection(-1.0/vec3len(subpt3(camera, center))); - identity3(rota); lookat(camera, center, up); mulm3(view, proj); light = normvec3(subpt3(light, center)); |