-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterial.c
More file actions
69 lines (60 loc) · 1.9 KB
/
Copy pathmaterial.c
File metadata and controls
69 lines (60 loc) · 1.9 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
/*
* material.c
*
* Initialize and dump fucntion for material struct.
*
* Chris Blades
*
* 31/3/2011
*/
#include <stdio.h>
#include "common.h"
#include "material.h"
/**
* Initialize a material struct by reading in ambient, diffuse, and specular
* rgb values from a file.
*
* PARAMETERS:
* in - file to read from
* mat - material struct to initialize
*/
void material_init(FILE *in, material_t *mat) {
char buf[256]; // buffer to read into
int rc = 0; // read counter
while (rc != 3) {
rc = fscanf(in, "%lf %lf %lf", mat->ambient, (mat->ambient + 1),
(mat->ambient + 2) );
fgets(buf, 256, in);
}
rc = 0;
while (rc != 3) {
rc = fscanf(in, "%lf %lf %lf", mat->diffuse, (mat->diffuse + 1),
(mat->diffuse + 2) );
fgets(buf, 256, in);
}
rc = 0;
while (rc != 3) {
rc = fscanf(in, "%lf %lf %lf", mat->specular, (mat->specular + 1),
(mat->specular + 2) );
fgets(buf, 256, in);
}
}
/*
* Print information in a material struct.
*
* PARAMETERS:
* out - file to write to
* mat - material struct to dump
*/
void material_dump(FILE *out, material_t *mat) {
fprintf(out, "\tMATERIAL: \n");
fprintf(out, "\t\tAmbient {%lf, %lf, %lf}\n", mat->ambient[0],
mat->ambient[1],
mat->ambient[2]);
fprintf(out, "\t\tDiffuse {%lf, %lf, %lf}\n", mat->diffuse[0],
mat->diffuse[1],
mat->diffuse[2]);
fprintf(out, "\t\tSpecular {%lf, %lf, %lf}\n", mat->specular[0],
mat->specular[1],
mat->specular[2]);
}