X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Frasterize;a=blobdiff_plain;f=scene.c;fp=scene.c;h=d079e17ac7c4788617beb42d6c1ff4665ddb428a;hp=85f15e6c02f093b61c7e7ddd1ac384faa80e0385;hb=95850b98f73ad7033af60a30e324e9c3cda55389;hpb=a0e6abd72f045a741fb1ecdd1c2d11281f2840b9 diff --git a/scene.c b/scene.c index 85f15e6..d079e17 100644 --- a/scene.c +++ b/scene.c @@ -39,10 +39,12 @@ scene_t* scene_alloc(FILE* file) int w, h; double eyeX, eyeY, eyeZ, spotX, spotY, spotZ, upX, upY, upZ; double fovy, aspect, near, far; - if (fscanf(file, "U3 %d %d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", + double aR, aG, aB; + if (fscanf(file, "U4 %d %d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf", &w, &h, &eyeX, &eyeY, &eyeZ, &spotX, &spotY, &spotZ, &upX, &upY, &upZ, - &fovy, &aspect, &near, &far) != 15) { + &fovy, &aspect, &near, &far, + &aR, &aG, &aB) != 18) { fprintf(stderr, "Cannot read scene header.\n"); return NULL; } @@ -57,7 +59,7 @@ scene_t* scene_alloc(FILE* file) s->eye = vec_new(eyeX, eyeY, eyeZ); s->projection = MAT_PERSPECTIVE((scal_t)fovy, (scal_t)aspect, (scal_t)near, (scal_t)far); s->lights = NULL; - s->ambient = color_new(S(0.05), S(0.05), S(0.05), S(1.0)); + s->ambient = color_new((scal_t)aR, (scal_t)aG, (scal_t)aB, S(1.0)); char filename[4096]; model_t* m = NULL; @@ -109,19 +111,13 @@ if (m == NULL) { \ } break; - case 'A': - if (_scene_set_ambient(s, file) != 0) { - goto fail; - } - break; - - case 'L': + case 'l': if (_scene_add_light(s, file) != 0) { goto fail; } break; - case 'M': + case 'p': _ASSERT_G; if (_model_set_material(m, file) != 0) { goto fail; @@ -138,6 +134,7 @@ if (m == NULL) { \ #undef _ASSERT_G done: + list_reverse(&s->models); return s; fail: @@ -158,18 +155,17 @@ void scene_destroy(scene_t* s) */ static int _model_set_colors(model_t* m, FILE* file) { - double r1, g1, b1, r2, g2, b2, r3, g3, b3; - if (fscanf(file, " %lf %lf %lf %lf %lf %lf %lf %lf %lf", - &r1, &g1, &b1, &r2, &g2, &b2, &r3, &g3, &b3) != 9) { + double a, r, g, b; + if (fscanf(file, " %lf %lf %lf %lf", &a, &r, &g, &b) != 4) { fprintf(stderr, "Cannot read color values from scene.\n"); return -1; } for (const list_t* i = model_geometry(m); i; i = i->link) { tri_t* t = (tri_t*)i->val; - t->a.c = color_new((colorchan_t)r1, (colorchan_t)g1, (colorchan_t)b1, S(1.0)); - t->b.c = color_new((colorchan_t)r2, (colorchan_t)g2, (colorchan_t)b2, S(1.0)); - t->c.c = color_new((colorchan_t)r3, (colorchan_t)g3, (colorchan_t)b3, S(1.0)); + t->a.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a); + t->b.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a); + t->c.c = color_new((colorchan_t)r, (colorchan_t)g, (colorchan_t)b, (colorchan_t)a); } return 0; } @@ -233,35 +229,21 @@ static int _model_set_material(model_t* m, FILE* file) return 0; } -/* - * Set the ambient light properties of a scene. - */ -static int _scene_set_ambient(scene_t* s, FILE* file) -{ - double r, g, b; - if (fscanf(file, " %lf %lf %lf", &r, &g, &b) != 3) { - fprintf(stderr, "Cannot read ambient light from scene.\n"); - return -1; - } - s->ambient = color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0)); - return 0; -} - /* * Add a light to the scene. */ static int _scene_add_light(scene_t* s, FILE* file) { - double lx, ly, lz, dr, dg, db, sr, sg, sb; - if (fscanf(file, " %lf %lf %lf %lf %lf %lf %lf %lf %lf", - &lx, &ly, &lz, &dr, &dg, &db, &sr, &sg, &sb) != 9) { + double lx, ly, lz, r, g, b; + if (fscanf(file, " %lf %lf %lf %lf %lf %lf", + &lx, &ly, &lz, &r, &g, &b) != 6) { fprintf(stderr, "Cannot read light values from scene.\n"); return -1; } light_t* l = light_alloc( vec_new(lx, ly, lz), - color_new(dr, dg, db, S(1.0)), - color_new(sr, sg, sb, S(1.0)) + color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0)), + color_new((scal_t)r, (scal_t)g, (scal_t)b, S(1.0)) ); list_push2(&s->lights, l, mem_free); return 0;