-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetparams_para.c
125 lines (104 loc) · 2.72 KB
/
getparams_para.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
122
123
124
/*
This file is part of the Mandelbox program developed for the course
CS/SE Distributed Computer Systems taught by N. Nedialkov in the
Winter of 2015 at McMaster University.
Copyright (C) 2015 T. Gwosdz and N. Nedialkov
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "renderer_para.h"
#include "mandelbox_para.h"
#include "camera.h"
#define BUF_SIZE 1024
static char buf[BUF_SIZE];
void getParameters(char *filename, CameraParams *camP, RenderParams *renP, MandelBoxParams *boxP)
{
printf("getting parameters...\n");
FILE *fp;
int ret;
double *d;
renP->fractalType = 0;
renP->maxRaySteps = 2000;
renP->maxDistance = 100;
fp = fopen(filename,"r");
if( !fp )
{
printf(" *** File %s does not exist\n", filename);
exit(1);
}
int count = 0;
while (1)
{
memset(buf, 0, BUF_SIZE);
ret = fscanf(fp, "%1023[^\n]\n", buf);
if (ret == EOF) break;
if(buf[0] == '#') // comment line
continue;
switch(count)
{
// CAMERA
//camera position
case 0:
d = camP->camPos;
sscanf(buf, "%lf %lf %lf", d, d+1, d+2);
break;
case 1:
//camera target
d = camP->camTarget;
sscanf(buf, "%lf %lf %lf", d, d+1, d+2);
break;
//camera up
case 2:
d = camP->camUp;
sscanf(buf, "%lf %lf %lf", d, d+1, d+2);
break;
//field of view
case 3:
sscanf(buf, "%lf", &camP->fov);
break;
//IMAGE
//width, height
case 4:
sscanf(buf, "%d %d", &renP->width, &renP->height);
break;
//detail
case 5:
sscanf(buf, "%f", &renP->detail);
break;
//FRACTAL
case 6:
sscanf(buf, "%f %f %f", &boxP->scale, &boxP->rMin, &boxP->rFixed);
break;
case 7:
sscanf(buf, "%d %f ", &boxP->num_iter, &boxP->escape_time);
break;
//COLORING
case 8:
sscanf(buf, "%d", &renP->colourType);
break;
case 9:
sscanf(buf, "%f ", &renP->brightness);
break;
case 10:
sscanf(buf, "%d ", &renP->super_sampling);
break;
//FILENAME
case 11:
strcpy(renP->file_name, buf);
break;
}
count++;
}
fclose(fp);
}