-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.c
121 lines (102 loc) · 3.51 KB
/
compile.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "compile.h"
#include <stdio.h>
void llist_append(struct llist *a_llist, struct node *a_node)
{
if(a_llist->head == NULL) {
a_llist->head = a_node;
a_llist->tail = a_llist->head;
a_llist->size = 1;
} else {
a_llist->tail->next = a_node;
a_llist->tail = a_node;
a_llist->size++;
}
}
struct node *compile_sphere(const struct sphere *a_sphere)
{
struct node *sphere_node = (struct node *)calloc(1, sizeof(struct node));
sphere_node->upper.s[0] = SHAPE_SPHERE;
sphere_node->upper.s[1] = a_sphere->position.s[0];
sphere_node->upper.s[2] = a_sphere->position.s[1];
sphere_node->upper.s[3] = a_sphere->position.s[2];
sphere_node->upper.s[4] = a_sphere->radius;
// 5 - 15 are padding
sphere_node->lower.s[0] = a_sphere->color.s[0];
sphere_node->lower.s[1] = a_sphere->color.s[1];
sphere_node->lower.s[2] = a_sphere->color.s[2];
sphere_node->lower.s[3] = a_sphere->color.s[3];
sphere_node->lower.s[4] = a_sphere->material_type;
// 5 - 15 are padding
sphere_node->next = NULL;
return sphere_node;
}
struct node *compile_box(const struct box *a_box)
{
struct node *box_node = (struct node *)calloc(1, sizeof(struct node));
box_node->upper.s[0] = SHAPE_BOX;
box_node->upper.s[1] = a_box->position.s[0];
box_node->upper.s[2] = a_box->position.s[1];
box_node->upper.s[3] = a_box->position.s[2];
box_node->upper.s[4] = a_box->vmin.s[0];
box_node->upper.s[5] = a_box->vmin.s[1];
box_node->upper.s[6] = a_box->vmin.s[2];
box_node->upper.s[7] = a_box->vmax.s[0];
box_node->upper.s[8] = a_box->vmax.s[1];
box_node->upper.s[9] = a_box->vmax.s[2];
// 10 - 15 are padding
box_node->lower.s[0] = a_box->color.s[0];
box_node->lower.s[1] = a_box->color.s[1];
box_node->lower.s[2] = a_box->color.s[2];
box_node->lower.s[3] = a_box->color.s[3];
box_node->lower.s[4] = a_box->material_type;
// 5 - 15 are padding
box_node->next = NULL;
return box_node;
}
struct node *compile_plane(const struct plane *a_plane)
{
struct node *plane_node = (struct node *)calloc(1, sizeof(struct node));
plane_node->upper.s[0] = SHAPE_PLANE;
plane_node->upper.s[1] = a_plane->position.s[0];
plane_node->upper.s[2] = a_plane->position.s[1];
plane_node->upper.s[3] = a_plane->position.s[2];
plane_node->upper.s[4] = a_plane->normal.s[0];
plane_node->upper.s[5] = a_plane->normal.s[1];
plane_node->upper.s[6] = a_plane->normal.s[2];
// 7 - 15 are padding
plane_node->lower.s[0] = a_plane->color.s[0];
plane_node->lower.s[1] = a_plane->color.s[1];
plane_node->lower.s[2] = a_plane->color.s[2];
plane_node->lower.s[3] = a_plane->color.s[3];
plane_node->lower.s[4] = a_plane->material_type;
// 5 - 15 are padding
plane_node->next = NULL;
return plane_node;
}
void llist_delete(struct llist *a_llist)
{
while(a_llist->head) {
struct node *jlvwnnoooo = a_llist->head;
a_llist->head = a_llist->head->next;
free(jlvwnnoooo);
}
free(a_llist);
}
//struct llist *get_compiled_scene(struct llist *a_llist)
//{
// struct sphere my_sphere = {
// .position = { 0.0f, 0.0f, 4.0f },
// .radius = 1.0f,
// .color = { 1.0f, 0.0f, 0.0f, 1.0f },
// .material_type = MATTE
// };
//
// struct sphere my_light = {
// .position = { 2.0f, 3.0f, 3.0f },
// .radius = 0.3f,
// .color = { 1.0f, 1.0f, 1.0f, 1.0f },
// .material_type = LIGHT
// };
//
// struct
//}