-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodel.cpp
More file actions
101 lines (68 loc) · 1.96 KB
/
model.cpp
File metadata and controls
101 lines (68 loc) · 1.96 KB
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
/* model.c - this file is given */
#include "ray.h"
extern int oparse;
#define NUM_ITEMS (sizeof(items) / sizeof(char *))
/* Load model data */
void model_t::model_load(FILE *in) {
char entity[16];
int count;
memset(entity, 0, sizeof(entity));
/* Here entity should be one of "material", */
/* "light", "plane" */
count = fscanf(in, "%s", entity);
while (count == 1)
{
model_load_entity(in, entity);
count = fscanf(in, "%s", entity);
}
}
void model_t::model_load_entity(FILE *in, char *entity) {
if (strcmp(entity, "camera") == 0)
cam = new camera_t(in);
else if (strcmp(entity, "material") == 0)
new material_t(in, this, 0);
else if (strcmp(entity, "plane") == 0)
new plane_t(in, this, 0);
/*else if (strcmp(entity, "pplane") == 0)
new pplane_t(in, this, 0);
*/
else if (strcmp(entity, "fplane") == 0)
new fplane_t(in, this, 0);
else if(strcmp(entity, "tiled_plane") == 0)
new tplane_t(in, this, 0);
else if (strcmp(entity, "sphere") == 0)
new sphere_t(in, this, 0);
else if (strcmp(entity, "light") == 0)
new light_t(in, this, 0);
else if (strcmp(entity, "spotlight") == 0)
new spotlight_t(in, this, 0);
else if(strcmp(entity, "texplane") == 0)
new texplane_t(in, this, 0);
else if(strcmp(entity, "texture") == 0)
new texture_t(in, this, 0);
else {
fprintf(stderr, "bad entity %s \n", entity);
exit(1);
}
return;
}
/* Init model data */
model_t::model_t(FILE *in) {
mats = new list_t;
assert(mats != NULL);
lgts = new list_t;
assert(lgts != NULL);
objs = new list_t;
assert(objs != NULL);
texs = new list_t;
assert(texs != NULL);
model_load(in);
}
/* print model data */
void model_t::print(FILE *out) {
cam->camera_print(out);
material_list_print(this, out);
object_list_print(this, out);
light_list_print(this, out);
//texplane_list_print(this,out);
}