Add texture to objects
This commit is contained in:
parent
7b30584ba5
commit
ca13877c19
2 changed files with 30 additions and 0 deletions
27
src/object.c
27
src/object.c
|
@ -9,6 +9,7 @@
|
|||
#include <assert.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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 --
|
||||
*
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue