From ca13877c19ca6d5e06b6f4364e56c9d211a48efa Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 7 Sep 2013 22:22:27 -0700 Subject: [PATCH] Add texture to objects --- src/object.c | 27 +++++++++++++++++++++++++++ src/object.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/src/object.c b/src/object.c index 809d8c9..544c1b0 100644 --- a/src/object.c +++ b/src/object.c @@ -9,6 +9,7 @@ #include #include #include + #include "basics.h" #include "object.h" @@ -16,6 +17,7 @@ struct _Object { ObjectType type; Vector3 location; + Texture *texture; void *shape; int (*does_intersect)(Object *obj, Ray ray, float **t); @@ -42,6 +44,10 @@ object_init(ObjectType type) return NULL; } + obj->type = type; + obj->location = ZeroVector3; + obj->texture = NULL; + switch (type) { case ObjectTypeSphere: { Sphere *s = malloc(sizeof(Sphere)); @@ -98,6 +104,27 @@ object_set_location(Object *obj, Vector3 location) } +/* + * object_get_texture -- + * object_set_texture -- + * + * Get and set the object's texture. + */ +Texture * +object_get_texture(Object *obj) +{ + assert(obj != NULL); + return obj->texture; +} + +void +object_set_texture(Object *obj, Texture *tex) +{ + assert(obj != NULL); + obj->texture = tex; +} + + /* * object_does_intersect -- * diff --git a/src/object.h b/src/object.h index 4e3e2fd..8fd7240 100644 --- a/src/object.h +++ b/src/object.h @@ -10,6 +10,7 @@ #define __OBJECT_H #include "basics.h" +#include "texture.h" typedef enum { @@ -24,6 +25,8 @@ void object_destroy(Object *obj); Vector3 object_get_location(Object *obj); void object_set_location(Object *obj, Vector3 location); +Texture *object_get_texture(Object *obj); +void object_set_texture(Object *obj, Texture *tex); int object_does_intersect(Object *obj, Ray ray, float **t);