]>
Dogcows Code - chaz/rasterize/blob - sphere.hh
3 * CS5600 University of Utah
5 * mcgarvey@eng.utah.edu
18 * A class for a sphere object.
20 class sphere
: public element
27 sphere(vec_t o
, scal_t r
= S(1.0)) :
34 virtual bool intersect(ray_t ray
, contact_t
& hit
) const
36 vec_t b
= vec_sub(origin
, ray
.o
);
37 scal_t z
= vec_dot(b
, ray
.d
);
39 // check if the sphere is behind the ray
44 scal_t d2
= vec_dot(b
, b
) - z
* z
;
45 scal_t r2
= radius
* radius
;
47 // check for an intersection
52 hit
.d
= z
- std::sqrt(r2
- d2
);
57 hit
.p
= ray_solve(ray
, hit
.d
);
58 hit
.n
= vec_sub(hit
.p
, origin
);
62 virtual vec_t
txcoord(vec_t point
) const
66 scal_t theta
= scal_atan2(point
.z
, point
.x
);
67 scal_t phi
= asin(point
.y
/ radius
);
69 uv
.x
= theta
/ (S(2.0) * M_PI
) + S(0.5);
70 uv
.y
= phi
/ M_PI
+ S(0.5);
78 * Destroy a new'd sphere, releasing its memory.
81 void sphere_destroy(sphere
* s
)
This page took 0.03595 seconds and 4 git commands to generate.