diff options
author | Julian T <julian@jtle.dk> | 2020-02-21 06:55:27 +0100 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2020-02-21 06:55:27 +0100 |
commit | 623fee395425ab33f14fb9cd8ffa790e362f59d7 (patch) | |
tree | c70b64e13fd5e00c2317fa40ee4b8cd786e635d5 /scene.c | |
parent | 63a84080f9f0e3d719d5470e370584a5eff18a47 (diff) |
Added pgm drawing and got light ray tracing working
Still needs correct light simulation and reflections
Diffstat (limited to 'scene.c')
-rw-r--r-- | scene.c | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -0,0 +1,56 @@ +#include "scene.h" + +#include <stdlib.h> + +static inline void link_object(space_t *s, object_t *o) +{ + if (s) { + o->next = s->objects; + s->objects = o; + } else { + o->next = 0; + } +} + +object_t *add_sphere(space_t *s, vector_t *c, COORD_T r) +{ + object_t *o = (object_t *) malloc(sizeof(object_t)); + + o->type = TYPE_SPHERE; + o->sph.center = c; + o->sph.radius = r; + + link_object(s, o); + + return o; +} + +object_t *add_plane(space_t *s, vector_t *start, vector_t *dir) +{ + object_t *o = (object_t *) malloc(sizeof(object_t)); + + o->type = TYPE_PLANE; + o->pl.start = start; + o->pl.norm = dir; + + link_object(s, o); + + return o; +} + +light_t *add_light(space_t *s, vector_t *pos, color_t *c) +{ + light_t *o = (light_t *) malloc(sizeof(light_t)); + + o->pos = pos; + o->col = c; + + if (s) { + o->next = s->lights; + s->lights = o; + } else { + o->next = NULL; + } + + return o; +} |