]>
Dogcows Code - chaz/rasterize/blob - element.hh
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
22 * A base class for an object in a scene.
32 * Determine if a ray intersects this element.
34 virtual bool intersect(ray_t ray
, contact_t
& hit
) const = 0;
37 * Get the material color of the element at a surface point.
39 virtual color_t
color(vec_t point
) const
45 * Cast a ray to this element, returning the correct color value.
47 color_t
cast(const contact_t
& hit
, const scene_t
* scene
) const
49 color_t Ia
= color_mult(scene_ambient(scene
), color(hit
.p
));
50 color_t Id
= diffuse(hit
, scene
);
51 return color_clamp(color_add(Ia
, Id
));
55 * Get whether or not a particular surface point is shadowed by other
56 * objects for a given light source.
58 bool is_shadowed(const contact_t
& hit
, const scene_t
* scene
, const light_t
* light
) const
61 ray_t ray
= ray_normalize(ray_new(hit
.p
, vec_sub(light
->v
, hit
.p
)));
62 for (list_t
* i
= scene_elements(scene
); i
; i
= i
->link
) {
63 rt::element
* obj
= (rt::element
*)i
->val
;
65 if (this != obj
&& obj
->intersect(ray
, hit
)) {
75 * Get the color of the element at a surface point after diffuse
78 color_t
diffuse(const contact_t
& hit
, const scene_t
* scene
) const
80 color_t kd
= color(hit
.p
);
81 vec_t n
= vec_normalize(hit
.n
);
83 color_t c
= COLOR_BLACK
;
85 for (list_t
* i
= scene_lights(scene
); i
; i
= i
->link
) {
86 light_t
* l
= (light_t
*)i
->val
;
87 if (!is_shadowed(hit
, scene
, l
)) {
88 vec_t I
= vec_normalize(vec_sub(l
->v
, hit
.p
));
89 scal_t dot
= scal_max(vec_dot(I
, n
), S(0.0));
90 color_t Id
= color_scale2(kd
, l
->d
, dot
);
102 #endif // _ELEMENT_HH_
This page took 0.036307 seconds and 4 git commands to generate.