-
Notifications
You must be signed in to change notification settings - Fork 0
/
scene.c
67 lines (53 loc) · 1.46 KB
/
scene.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "scene.h"
struct scene_objects {
int num_objects;
struct object* objects;
};
struct scene_objects scene;
struct colour
colour_function(struct ray* ray, struct object* obj)
{
if (scene.num_objects == 0) {
return (struct colour) {};
}
struct colour scene_colour = scene.objects[0].col(ray, &scene.objects[0]);
double min = DBL_MAX;
for (int i = 0; i < scene.num_objects; i++) {
double distance = solid_dist(&(scene.objects[i].sol), ray->pos);
if (distance < min) {
min = distance;
scene_colour = solid_col(scene.objects + i, ray);
}
}
return scene_colour;
}
double
distance_function(struct vec* position)
{
double min = DBL_MAX;
for (int i = 0; i < scene.num_objects; i++) {
double distance = solid_dist(&(scene.objects[i].sol), position);
if (distance < min) {
min = distance;
}
}
return min;
}
struct object *
new_scene(int num_scene_objects, struct object* scene_objects)
{
scene.num_objects = num_scene_objects;
scene.objects = scene_objects;
/*
for (int i = 0; i < num_scene_objects; i++) {
place(&(scene.objects[i].sol));
}
*/
struct object *scene_rep = malloc(sizeof(struct object));
scene_rep->sol.dist = distance_function;
scene_rep->sol.op = B_ADD;
scene_rep->sol.rotation = 0;
scene_rep->sol.scale = 1;
scene_rep->col = colour_function;
return scene_rep;
}