Create obj module for scene objects
This commit is contained in:
35
include/obj.h
Normal file
35
include/obj.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef OBJ_H
|
||||
#define OBJ_H
|
||||
|
||||
#include "ray.h"
|
||||
|
||||
#define SPHERE(x, y, z, r) \
|
||||
{ \
|
||||
.intersect = intersect_sphere, \
|
||||
.params = { \
|
||||
.sphere = { .centre = { x, y, z }, .radius = r }, \
|
||||
}, \
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
vec3_t point, normal;
|
||||
double t;
|
||||
} hit_t;
|
||||
|
||||
typedef struct {
|
||||
vec3_t centre;
|
||||
double radius;
|
||||
} sphere_params_t;
|
||||
|
||||
typedef union {
|
||||
sphere_params_t sphere;
|
||||
} obj_params_t;
|
||||
|
||||
typedef struct {
|
||||
bool (*intersect)(obj_params_t params, ray_t ray, hit_t *hit_out);
|
||||
obj_params_t params;
|
||||
} obj_t;
|
||||
|
||||
bool intersect_sphere(obj_params_t params, ray_t ray, hit_t *hit_out);
|
||||
|
||||
#endif
|
||||
10
include/ray.h
Normal file
10
include/ray.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef RAY_H
|
||||
#define RAY_H
|
||||
|
||||
#include "vec3.h"
|
||||
|
||||
typedef struct {
|
||||
vec3_t orig, dir;
|
||||
} ray_t;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user