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