]>
Dogcows Code - chaz/rasterize/blob - sphere.hh
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
19 * A class for a sphere object.
21 class sphere
: public element
29 sphere(vec_t o
, scal_t r
= S(1.0), color_t color
= COLOR_WHITE
) :
30 origin(o
), radius(r
), material(color
)
36 virtual bool intersect(ray_t ray
, contact_t
& hit
) const
38 vec_t b
= vec_sub(origin
, ray
.o
);
39 scal_t z
= vec_dot(b
, ray
.d
);
41 // check if the sphere is behind the ray
46 scal_t d2
= vec_dot(b
, b
) - z
* z
;
47 scal_t r2
= radius
* radius
;
49 // check for an intersection
54 hit
.d
= z
- std::sqrt(r2
- d2
);
59 hit
.p
= ray_solve(ray
, hit
.d
);
60 hit
.n
= vec_sub(hit
.p
, origin
);
64 virtual color_t
color(vec_t point
) const
72 * Destroy a new'd sphere, releasing its memory.
75 void sphere_destroy(sphere
* s
)
This page took 0.036238 seconds and 4 git commands to generate.