@@ -34,9 +34,6 @@ void render ();
34
34
void cleanup ();
35
35
void reset ();
36
36
void selection (const Vector2i &start, const Vector2i &end, void *clientData);
37
- void createSphereBuffers (Real radius, int resolution);
38
- void renderSphere (const Vector3r &x, const float color[]);
39
- void releaseSphereBuffers ();
40
37
41
38
42
39
FluidModel model;
@@ -53,12 +50,6 @@ const Real containerHeight = 4.0;
53
50
bool doPause = true ;
54
51
std::vector<unsigned int > selectedParticles;
55
52
Vector3r oldMousePos;
56
- // initiate buffers
57
- GLuint elementbuffer;
58
- GLuint normalbuffer;
59
- GLuint vertexbuffer;
60
- int vertexBufferSize = 0 ;
61
- GLint context_major_version, context_minor_version;
62
53
string exePath;
63
54
string dataPath;
64
55
@@ -102,10 +93,6 @@ int main( int argc, char **argv )
102
93
param->setFct = [&](Real v) -> void { model.setViscosity (v); };
103
94
imguiParameters::addParam (" Simulation" , " PBD" , param);
104
95
105
- MiniGL::getOpenGLVersion (context_major_version, context_minor_version);
106
- if (context_major_version >= 3 )
107
- createSphereBuffers ((Real)particleRadius, 8 );
108
-
109
96
MiniGL::mainLoop ();
110
97
111
98
cleanup ();
@@ -122,8 +109,6 @@ int main( int argc, char **argv )
122
109
void cleanup ()
123
110
{
124
111
delete TimeManager::getCurrent ();
125
- if (context_major_version >= 3 )
126
- releaseSphereBuffers ();
127
112
}
128
113
129
114
void reset ()
@@ -202,64 +187,23 @@ void render ()
202
187
const ParticleData &pd = model.getParticles ();
203
188
const unsigned int nParticles = pd.size ();
204
189
205
- float surfaceColor[4 ] = { 0 .2f , 0 .6f , 0 .8f , 1 };
206
- float speccolor[4 ] = { 1.0 , 1.0 , 1.0 , 1.0 };
207
- glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, surfaceColor);
208
- glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, surfaceColor);
209
- glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, speccolor);
210
- glMaterialf (GL_FRONT_AND_BACK, GL_SHININESS, 100.0 );
211
- glColor3fv (surfaceColor);
212
-
213
- glPointSize (4.0 );
214
-
215
190
const Real supportRadius = model.getSupportRadius ();
216
191
Real vmax = static_cast <Real>(0.4 *2.0 )*supportRadius / TimeManager::getCurrent ()->getTimeStepSize ();
217
192
Real vmin = 0.0 ;
218
193
219
- if (context_major_version > 3 )
220
- {
221
- for (unsigned int i = 0 ; i < nParticles; i++)
222
- {
223
- Real v = pd.getVelocity (i).norm ();
224
- v = static_cast <Real>(0.5 )*((v - vmin) / (vmax - vmin));
225
- v = min (static_cast <Real>(128.0 )*v*v, static_cast <Real>(0.5 ));
226
- float fluidColor[4 ] = { 0 .2f , 0 .2f , 0 .2f , 1.0 };
227
- MiniGL::hsvToRgb (0 .55f , 1 .0f , 0 .5f + (float )v, fluidColor);
228
- renderSphere (pd.getPosition (i), fluidColor);
229
- }
230
-
231
- // for (unsigned int i = 0; i < model.numBoundaryParticles(); i++)
232
- // renderSphere(model.getBoundaryX(i), surfaceColor);
233
- }
234
- else
194
+ for (unsigned int i = 0 ; i < nParticles; i++)
235
195
{
236
- glDisable (GL_LIGHTING);
237
- glBegin (GL_POINTS);
238
- for (unsigned int i = 0 ; i < nParticles; i++)
239
- {
240
- Real v = pd.getVelocity (i).norm ();
241
- v = static_cast <Real>(0.5 )*((v - vmin) / (vmax - vmin));
242
- v = min (static_cast <Real>(128.0 )*v*v, static_cast <Real>(0.5 ));
243
- float fluidColor[4 ] = { 0 .2f , 0 .2f , 0 .2f , 1.0 };
244
- MiniGL::hsvToRgb (0 .55f , 1 .0f , 0 .5f + (float )v, fluidColor);
245
-
246
- glColor3fv (fluidColor);
247
- glVertex3v (&pd.getPosition (i)[0 ]);
248
- }
249
- glEnd ();
250
-
251
- // glBegin(GL_POINTS);
252
- // for (unsigned int i = 0; i < model.numBoundaryParticles(); i++)
253
- // {
254
- // glColor3fv(surfaceColor);
255
- // glVertex3fv(&model.getBoundaryX(i)[0]);
256
- // }
257
- // glEnd();
258
-
259
- glEnable (GL_LIGHTING);
196
+ Real v = pd.getVelocity (i).norm ();
197
+ v = static_cast <Real>(0.5 )*((v - vmin) / (vmax - vmin));
198
+ v = min (static_cast <Real>(128.0 )*v*v, static_cast <Real>(0.5 ));
199
+ float fluidColor[4 ] = { 0 .2f , 0 .2f , 0 .2f , 1.0 };
200
+ MiniGL::hsvToRgb (0 .55f , 1 .0f , 0 .5f + (float )v, fluidColor);
201
+ MiniGL::drawSphere (pd.getPosition (i), particleRadius, fluidColor, 8 );
260
202
}
261
203
262
-
204
+ // float surfaceColor[4] = { 0.2f, 0.6f, 0.8f, 1 };
205
+ // for (unsigned int i = 0; i < model.numBoundaryParticles(); i++)
206
+ // MiniGL::drawSphere(model.getBoundaryX(i), particleRadius, surfaceColor, 8);
263
207
264
208
float red[4 ] = { 0 .8f , 0 .0f , 0 .0f , 1 };
265
209
for (unsigned int j = 0 ; j < selectedParticles.size (); j++)
@@ -365,141 +309,3 @@ void initBoundaryData(std::vector<Vector3r> &boundaryParticles)
365
309
// Front
366
310
addWall (Vector3r (x1, y1 , z2), Vector3r (x2, y2, z2), boundaryParticles);
367
311
}
368
-
369
-
370
- void createSphereBuffers (Real radius, int resolution)
371
- {
372
- Real PI = static_cast <Real>(M_PI);
373
- // vectors to hold our data
374
- // vertice positions
375
- std::vector<Vector3r> v;
376
- // normals
377
- std::vector<Vector3r> n;
378
- std::vector<unsigned short > indices;
379
-
380
- // initiate the variable we are going to use
381
- Real X1, Y1, X2, Y2, Z1, Z2;
382
- Real inc1, inc2, inc3, inc4, radius1, radius2;
383
-
384
- for (int w = 0 ; w < resolution; w++)
385
- {
386
- for (int h = (-resolution / 2 ); h < (resolution / 2 ); h++)
387
- {
388
- inc1 = (w / (Real)resolution) * 2 * PI;
389
- inc2 = ((w + 1 ) / (Real)resolution) * 2 * PI;
390
- inc3 = (h / (Real)resolution)*PI;
391
- inc4 = ((h + 1 ) / (Real)resolution)*PI;
392
-
393
- X1 = sin (inc1);
394
- Y1 = cos (inc1);
395
- X2 = sin (inc2);
396
- Y2 = cos (inc2);
397
-
398
- // store the upper and lower radius, remember everything is going to be drawn as triangles
399
- radius1 = radius*cos (inc3);
400
- radius2 = radius*cos (inc4);
401
-
402
- Z1 = radius*sin (inc3);
403
- Z2 = radius*sin (inc4);
404
-
405
- // insert the triangle coordinates
406
- v.push_back (Vector3r (radius1*X1, Z1, radius1*Y1));
407
- v.push_back (Vector3r (radius1*X2, Z1, radius1*Y2));
408
- v.push_back (Vector3r (radius2*X2, Z2, radius2*Y2));
409
-
410
- indices.push_back ((unsigned short )v.size () - 3 );
411
- indices.push_back ((unsigned short )v.size () - 2 );
412
- indices.push_back ((unsigned short )v.size () - 1 );
413
-
414
- v.push_back (Vector3r (radius1*X1, Z1, radius1*Y1));
415
- v.push_back (Vector3r (radius2*X2, Z2, radius2*Y2));
416
- v.push_back (Vector3r (radius2*X1, Z2, radius2*Y1));
417
-
418
- indices.push_back ((unsigned short )v.size () - 3 );
419
- indices.push_back ((unsigned short )v.size () - 2 );
420
- indices.push_back ((unsigned short )v.size () - 1 );
421
-
422
- // insert the normal data
423
- n.push_back (Vector3r (X1, Z1, Y1));
424
- n.push_back (Vector3r (X2, Z1, Y2));
425
- n.push_back (Vector3r (X2, Z2, Y2));
426
- n.push_back (Vector3r (X1, Z1, Y1));
427
- n.push_back (Vector3r (X2, Z2, Y2));
428
- n.push_back (Vector3r (X1, Z2, Y1));
429
- }
430
- }
431
-
432
- for (unsigned int i = 0 ; i < n.size (); i++)
433
- n[i].normalize ();
434
-
435
-
436
- glGenBuffers (1 , &vertexbuffer);
437
- glBindBuffer (GL_ARRAY_BUFFER, vertexbuffer);
438
- glBufferData (GL_ARRAY_BUFFER, v.size () * sizeof (Vector3r), &v[0 ], GL_STATIC_DRAW);
439
-
440
- glGenBuffers (1 , &normalbuffer);
441
- glBindBuffer (GL_ARRAY_BUFFER, normalbuffer);
442
- glBufferData (GL_ARRAY_BUFFER, n.size () * sizeof (Vector3r), &n[0 ], GL_STATIC_DRAW);
443
- glBindBuffer (GL_ARRAY_BUFFER, 0 );
444
-
445
- // Generate a buffer for the indices as well
446
- glGenBuffers (1 , &elementbuffer);
447
- glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, elementbuffer);
448
- glBufferData (GL_ELEMENT_ARRAY_BUFFER, indices.size () * sizeof (unsigned short ), &indices[0 ], GL_STATIC_DRAW);
449
- glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0 );
450
-
451
- // store the number of indices for later use
452
- vertexBufferSize = (unsigned int )indices.size ();
453
-
454
- // clean up after us
455
- indices.clear ();
456
- n.clear ();
457
- v.clear ();
458
- }
459
-
460
- void renderSphere (const Vector3r &x, const float color[])
461
- {
462
- glEnableClientState (GL_VERTEX_ARRAY);
463
- glEnableClientState (GL_NORMAL_ARRAY);
464
-
465
- glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, color);
466
- glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, color);
467
-
468
-
469
- glBindBuffer (GL_ARRAY_BUFFER, vertexbuffer);
470
- glVertexPointer (3 , GL_REAL, 0 , 0 );
471
-
472
- glBindBuffer (GL_ARRAY_BUFFER, normalbuffer);
473
- glNormalPointer (GL_REAL, 0 , 0 );
474
-
475
- glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, elementbuffer);
476
-
477
- glPushMatrix ();
478
- glTranslated (x[0 ], x[1 ], x[2 ]);
479
- glDrawElements (GL_TRIANGLES, (GLsizei)vertexBufferSize, GL_UNSIGNED_SHORT, 0 );
480
- glPopMatrix ();
481
- glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0 );
482
- glBindBuffer (GL_ARRAY_BUFFER, 0 );
483
-
484
- glDisableClientState (GL_NORMAL_ARRAY);
485
- glDisableClientState (GL_VERTEX_ARRAY);
486
- }
487
-
488
- void releaseSphereBuffers ()
489
- {
490
- if (elementbuffer != 0 )
491
- {
492
- glDeleteBuffers (1 , &elementbuffer);
493
- elementbuffer = 0 ;
494
- }
495
- if (normalbuffer != 0 )
496
- {
497
- glDeleteBuffers (1 , &normalbuffer);
498
- normalbuffer = 0 ;
499
- }
500
- if (vertexbuffer != 0 )
501
- {
502
- glDeleteBuffers (1 , &vertexbuffer);
503
- vertexbuffer = 0 ;
504
- }
505
- }
0 commit comments