]>
Dogcows Code - chaz/rasterize/blob - scene.cc
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
17 static int _scene_add_light(scene_t
* s
, FILE* file
);
18 static int _scene_add_sphere(scene_t
* s
, FILE* file
);
19 static int _scene_add_plane(scene_t
* s
, FILE* file
);
35 scene_t
* scene_alloc(FILE* file
)
38 double eyeX
, eyeY
, eyeZ
, spotX
, spotY
, spotZ
, upX
, upY
, upZ
;
41 if (fscanf(file
, "U5 %d %d %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
43 &eyeX
, &eyeY
, &eyeZ
, &spotX
, &spotY
, &spotZ
, &upX
, &upY
, &upZ
,
45 &aR
, &aG
, &aB
) != 16) {
46 fprintf(stderr
, "Cannot read scene header.\n");
50 scene_t
* s
= (scene_t
*)mem_alloc(sizeof(scene_t
));
53 s
->eye
= vec_new(eyeX
, eyeY
, eyeZ
);
54 s
->spot
= vec_new(spotX
, spotY
, spotZ
);
55 s
->up
= vec_new(upX
, upY
, upZ
);
56 // what to do with fovy and aspect...
60 s
->ambient
= color_new((scal_t
)aR
, (scal_t
)aG
, (scal_t
)aB
, S(1.0));
63 while (fscanf(file
, " %c", &type
) == 1) {
66 if (_scene_add_light(s
, file
) != 0) {
72 if (_scene_add_sphere(s
, file
) != 0) {
78 if (_scene_add_plane(s
, file
) != 0) {
87 fprintf(stderr
, "Unknown identifier: %c\n", type
);
93 if (s
->spheres
) list_reverse(&s
->spheres
);
94 if (s
->planes
) list_reverse(&s
->planes
);
102 void scene_destroy(scene_t
* s
)
104 if (s
->lights
) list_destroy(&s
->lights
);
105 if (s
->spheres
) list_destroy(&s
->spheres
);
106 if (s
->planes
) list_destroy(&s
->planes
);
112 * Add a light to the scene.
114 static int _scene_add_light(scene_t
* s
, FILE* file
)
116 double lx
, ly
, lz
, r
, g
, b
;
117 if (fscanf(file
, " %lf %lf %lf %lf %lf %lf",
118 &lx
, &ly
, &lz
, &r
, &g
, &b
) != 6) {
119 fprintf(stderr
, "Cannot read light values from scene.\n");
122 light_t
* l
= light_alloc(
124 color_new((scal_t
)r
, (scal_t
)g
, (scal_t
)b
, S(1.0)),
125 color_new((scal_t
)r
, (scal_t
)g
, (scal_t
)b
, S(1.0))
127 list_push2(&s
->lights
, l
, mem_free
);
131 static int _scene_add_sphere(scene_t
* s
, FILE* file
)
133 double x
, y
, z
, radius
, r
, g
, b
;
134 if (fscanf(file
, " %lf %lf %lf %lf %lf %lf %lf",
135 &x
, &y
, &z
, &radius
, &r
, &g
, &b
) != 7) {
136 fprintf(stderr
, "Cannot read sphere values from scene.\n");
139 /*list_push2(&s->spheres, s, mem_free);*/
143 static int _scene_add_plane(scene_t
* s
, FILE* file
)
145 double x
, y
, z
, nx
, ny
, nz
, r
, g
, b
;
146 if (fscanf(file
, " %lf %lf %lf %lf %lf %lf %lf %lf %lf",
147 &x
, &y
, &z
, &nx
, &ny
, &nz
, &r
, &g
, &b
) != 9) {
148 fprintf(stderr
, "Cannot read plane values from scene.\n");
151 /*list_push2(&s->planes, s, mem_free);*/
156 raster_t
* scene_render(scene_t
* s
)
162 raster_t
* p
= raster_alloc(s
->w
, s
->h
, COLOR_BLACK
);
164 /*for (list_t* i = s->lights; i; i = i->link) {*/
165 /*raster_light(p, *(light_t*)i->val);*/
169 printf("rendering scene...\n");
175 long dt
= timer_stop();
176 printf("render complete!\ntime\t%.3fms\n", (float)dt
/ 1000.0f
);
This page took 0.04231 seconds and 4 git commands to generate.