aboutsummaryrefslogtreecommitdiff
path: root/scene.c
diff options
context:
space:
mode:
authorJulian T <julian@jtle.dk>2020-02-21 14:42:42 +0100
committerJulian T <julian@jtle.dk>2020-02-21 14:42:42 +0100
commit9b40029e42f994aeff59ecc44a6d3b8fba93071d (patch)
treec133f8f6190b445560c4d8438ba89d7caaa0a7cd /scene.c
parent623fee395425ab33f14fb9cd8ffa790e362f59d7 (diff)
Pretty realistic colors
Diffstat (limited to 'scene.c')
-rw-r--r--scene.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/scene.c b/scene.c
index a75b329..99ae0e8 100644
--- a/scene.c
+++ b/scene.c
@@ -12,11 +12,13 @@ static inline void link_object(space_t *s, object_t *o)
}
}
-object_t *add_sphere(space_t *s, vector_t *c, COORD_T r)
+object_t *add_sphere(space_t *s, vector_t *c, COORD_T r, material_t *m)
{
object_t *o = (object_t *) malloc(sizeof(object_t));
o->type = TYPE_SPHERE;
+ o->m = m;
+
o->sph.center = c;
o->sph.radius = r;
@@ -38,12 +40,12 @@ object_t *add_plane(space_t *s, vector_t *start, vector_t *dir)
return o;
}
-light_t *add_light(space_t *s, vector_t *pos, color_t *c)
+light_t *add_light(space_t *s, vector_t *pos, color_t *defuse)
{
light_t *o = (light_t *) malloc(sizeof(light_t));
o->pos = pos;
- o->col = c;
+ o->defuse = defuse;
if (s) {
o->next = s->lights;
@@ -54,3 +56,18 @@ light_t *add_light(space_t *s, vector_t *pos, color_t *c)
return o;
}
+
+void obj_norm_at(object_t *o, vector_t *dest, vector_t *point)
+{
+ switch(o->type) {
+ case TYPE_SPHERE:
+ vector_sub(dest, point, o->sph.center);
+ vector_scale_inv(dest, dest, vector_len(dest));
+ break;
+ case TYPE_PLANE:
+ vector_copy(dest, o->pl.norm);
+ break;
+ }
+
+ return;
+}