]> Dogcows Code - chaz/rasterize/blob - ray.hh
finishing fifth project
[chaz/rasterize] / ray.hh
1
2 /*
3 * CS5600 University of Utah
4 * Charles McGarvey
5 * mcgarvey@eng.utah.edu
6 */
7
8 #ifndef _RAY_HH_
9 #define _RAY_HH_
10
11 #include "vec.hh"
12
13
14 /*
15 * A simple ray class.
16 */
17 struct ray
18 {
19 vec_t o;
20 vec_t d;
21 };
22 typedef struct ray ray_t;
23
24 /*
25 * Initialize a ray with an origin point and a direction.
26 */
27 INLINE_MAYBE
28 void ray_init(ray_t* r, vec_t origin, vec_t direction)
29 {
30 r->o = origin;
31 r->d = direction;
32 }
33
34
35 /*
36 * Create a new ray with an origin point and a direction.
37 */
38 INLINE_MAYBE
39 ray_t ray_new(vec_t origin, vec_t direction)
40 {
41 ray_t r;
42 ray_init(&r, origin, direction);
43 return r;
44 }
45
46
47 /*
48 * Normalize the direction of a ray.
49 */
50 INLINE_MAYBE
51 ray_t ray_normalize(ray_t r)
52 {
53 return ray_new(r.o, vec_normalize(r.d));
54 }
55
56
57 /*
58 * Solve for a point along the array, given a distance. The ray must be
59 * normalized for this to work as expected.
60 */
61 INLINE_MAYBE
62 vec_t ray_solve(ray_t r, scal_t distance)
63 {
64 return vec_add(r.o, vec_scale(r.d, distance));
65 }
66
67
68 #endif // _RAY_HH_
69
This page took 0.041479 seconds and 4 git commands to generate.