]> Dogcows Code - chaz/rasterize/blob - light.hh
finishing fifth project
[chaz/rasterize] / light.hh
1
2 /*
3 * CS5600 University of Utah
4 * Charles McGarvey
5 * mcgarvey@eng.utah.edu
6 */
7
8 #ifndef _LIGHT_HH_
9 #define _LIGHT_HH_
10
11 #include "color.hh"
12 #include "vec.hh"
13
14
15 /*
16 * A light source.
17 */
18 struct light
19 {
20 vec_t v; // position
21 color_t d; // diffuse
22 };
23 typedef struct light light_t;
24
25 /*
26 * Initialize a light with a position and color.
27 */
28 INLINE_MAYBE
29 void light_init(light_t* l, vec_t position, color_t diffuse)
30 {
31 l->v = position;
32 l->d = diffuse;
33 }
34
35
36 /*
37 * Create a new light with a position and color.
38 */
39 INLINE_MAYBE
40 light_t light_new(vec_t position, color_t diffuse)
41 {
42 light_t l;
43 light_init(&l, position, diffuse);
44 return l;
45 }
46
47
48 /*
49 * Create a new light on the heap.
50 */
51 INLINE_MAYBE
52 light_t* light_alloc(vec_t position, color_t diffuse)
53 {
54 light_t* l = (light_t*)mem_alloc(sizeof(light_t));
55 light_init(l, position, diffuse);
56 return l;
57 }
58
59 INLINE_MAYBE
60 light_t* light_copy(light_t l)
61 {
62 light_t* n = (light_t*)mem_alloc(sizeof(light_t));
63 memcpy(n, &l, sizeof(light_t));
64 return n;
65 }
66
67
68 #endif // _LIGHT_HH_
69
This page took 0.036619 seconds and 4 git commands to generate.