-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_cam_data.c
66 lines (48 loc) · 1.65 KB
/
generate_cam_data.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define OUTPUT_FILE "cam_params.dat"
#define INPUT_FILE "cam_instructions.dat"
#define NUM_FIELDS 10
FILE *output_fp;
FILE *input_fp;
double camPos[3];
double camTarget[3];
double camUp[3];
double camPosDelta[3];
double camTargetDelta[3];
double camUpDelta[3];
int num_frames = 0;
int readLine (){
int numFields = 0;
//Read in the deltas and number of frames to apply them over
for (int i=0; i<3; i++) numFields += fscanf(input_fp, " %lf", &camPosDelta[i]);
for (int i=0; i<3; i++) numFields += fscanf(input_fp, " %lf", &camTargetDelta[i]);
for (int i=0; i<3; i++) numFields += fscanf(input_fp, " %lf", &camUpDelta[i]);
numFields += fscanf(input_fp, " %d", &num_frames);
return numFields;
}
int main(int argc, char** argv)
{
//Open files
output_fp = fopen(OUTPUT_FILE,"w");
input_fp = fopen(INPUT_FILE,"r");
//Read in the initial params from the first line of the file
for (int i=0; i<3; i++) fscanf(input_fp, " %lf", &camPos[i]);
for (int i=0; i<3; i++) fscanf(input_fp, " %lf", &camTarget[i]);
for (int i=0; i<3; i++) fscanf(input_fp, " %lf", &camUp[i]);
while (readLine() == NUM_FIELDS) {
for (int i=0; i<num_frames; i++) {
//Apply the deltas
for (int j=0; j<3; j++) camPos[j] += camPosDelta[j];
for (int j=0; j<3; j++) camTarget[j] += camTargetDelta[j];
for (int j=0; j<3; j++) camUp[j] += camUpDelta[j];
fprintf(
output_fp, "%lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
camPos[0], camPos[1], camPos[2], camTarget[0], camTarget[1], camTarget[2], camUp[0], camUp[1], camUp[2]
);
}
}
fclose(output_fp);
fclose(input_fp);
}