/
main.cpp
192 lines (171 loc) · 4.08 KB
/
main.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
#include "commonData.h"
#include "main.h"
#include <time.h>
#include <pthread.h>
#include <omp.h>
#include <sys/time.h>
/*
int main(int argc, char** argv)
{
struct timeval tt1, tt2;
init();
int i=pthread_getconcurrency();
int it=0;
int ni= 0;
while(ni++<NO_OF_ITERATIONS){
gettimeofday(&tt1, NULL);
animate();
gettimeofday(&tt2, NULL);
int milliSeconds = (tt2.tv_sec - tt1.tv_sec) * 1000 + (tt2.tv_usec - tt1.tv_usec)/1000;
cout<<"Iteration "<<it<<" : "<<milliSeconds<<"ms"<<endl<<endl;
it++;
}
return 0;
}
*/
void animate()
{
fluidSim->simulate(timestep);
}
void init(void)
{
sGrid->initGridStag();
fluidSim->init(sGrid);
fluidSim->initFluidBody(fBT);// 2: indicates dam break center
print->init(sGrid);
render->init(sGrid);
}
void initParticles()
{
sGrid->fluidParticles.clear();
}
/*------------------Code Below this is used when rendered is ON---------*/
void display ( void ) ;
void preDisplay ( );
void postDisplay ( );
void openGlutWindow ( char* windowName) ;
void reshape ( int w, int h ) ;
void idleFun();
int main(int argc, char** argv)
{
glutInit(&argc, argv);
init ();
int i=pthread_getconcurrency();
char windowName[]=" Liquid_Simulator-LevelSet+Surface" ;
openGlutWindow(windowName);
glutMainLoop();
return 0;
}
void display(void){
preDisplay();
static bool flag[10]={true,true,true,true,true,false};
char output1 = ' ';
bool anyUpdation = false;
switch(output1){
case'~':
flag[0] = !flag[0];
//render->renderBoundary
break;
case '!':
flag[1] = !flag[1];
//render->renderGrid();
break;
case '@':
flag[2] = !flag[2];
//render->renderParticles();
break;
case '#':
flag[3] = !flag[3];
//render->renderSurfaceBoundary();
break;
case '$':
flag[4] = !flag[4];
//render->renderVector2D(sGrid->u,sGrid->v);
break;
case '%':
flag[5] = !flag[5];
//render->renderMat(sGrid->distanceLevelSet,1);
break;
/*case '^':
flag[6] = !flag[6];
//render->renderMat(sGrid->isFluidBoundary,1);
break;*/
}
if(anyUpdation){
cout<<"Flags :"<<" ~"<<flag[0]<<" !"<<flag[1]<<" @"<<flag[2]<<" #"<<flag[3]<<
" $"<<flag[4]<<" %"<<flag[5]/*<<" ^"<<flag[6]*/<<" +"<<endl;
anyUpdation = false;
}
if(flag[0])
render->renderBoundary();
if(flag[1])
render->renderGrid();
if(flag[2])
render->renderParticles();
if(flag[3])
render->renderSurfaceBoundary();
if(flag[4])
render->renderVector2D(sGrid->u,sGrid->v);
if(flag[5])
render->renderMat(sGrid->distanceLevelSet,2);
/*if(flag[6])
render->renderMat(sGrid->isFluidBoundary,1);
*/
output1 = ' ';
postDisplay();
}
void idleFun ( void )
{
struct timeval tt1, tt2;
static int it = 0;
static struct timeval tt3, tt4;
tt3=tt4;
gettimeofday(&tt4, NULL);
gettimeofday(&tt1, NULL);
animate();
gettimeofday(&tt2, NULL);
int milliSeconds = (tt2.tv_sec - tt1.tv_sec) * 1000 + (tt2.tv_usec - tt1.tv_usec)/1000;
cout<<"Iteration "<<it<<" : "<<milliSeconds<<"ms"<<endl;
int milliSeconds2 = (tt4.tv_sec - tt3.tv_sec) * 1000 + (tt4.tv_usec - tt3.tv_usec)/1000;
cout<<"Actual "<<it<<" : "<<milliSeconds2<<"ms"<<endl<<endl;
it++;
glutSetWindow ( winId );
glutPostRedisplay ( );
}
void reshape (int w, int h)
{
glutSetWindow(winId);
glutReshapeWindow(w ,h);
winSizeX = w;
winSizeY = h;
}
void preDisplay()
{
glViewport ( 0, 0, winSizeX, winSizeY);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho( 0, zoomFactor, 0, zoomFactor , 0,1 ); //better to use ortho..
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
}
void postDisplay()
{
glutSwapBuffers();
}
void openGlutWindow(char* windowName)
{
glutInitDisplayMode ( GLUT_RGBA | GLUT_DOUBLE );
glutInitWindowSize (winSizeX, winSizeY);
glutInitWindowPosition (570, 100);
winId = glutCreateWindow (&windowName[2]);
glClearColor( 0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
glutDisplayFunc(display);
// glutSpecialFunc(&SpecialKeyPressed);
// glutKeyboardFunc(&KeyPressed);
glutReshapeFunc(reshape);
glutIdleFunc(idleFun);
}