diff options
-rw-r--r-- | cubemap/skybox/back.jpg | bin | 0 -> 473329 bytes | |||
-rw-r--r-- | cubemap/skybox/bottom.jpg | bin | 0 -> 280589 bytes | |||
-rwxr-xr-x | cubemap/skybox/conv | 3 | ||||
-rw-r--r-- | cubemap/skybox/front.jpg | bin | 0 -> 740068 bytes | |||
-rw-r--r-- | cubemap/skybox/left.jpg | bin | 0 -> 601885 bytes | |||
-rw-r--r-- | cubemap/skybox/right.jpg | bin | 0 -> 538038 bytes | |||
-rw-r--r-- | cubemap/skybox/top.jpg | bin | 0 -> 346139 bytes | |||
-rw-r--r-- | cubemap/solar/back.jpg | bin | 0 -> 577592 bytes | |||
-rw-r--r-- | cubemap/solar/bottom.jpg | bin | 0 -> 131500 bytes | |||
-rwxr-xr-x | cubemap/solar/conv | 3 | ||||
-rw-r--r-- | cubemap/solar/front.jpg | bin | 0 -> 444175 bytes | |||
-rw-r--r-- | cubemap/solar/left.jpg | bin | 0 -> 533090 bytes | |||
-rw-r--r-- | cubemap/solar/right.jpg | bin | 0 -> 652341 bytes | |||
-rw-r--r-- | cubemap/solar/top.jpg | bin | 0 -> 137533 bytes | |||
-rw-r--r-- | med.c | 12 | ||||
-rw-r--r-- | solar.c | 18 | ||||
-rw-r--r-- | vis.c | 38 |
17 files changed, 51 insertions, 23 deletions
diff --git a/cubemap/skybox/back.jpg b/cubemap/skybox/back.jpg Binary files differnew file mode 100644 index 0000000..4e17b77 --- /dev/null +++ b/cubemap/skybox/back.jpg diff --git a/cubemap/skybox/bottom.jpg b/cubemap/skybox/bottom.jpg Binary files differnew file mode 100644 index 0000000..893f394 --- /dev/null +++ b/cubemap/skybox/bottom.jpg diff --git a/cubemap/skybox/conv b/cubemap/skybox/conv new file mode 100755 index 0000000..2cb32ea --- /dev/null +++ b/cubemap/skybox/conv @@ -0,0 +1,3 @@ +#!/bin/rc +for(f in *.jpg) <$f jpg -t9 >`{echo $f | sed 's/jpg/pic/g'} +chmod +t *.pic diff --git a/cubemap/skybox/front.jpg b/cubemap/skybox/front.jpg Binary files differnew file mode 100644 index 0000000..470a679 --- /dev/null +++ b/cubemap/skybox/front.jpg diff --git a/cubemap/skybox/left.jpg b/cubemap/skybox/left.jpg Binary files differnew file mode 100644 index 0000000..5750b91 --- /dev/null +++ b/cubemap/skybox/left.jpg diff --git a/cubemap/skybox/right.jpg b/cubemap/skybox/right.jpg Binary files differnew file mode 100644 index 0000000..8963037 --- /dev/null +++ b/cubemap/skybox/right.jpg diff --git a/cubemap/skybox/top.jpg b/cubemap/skybox/top.jpg Binary files differnew file mode 100644 index 0000000..4db3c2a --- /dev/null +++ b/cubemap/skybox/top.jpg diff --git a/cubemap/solar/back.jpg b/cubemap/solar/back.jpg Binary files differnew file mode 100644 index 0000000..fa3e9c7 --- /dev/null +++ b/cubemap/solar/back.jpg diff --git a/cubemap/solar/bottom.jpg b/cubemap/solar/bottom.jpg Binary files differnew file mode 100644 index 0000000..59cfe67 --- /dev/null +++ b/cubemap/solar/bottom.jpg diff --git a/cubemap/solar/conv b/cubemap/solar/conv new file mode 100755 index 0000000..2cb32ea --- /dev/null +++ b/cubemap/solar/conv @@ -0,0 +1,3 @@ +#!/bin/rc +for(f in *.jpg) <$f jpg -t9 >`{echo $f | sed 's/jpg/pic/g'} +chmod +t *.pic diff --git a/cubemap/solar/front.jpg b/cubemap/solar/front.jpg Binary files differnew file mode 100644 index 0000000..07107d6 --- /dev/null +++ b/cubemap/solar/front.jpg diff --git a/cubemap/solar/left.jpg b/cubemap/solar/left.jpg Binary files differnew file mode 100644 index 0000000..31397f0 --- /dev/null +++ b/cubemap/solar/left.jpg diff --git a/cubemap/solar/right.jpg b/cubemap/solar/right.jpg Binary files differnew file mode 100644 index 0000000..558b374 --- /dev/null +++ b/cubemap/solar/right.jpg diff --git a/cubemap/solar/top.jpg b/cubemap/solar/top.jpg Binary files differnew file mode 100644 index 0000000..89cc3c8 --- /dev/null +++ b/cubemap/solar/top.jpg @@ -243,7 +243,7 @@ gouraudvshader(VSparams *sp) diffuse.a *= m->diffuse.a; } - lookdir = normvec3(subpt3(cam.p, pos)); + lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = qrotate(lightdir, sp->v->n, PI); spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m? m->shininess: 1); specular = mulpt3(light.c, spec*Ks); @@ -255,7 +255,7 @@ gouraudvshader(VSparams *sp) } sp->v->c = addpt3(ambient, addpt3(diffuse, specular)); - return world2clip(&cam, pos); + return world2clip(sp->su->camera, pos); } Color @@ -299,7 +299,7 @@ phongvshader(VSparams *sp) addvattr(sp->v, "specular", VAPoint, &s); addvattr(sp->v, "shininess", VANumber, &ss); } - return world2clip(&cam, pos); + return world2clip(sp->su->camera, pos); } Color @@ -340,7 +340,7 @@ phongshader(FSparams *sp) diffuse.b *= m.diffuse.b; diffuse.a *= m.diffuse.a; - lookdir = normvec3(subpt3(cam.p, pos)); + lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = qrotate(lightdir, sp->v.n, PI); spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m.shininess); specular = mulpt3(light.c, spec*Ks); @@ -372,7 +372,7 @@ identvshader(VSparams *sp) sp->v->p = model2world(sp->su->entity, sp->v->p); if(sp->v->mtl != nil) sp->v->c = sp->v->mtl->diffuse; - return world2clip(&cam, sp->v->p); + return world2clip(sp->su->camera, sp->v->p); } Color @@ -777,7 +777,7 @@ threadmain(int argc, char *argv[]) v = mkviewport(screenb->r); placecamera(&cam, camcfg.p, camcfg.lookat, camcfg.up); configcamera(&cam, v, camcfg.fov, camcfg.clipn, camcfg.clipf, camcfg.ptype); - cam.s = scene; + cam.scene = scene; cam.rctl = rctl; light.p = Pt3(0,100,100,1); light.c = Pt3(1,1,1,1); @@ -109,6 +109,14 @@ Rune keys[Ke] = { [Kzoomout] = 'x', [Khud] = 'h', }; +char *skyboxpaths[] = { + "cubemap/solar/left.pic", + "cubemap/solar/right.pic", + "cubemap/solar/bottom.pic", + "cubemap/solar/top.pic", + "cubemap/solar/front.pic", + "cubemap/solar/back.pic", +}; Planet planets[] = { { .id = 10, .name = "Sol", .scale = 695700 }, { .id = 1, .name = "Mercury", .scale = 2439.4 }, @@ -149,6 +157,7 @@ Point3 center = {0,0,0,1}; double speed = 10; static int museummode; +static int showskybox; static int doprof; static int showhud; @@ -334,7 +343,7 @@ identvshader(VSparams *sp) sp->v->mtl = p->mtl; sp->v->c = p->mtl->diffuse; - return world2clip(&camera, model2world(sp->su->entity, pos)); + return world2clip(sp->su->camera, model2world(sp->su->entity, pos)); } Color @@ -730,7 +739,7 @@ confproc(void) void usage(void) { - fprint(2, "usage: %s [-m]\n", argv0); + fprint(2, "usage: %s [-ms]\n", argv0); exits("usage"); } @@ -750,6 +759,7 @@ threadmain(int argc, char *argv[]) GEOMfmtinstall(); ARGBEGIN{ case 'm': museummode++; break; + case 's': showskybox++; break; case 'p': doprof++; break; default: usage(); }ARGEND; @@ -790,6 +800,8 @@ threadmain(int argc, char *argv[]) snprint(datestr, sizeof datestr, "%τ", tmfmt(&date, datefmt)); if(!museummode) updateplanets(); + if(showskybox) + scene->skybox = readcubemap(skyboxpaths); if(memimageinit() != 0) sysfatal("memimageinit: %r"); @@ -816,7 +828,7 @@ threadmain(int argc, char *argv[]) v = mkviewport(screenb->r); placecamera(&camera, cameracfg.p, cameracfg.lookat, cameracfg.up); configcamera(&camera, v, cameracfg.fov, cameracfg.clipn, cameracfg.clipf, cameracfg.ptype); - camera.s = scene; + camera.scene = scene; camera.rctl = rctl; gotoplanet(getplanet("Sol")); @@ -40,6 +40,14 @@ Rune keys[Ke] = { [Kcam3] = KF|4, [Khud] = 'h', }; +char *skyboxpaths[] = { + "cubemap/skybox/left.pic", + "cubemap/skybox/right.pic", + "cubemap/skybox/bottom.pic", + "cubemap/skybox/top.pic", + "cubemap/skybox/front.pic", + "cubemap/skybox/back.pic", +}; char stats[Se][256]; Image *screenb; Mousectl *mctl; @@ -78,6 +86,7 @@ Camcfg camcfgs[4] = { Point3 center = {0,0,0,1}; LightSource light; /* global point light */ +static int showskybox; static int doprof; static int inception; static int showhud; @@ -141,7 +150,7 @@ gouraudvshader(VSparams *sp) diffuse.a *= m->diffuse.a; } - lookdir = normvec3(subpt3(maincam->p, pos)); + lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = qrotate(lightdir, sp->v->n, PI); spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m? m->shininess: 1); specular = mulpt3(light.c, spec*Ks); @@ -153,7 +162,7 @@ gouraudvshader(VSparams *sp) } sp->v->c = addpt3(ambient, addpt3(diffuse, specular)); - return world2clip(maincam, pos); + return world2clip(sp->su->camera, pos); } Color @@ -201,7 +210,7 @@ phongvshader(VSparams *sp) addvattr(sp->v, "specular", VAPoint, &s); addvattr(sp->v, "shininess", VANumber, &ss); } - return world2clip(maincam, pos); + return world2clip(sp->su->camera, pos); } Color @@ -260,7 +269,7 @@ phongshader(FSparams *sp) diffuse.b *= m.diffuse.b; diffuse.a *= m.diffuse.a; - lookdir = normvec3(subpt3(maincam->p, pos)); + lookdir = normvec3(subpt3(sp->su->camera->p, pos)); lightdir = qrotate(lightdir, n, PI); spec = pow(fmax(0, dotvec3(lookdir, lightdir)), m.shininess); specular = mulpt3(light.c, spec*Ks); @@ -299,7 +308,7 @@ identvshader(VSparams *sp) addvattr(sp->v, "intensity", VANumber, &intens); if(sp->v->mtl != nil) sp->v->c = sp->v->mtl->diffuse; - return world2clip(maincam, pos); + return world2clip(sp->su->camera, pos); } Color @@ -340,7 +349,7 @@ ivshader(VSparams *sp) { sp->v->n = model2world(sp->su->entity, sp->v->n); sp->v->p = model2world(sp->su->entity, sp->v->p); - return world2clip(maincam, sp->v->p); + return world2clip(sp->su->camera, sp->v->p); } Color @@ -796,7 +805,7 @@ confproc(void) void usage(void) { - fprint(2, "usage: %s [-t texture] [-s shader] model...\n", argv0); + fprint(2, "usage: %s [-s] [-t texture] model...\n", argv0); exits("usage"); } @@ -808,15 +817,14 @@ threadmain(int argc, char *argv[]) Channel *keyc; Entity *subject; OBJ *obj; - char *texpath, *sname, *mdlpath; + char *texpath, *mdlpath; int i, fd; GEOMfmtinstall(); texpath = nil; - sname = "gouraud"; ARGBEGIN{ + case 's': showskybox++; break; case 't': texpath = EARGF(usage()); break; - case 's': sname = EARGF(usage()); break; case L'ι': inception++; break; case 'p': doprof++; break; default: usage(); @@ -826,15 +834,15 @@ threadmain(int argc, char *argv[]) confproc(); - if((shader = getshader(sname)) == nil) - sysfatal("couldn't find %s shader", sname); + if((shader = getshader("gouraud")) == nil) + sysfatal("couldn't find gouraud shader"); scene = newscene(nil); while(argc--){ mdlpath = argv[argc]; model = newmodel(); subject = newentity(model); - subject->p.x = argc*4; +// subject->p.x = argc*4; scene->addent(scene, subject); if((obj = objparse(mdlpath)) == nil) @@ -851,6 +859,8 @@ threadmain(int argc, char *argv[]) close(fd); } } + if(showskybox) + scene->skybox = readcubemap(skyboxpaths); if(memimageinit() != 0) sysfatal("memimageinit: %r"); @@ -866,7 +876,7 @@ threadmain(int argc, char *argv[]) v = mkviewport(screenb->r); placecamera(&cams[i], camcfgs[i].p, camcfgs[i].lookat, camcfgs[i].up); configcamera(&cams[i], v, camcfgs[i].fov, camcfgs[i].clipn, camcfgs[i].clipf, camcfgs[i].ptype); - cams[i].s = scene; + cams[i].scene = scene; cams[i].rctl = rctl; } maincam = &cams[3]; |