forked from asanotigaku/planet
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprof2pov.cpp
195 lines (155 loc) · 3.28 KB
/
prof2pov.cpp
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <string>
#include <lua.hpp>
#define POVRAY_INC_FILE "stdpov.inc"
using namespace std;
void usage();
void LoadProf(FILE *fp);
void prof2pov(FILE *fp, char *fmt, int num);
void Malloc(int nP);
void Free();
lua_State *lua = NULL;
char* fformat;
int fnum = 0;
//prof
int nP;
float SimTime;
float *Pos, *Vel, *Rad, *Val;
int *Id, *Typ;
namespace CAM {
float pos[3];
float look[3];
float angle;
};
void init(){
using namespace CAM;
pos[0] = 0.0;
pos[1] = 0.0;
pos[2] = 3.0 * pow(10,8);
look[0]= 0.0;
look[1]= 0.0;
look[2]= 0.0;
angle = 45;
}
int main(int argc, char **argv){
init();
switch(argc){
case 1:
case 2:
usage();
return -1;
case 3: // lua無し
break;
case 4: // lua有り
// lua = lua_open();
lua = luaL_newstate();
luaL_openlibs(lua);
if(luaL_loadfile(lua, argv[3])){
fprintf(stderr, "can't load lua file:%s\n", argv[3]);
return -1;
}
break;
default:
usage();
return -1;
break;
}
fformat = argv[1];
fnum = atoi(argv[2]);
char fname[256];
FILE *fp;
for(int i=0;i<fnum;i++){
sprintf(fname, fformat, i);
cout<<"loading: "<<fname<<endl;
fp = fopen(fname, "r");
if(fp == NULL){
cout<<"error: can't open file."<<endl;
break;
}
LoadProf(fp);
char tmp[256];
strcpy(tmp, fformat);
char *p = tmp;
for(;;){ p++; if(*p == '.') break; }
p++; *p='p';
p++; *p='o';
p++; *p='v';
p++; *p='\0';
prof2pov(fp, tmp, i);
fclose(fp);
Free();
}
}
void usage(){
printf("usage> ./prof2pov fileformat filenumber [Lua_file] \n");
}
void prof2pov(FILE *fp, char *fmt, int num){
char fname[256];
sprintf(fname, fmt, num);
cout<<"writing: "<<fname<<endl;
fp = fopen(fname, "w");
//include files
fprintf(fp, "#include \"%s\"\n", POVRAY_INC_FILE);
//load settings
if(lua != NULL){
lua_getglobal(lua, "setCamPos");
lua_pushnumber(lua, num);
if(lua_pcall(lua, 1, 3, 0)){
fprintf(stderr, "can't exec setCamPos(): %s\n", lua_tostring(lua, -1));
getchar();
}
float x,y,z;
x = y = z = 0.0;
if(lua_isnumber(lua, -1)){
x = lua_tonumber(lua, -1);
}
lua_pop(lua, 1);
if(lua_isnumber(lua, -1)){
y = lua_tonumber(lua, -1);
}
lua_pop(lua, 1);
if(lua_isnumber(lua, -1)){
z = lua_tonumber(lua, -1);
}
lua_pop(lua, 1);
CAM::pos[0] = x;
CAM::pos[1] = y;
CAM::pos[2] = z;
}
//settings
fprintf(fp, "LIGHT_SRC(<%f,%f,%f>,<%f,%f,%f>)\n", 100000.0, 0.0, 0.0, 0.0, 0.0, 0.0);
fprintf(fp, "CAM(<%f,%f,%f>,<%f,%f,%f>,%f)\n", CAM::pos[0], CAM::pos[1], CAM::pos[2], CAM::look[0], CAM::look[1], CAM::look[2], CAM::angle);
//output data
for(int i=0;i<nP;i++){
fprintf(fp, "SP(<%f,%f,%f>,%f)\n", Pos[i*3], Pos[i*3+1], Pos[i*3+2], Rad[i]);
}
fclose(fp);
}
void LoadProf(FILE *fp){
fscanf(fp, "%f", &SimTime);
fscanf(fp, "%d", &nP);
Malloc(nP);
for(int i=0;i<nP;i++){
fscanf(fp, "%f %f %f %f %f %f %f %d %d %f", &Pos[i*3], &Pos[i*3+1], &Pos[i*3+2], &Vel[i*3], &Vel[i*3+1], &Vel[i*3+2], &Rad[i], &Id[i], &Typ[i], &Vel[i]);
}
}
void Malloc(int nP){
Pos = new float[nP*3];
Vel = new float[nP*3];
Rad = new float[nP];
Val = new float[nP];
Id = new int[nP];
Typ = new int[nP];
}
void Free(){
delete Pos;
delete Vel;
delete Rad;
delete Val;
delete Id;
delete Typ;
}