*/
struct light
{
- color_t color;
- vec_t position;
+ vec_t v; // position
+ color_t d; // diffuse
+ color_t s; // specular
};
typedef struct light light_t;
-
/*
- * Initialize a light with a color and position.
+ * Initialize a light with a position and color.
*/
INLINE_MAYBE
-void light_init(light_t* l, color_t color, vec_t position)
+void light_init(light_t* l, vec_t position, color_t diffuse, color_t specular)
{
- l->color = color;
- l->position = position;
+ l->v = position;
+ l->d = diffuse;
+ l->s = specular;
}
/*
- * Create a new light with a color and position.
+ * Create a new light with a position and color.
*/
INLINE_MAYBE
-light_t light_new(color_t color, vec_t position)
+light_t light_new(vec_t position, color_t diffuse, color_t specular)
{
light_t l;
- light_init(&l, color, position);
+ light_init(&l, position, diffuse, specular);
return l;
}
+/*
+ * Create a new light on the heap.
+ */
+INLINE_MAYBE
+light_t* light_alloc(vec_t position, color_t diffuse, color_t specular)
+{
+ light_t* l = (light_t*)mem_alloc(sizeof(light_t));
+ light_init(l, position, diffuse, specular);
+ return l;
+}
+
+INLINE_MAYBE
+light_t* light_copy(light_t l)
+{
+ light_t* n = (light_t*)mem_alloc(sizeof(light_t));
+ memcpy(n, &l, sizeof(light_t));
+ return n;
+}
+
+
#endif // _LIGHT_H_