1
- #include " Demos/Utils /Config.h"
1
+ #include " Demos/Common /Config.h"
2
2
#include " Demos/Visualization/MiniGL.h"
3
3
#include " Demos/Visualization/Selection.h"
4
4
#include " GL/glut.h"
@@ -48,9 +48,10 @@ TimeStepController sim;
48
48
const unsigned int width = 30 ;
49
49
const unsigned int depth = 5 ;
50
50
const unsigned int height = 5 ;
51
+ short simulationMethod = 2 ;
51
52
bool doPause = true ;
52
53
std::vector<unsigned int > selectedParticles;
53
- Eigen::Vector3f oldMousePos;
54
+ Vector3r oldMousePos;
54
55
Shader *shader;
55
56
string exePath;
56
57
string dataPath;
@@ -75,17 +76,17 @@ int main( int argc, char **argv )
75
76
buildModel ();
76
77
77
78
MiniGL::setClientSceneFunc (render);
78
- MiniGL::setViewport (40 .0f , 0 .1f , 500 .0f , Vector3f (5.0 , - 10.0 , 30.0 ), Vector3f (5.0 , 0.0 , 0.0 ));
79
+ MiniGL::setViewport (40 .0f , 0 .1f , 500 .0f , Vector3r (5.0 , 10.0 , 30.0 ), Vector3r (5.0 , 0.0 , 0.0 ));
79
80
80
81
TwAddVarRW (MiniGL::getTweakBar (), " Pause" , TW_TYPE_BOOLCPP, &doPause, " label='Pause' group=Simulation key=SPACE " );
81
- TwAddVarCB (MiniGL::getTweakBar (), " TimeStepSize" , TW_TYPE_FLOAT , setTimeStep, getTimeStep, &model, " label='Time step size' min=0.0 max = 0.1 step=0.001 precision=4 group=Simulation " );
82
+ TwAddVarCB (MiniGL::getTweakBar (), " TimeStepSize" , TW_TYPE_REAL , setTimeStep, getTimeStep, &model, " label='Time step size' min=0.0 max = 0.1 step=0.001 precision=4 group=Simulation " );
82
83
TwType enumType = TwDefineEnum (" VelocityUpdateMethodType" , NULL , 0 );
83
84
TwAddVarCB (MiniGL::getTweakBar (), " VelocityUpdateMethod" , enumType, setVelocityUpdateMethod, getVelocityUpdateMethod, &sim, " label='Velocity update method' enum='0 {First Order Update}, 1 {Second Order Update}' group=Simulation" );
84
85
TwType enumType2 = TwDefineEnum (" SimulationMethodType" , NULL , 0 );
85
- TwAddVarCB (MiniGL::getTweakBar (), " SimulationMethod" , enumType2, setSimulationMethod, getSimulationMethod, &sim ,
86
+ TwAddVarCB (MiniGL::getTweakBar (), " SimulationMethod" , enumType2, setSimulationMethod, getSimulationMethod, &simulationMethod ,
86
87
" label='Simulation method' enum='0 {None}, 1 {Volume constraints}, 2 {FEM based PBD}, 3 {Strain based dynamics (no inversion handling)}, 4 {Shape matching (no inversion handling)}' group=Simulation" );
87
- TwAddVarCB (MiniGL::getTweakBar (), " Stiffness" , TW_TYPE_FLOAT , setStiffness, getStiffness, &model, " label='Stiffness' min=0.0 step=0.1 precision=4 group='Simulation' " );
88
- TwAddVarCB (MiniGL::getTweakBar (), " PoissonRatio" , TW_TYPE_FLOAT , setPoissonRatio, getPoissonRatio, &model, " label='Poisson ratio XY' min=0.0 step=0.1 precision=4 group='Simulation' " );
88
+ TwAddVarCB (MiniGL::getTweakBar (), " Stiffness" , TW_TYPE_REAL , setStiffness, getStiffness, &model, " label='Stiffness' min=0.0 step=0.1 precision=4 group='Simulation' " );
89
+ TwAddVarCB (MiniGL::getTweakBar (), " PoissonRatio" , TW_TYPE_REAL , setPoissonRatio, getPoissonRatio, &model, " label='Poisson ratio XY' min=0.0 step=0.1 precision=4 group='Simulation' " );
89
90
TwAddVarCB (MiniGL::getTweakBar (), " NormalizeStretch" , TW_TYPE_BOOL32, setNormalizeStretch, getNormalizeStretch, &model, " label='Normalize stretch' group='Strain based dynamics' " );
90
91
TwAddVarCB (MiniGL::getTweakBar (), " NormalizeShear" , TW_TYPE_BOOL32, setNormalizeShear, getNormalizeShear, &model, " label='Normalize shear' group='Strain based dynamics' " );
91
92
@@ -132,12 +133,12 @@ void reset()
132
133
133
134
void mouseMove (int x, int y)
134
135
{
135
- Eigen::Vector3f mousePos;
136
+ Vector3r mousePos;
136
137
MiniGL::unproject (x, y, mousePos);
137
- const Eigen::Vector3f diff = mousePos - oldMousePos;
138
+ const Vector3r diff = mousePos - oldMousePos;
138
139
139
140
TimeManager *tm = TimeManager::getCurrent ();
140
- const float h = tm ->getTimeStepSize ();
141
+ const Real h = tm ->getTimeStepSize ();
141
142
142
143
ParticleData &pd = model.getParticles ();
143
144
for (unsigned int j = 0 ; j < selectedParticles.size (); j++)
@@ -178,7 +179,7 @@ void timeStep ()
178
179
179
180
void buildModel ()
180
181
{
181
- TimeManager::getCurrent ()->setTimeStepSize (0 .005f );
182
+ TimeManager::getCurrent ()->setTimeStepSize (0.005 );
182
183
183
184
createMesh ();
184
185
}
@@ -207,8 +208,9 @@ void renderTetModels()
207
208
208
209
for (unsigned int i = 0 ; i < model.getTetModels ().size (); i++)
209
210
{
210
- const IndexedFaceMesh &visMesh = model.getTetModels ()[i]->getVisMesh ();
211
- Visualization::drawMesh (pd, visMesh, surfaceColor);
211
+ TetModel *tetModel = model.getTetModels ()[i];
212
+ const IndexedFaceMesh &surfaceMesh = tetModel->getSurfaceMesh ();
213
+ Visualization::drawMesh (pd, surfaceMesh, tetModel->getIndexOffset (), surfaceColor);
212
214
}
213
215
if (shader)
214
216
shader->end ();
@@ -235,14 +237,14 @@ void render ()
235
237
236
238
void createMesh ()
237
239
{
238
- Eigen::Vector3f points[width*height*depth];
240
+ Vector3r points[width*height*depth];
239
241
for (unsigned int i = 0 ; i < width; i++)
240
242
{
241
243
for (unsigned int j = 0 ; j < height; j++)
242
244
{
243
245
for (unsigned int k = 0 ; k < depth; k++)
244
246
{
245
- points[i*height*depth + j*depth + k] = 0 .3f * Eigen::Vector3f (( float )i, (float )j, (float )k);
247
+ points[i*height*depth + j*depth + k] = 0.3 * Vector3r ((Real )i, (Real )j, (Real )k);
246
248
}
247
249
}
248
250
}
@@ -314,7 +316,7 @@ void createMesh()
314
316
const unsigned int nTets = model.getTetModels ()[cm]->getParticleMesh ().numTets ();
315
317
const unsigned int *tets = model.getTetModels ()[cm]->getParticleMesh ().getTets ().data ();
316
318
const IndexedTetMesh::VertexTets *vTets = model.getTetModels ()[cm]->getParticleMesh ().getVertexTets ().data ();
317
- if (sim. getSimulationMethod () == 1 )
319
+ if (simulationMethod == 1 )
318
320
{
319
321
const unsigned int offset = model.getTetModels ()[cm]->getIndexOffset ();
320
322
const unsigned int nEdges = model.getTetModels ()[cm]->getParticleMesh ().numEdges ();
@@ -337,9 +339,8 @@ void createMesh()
337
339
model.addVolumeConstraint (v1, v2, v3, v4);
338
340
}
339
341
}
340
- else if (sim. getSimulationMethod () == 2 )
342
+ else if (simulationMethod == 2 )
341
343
{
342
- const unsigned int offset = model.getTetModels ()[cm]->getIndexOffset ();
343
344
TetModel::ParticleMesh &mesh = model.getTetModels ()[cm]->getParticleMesh ();
344
345
for (unsigned int i = 0 ; i < nTets; i++)
345
346
{
@@ -351,9 +352,8 @@ void createMesh()
351
352
model.addFEMTetConstraint (v1, v2, v3, v4);
352
353
}
353
354
}
354
- else if (sim. getSimulationMethod () == 3 )
355
+ else if (simulationMethod == 3 )
355
356
{
356
- const unsigned int offset = model.getTetModels ()[cm]->getIndexOffset ();
357
357
TetModel::ParticleMesh &mesh = model.getTetModels ()[cm]->getParticleMesh ();
358
358
for (unsigned int i = 0 ; i < nTets; i++)
359
359
{
@@ -365,9 +365,8 @@ void createMesh()
365
365
model.addStrainTetConstraint (v1, v2, v3, v4);
366
366
}
367
367
}
368
- else if (sim. getSimulationMethod () == 4 )
368
+ else if (simulationMethod == 4 )
369
369
{
370
- const unsigned int offset = model.getTetModels ()[cm]->getIndexOffset ();
371
370
TetModel::ParticleMesh &mesh = model.getTetModels ()[cm]->getParticleMesh ();
372
371
for (unsigned int i = 0 ; i < nTets; i++)
373
372
{
@@ -388,35 +387,35 @@ void createMesh()
388
387
389
388
void TW_CALL setTimeStep (const void *value, void *clientData)
390
389
{
391
- const float val = *(const float *)(value);
390
+ const Real val = *(const Real *)(value);
392
391
TimeManager::getCurrent ()->setTimeStepSize (val);
393
392
}
394
393
395
394
void TW_CALL getTimeStep (void *value, void *clientData)
396
395
{
397
- *(float *)(value) = TimeManager::getCurrent ()->getTimeStepSize ();
396
+ *(Real *)(value) = TimeManager::getCurrent ()->getTimeStepSize ();
398
397
}
399
398
400
399
void TW_CALL setStiffness (const void *value, void *clientData)
401
400
{
402
- const float val = *(const float *)(value);
401
+ const Real val = *(const Real *)(value);
403
402
((SimulationModel*) clientData)->setSolidStiffness (val);
404
403
}
405
404
406
405
void TW_CALL getStiffness (void *value, void *clientData)
407
406
{
408
- *(float *)(value) = ((SimulationModel*)clientData)->getSolidStiffness ();
407
+ *(Real *)(value) = ((SimulationModel*)clientData)->getSolidStiffness ();
409
408
}
410
409
411
410
void TW_CALL setPoissonRatio (const void *value, void *clientData)
412
411
{
413
- const float val = *(const float *)(value);
412
+ const Real val = *(const Real *)(value);
414
413
((SimulationModel*)clientData)->setSolidPoissonRatio (val);
415
414
}
416
415
417
416
void TW_CALL getPoissonRatio (void *value, void *clientData)
418
417
{
419
- *(float *)(value) = ((SimulationModel*)clientData)->getSolidPoissonRatio ();
418
+ *(Real *)(value) = ((SimulationModel*)clientData)->getSolidPoissonRatio ();
420
419
}
421
420
422
421
void TW_CALL setNormalizeStretch (const void *value, void *clientData)
@@ -444,13 +443,13 @@ void TW_CALL getNormalizeShear(void *value, void *clientData)
444
443
void TW_CALL setSimulationMethod (const void *value, void *clientData)
445
444
{
446
445
const short val = *(const short *)(value);
447
- ((TimeStepController *)clientData)-> setSimulationMethod (( unsigned int ) val) ;
446
+ *(( short *)clientData) = val;
448
447
reset ();
449
448
}
450
449
451
450
void TW_CALL getSimulationMethod (void *value, void *clientData)
452
451
{
453
- *(short *)(value) = ( short )((TimeStepController *)clientData)-> getSimulationMethod ( );
452
+ *(short *)(value) = *(( short *)clientData);
454
453
}
455
454
456
455
void TW_CALL setVelocityUpdateMethod (const void *value, void *clientData)
0 commit comments