-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.cpp
134 lines (105 loc) · 2.83 KB
/
generator.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
#include <iostream>
#include "generator_map.h"
#include "generator_viewer.h"
#include "fluid_simulation.h"
#include "simulation_state.h"
#include <time.h>
int mainOld() {
std::cout<<"XX"<<std::endl;
srand (time(NULL));
int low=8;
int high=low*4-1;
Generator::Map2D m2d0(low,low);
Generator::Map2D m2d1(high,high);
Generator::Map m(512,512,128);
std::cout<<"low res 2d..."<<std::endl;
Generator::forAll(m2d0,&Generator::nullify);
Generator::forAll(m2d0,Generator::random(Generator::Cell::SAND,120));
output(m2d0,Generator::Cell::SAND);
std::cout<<"blur..."<<std::endl;
Generator::blur(m2d0,Generator::Cell::SAND);
output(m2d0,Generator::Cell::SAND);
std::cout<<"high res 2d..."<<std::endl;
interpolate(m2d0,m2d1,Generator::Cell::SAND);
output(m2d1,Generator::Cell::SAND);
std::cout<<"some more detail..."<<std::endl;
Generator::Map2D m2d2(high,high);
Generator::forAll(m2d2,Generator::random(Generator::Cell::SAND,40));
add(m2d1,m2d2,Generator::Cell::SAND);
output(m2d1,Generator::Cell::SAND);
// Generator::view(m2d1);
std::cout<<"high res 3d..."<<std::endl;
Generator::forAll(m,&Generator::nullify);
return 0;
}
void output(Grid2D<float> grid) {
for(int y=0;y<grid.height();y++) {
for(int x=0;x<grid.width();x++) {
printf("% 3.2f ",grid(y,x));
}
std::cout<<std::endl;
}
std::cout<<std::endl;
std::cout<<std::endl;
}
void diff(Grid2D<float> &old,Grid2D<float> &n) {
for(int y=0;y<old.height();y++) {
for(int x=0;x<old.width();x++) {
old(y,x)=old(y,x)-n(y,x);
}
}
}
void output(SimulationState &state) {
std::cout<<"Terrain:"<<std::endl;
output(state.terrain);
std::cout<<"Water:"<<std::endl;
output(state.water);
std::cout<<"suspended:"<<std::endl;
output(state.suspendedSediment);
}
int main() {
int step=4;
int w=32*step;
SimulationState state(w,w,time(0));
FluidSimulation sim(state);
double dt = 1000.0/(60);
Grid2D<float> old=state.terrain;
//output(state.terrain);
std::cout<<"BEFORE:"<<std::endl;
//output(state);
for(int i=0;i<4;i++) {
sim.update(dt,true,true);
std::cout<<"I0 "<<i<<std::endl;
}
for(int i=0;i<240;i++) {
sim.update(dt,true,false);
std::cout<<"I1 "<<i<<std::endl;
}
std::cout<<"AfTER RAIN:"<<std::endl;
//output(state);
for(int i=0;i<600;i++) {
sim.update(dt,false,false);
std::cout<<"I2 "<<i<<std::endl;
}
std::cout<<"AfTER:"<<std::endl;
//output(state);
//diff(old,state.terrain);
//output(old);
char key;
float val=1;
int frame=0;
do {
Generator::view(state,val,val+1,step,frame++);
key=Generator::waitForKey();
switch((int)key) {
case 60:
val-=1;break;
case 62:
val+=1;break;
}
sim.update(dt,false,false);
std::cout<<"KEY:"<<(int)key<<std::endl;
}while(key!=27);
Generator::close();
return 0;
}