1- #include " Demos/Utils /Config.h"
1+ #include " Demos/Common /Config.h"
22#include " Demos/Visualization/MiniGL.h"
33#include " Demos/Visualization/Selection.h"
44#include " GL/glut.h"
@@ -48,9 +48,10 @@ TimeStepController sim;
4848const unsigned int width = 30 ;
4949const unsigned int depth = 5 ;
5050const unsigned int height = 5 ;
51+ short simulationMethod = 2 ;
5152bool doPause = true ;
5253std::vector<unsigned int > selectedParticles;
53- Eigen::Vector3f oldMousePos;
54+ Vector3r oldMousePos;
5455Shader *shader;
5556string exePath;
5657string dataPath;
@@ -75,17 +76,17 @@ int main( int argc, char **argv )
7576 buildModel ();
7677
7778 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 ));
7980
8081 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 " );
8283 TwType enumType = TwDefineEnum (" VelocityUpdateMethodType" , NULL , 0 );
8384 TwAddVarCB (MiniGL::getTweakBar (), " VelocityUpdateMethod" , enumType, setVelocityUpdateMethod, getVelocityUpdateMethod, &sim, " label='Velocity update method' enum='0 {First Order Update}, 1 {Second Order Update}' group=Simulation" );
8485 TwType enumType2 = TwDefineEnum (" SimulationMethodType" , NULL , 0 );
85- TwAddVarCB (MiniGL::getTweakBar (), " SimulationMethod" , enumType2, setSimulationMethod, getSimulationMethod, &sim ,
86+ TwAddVarCB (MiniGL::getTweakBar (), " SimulationMethod" , enumType2, setSimulationMethod, getSimulationMethod, &simulationMethod ,
8687 " 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' " );
8990 TwAddVarCB (MiniGL::getTweakBar (), " NormalizeStretch" , TW_TYPE_BOOL32, setNormalizeStretch, getNormalizeStretch, &model, " label='Normalize stretch' group='Strain based dynamics' " );
9091 TwAddVarCB (MiniGL::getTweakBar (), " NormalizeShear" , TW_TYPE_BOOL32, setNormalizeShear, getNormalizeShear, &model, " label='Normalize shear' group='Strain based dynamics' " );
9192
@@ -132,12 +133,12 @@ void reset()
132133
133134void mouseMove (int x, int y)
134135{
135- Eigen::Vector3f mousePos;
136+ Vector3r mousePos;
136137 MiniGL::unproject (x, y, mousePos);
137- const Eigen::Vector3f diff = mousePos - oldMousePos;
138+ const Vector3r diff = mousePos - oldMousePos;
138139
139140 TimeManager *tm = TimeManager::getCurrent ();
140- const float h = tm->getTimeStepSize ();
141+ const Real h = tm->getTimeStepSize ();
141142
142143 ParticleData &pd = model.getParticles ();
143144 for (unsigned int j = 0 ; j < selectedParticles.size (); j++)
@@ -178,7 +179,7 @@ void timeStep ()
178179
179180void buildModel ()
180181{
181- TimeManager::getCurrent ()->setTimeStepSize (0 .005f );
182+ TimeManager::getCurrent ()->setTimeStepSize (0.005 );
182183
183184 createMesh ();
184185}
@@ -207,8 +208,9 @@ void renderTetModels()
207208
208209 for (unsigned int i = 0 ; i < model.getTetModels ().size (); i++)
209210 {
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);
212214 }
213215 if (shader)
214216 shader->end ();
@@ -235,14 +237,14 @@ void render ()
235237
236238void createMesh ()
237239{
238- Eigen::Vector3f points[width*height*depth];
240+ Vector3r points[width*height*depth];
239241 for (unsigned int i = 0 ; i < width; i++)
240242 {
241243 for (unsigned int j = 0 ; j < height; j++)
242244 {
243245 for (unsigned int k = 0 ; k < depth; k++)
244246 {
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);
246248 }
247249 }
248250 }
@@ -314,7 +316,7 @@ void createMesh()
314316 const unsigned int nTets = model.getTetModels ()[cm]->getParticleMesh ().numTets ();
315317 const unsigned int *tets = model.getTetModels ()[cm]->getParticleMesh ().getTets ().data ();
316318 const IndexedTetMesh::VertexTets *vTets = model.getTetModels ()[cm]->getParticleMesh ().getVertexTets ().data ();
317- if (sim. getSimulationMethod () == 1 )
319+ if (simulationMethod == 1 )
318320 {
319321 const unsigned int offset = model.getTetModels ()[cm]->getIndexOffset ();
320322 const unsigned int nEdges = model.getTetModels ()[cm]->getParticleMesh ().numEdges ();
@@ -337,9 +339,8 @@ void createMesh()
337339 model.addVolumeConstraint (v1, v2, v3, v4);
338340 }
339341 }
340- else if (sim. getSimulationMethod () == 2 )
342+ else if (simulationMethod == 2 )
341343 {
342- const unsigned int offset = model.getTetModels ()[cm]->getIndexOffset ();
343344 TetModel::ParticleMesh &mesh = model.getTetModels ()[cm]->getParticleMesh ();
344345 for (unsigned int i = 0 ; i < nTets; i++)
345346 {
@@ -351,9 +352,8 @@ void createMesh()
351352 model.addFEMTetConstraint (v1, v2, v3, v4);
352353 }
353354 }
354- else if (sim. getSimulationMethod () == 3 )
355+ else if (simulationMethod == 3 )
355356 {
356- const unsigned int offset = model.getTetModels ()[cm]->getIndexOffset ();
357357 TetModel::ParticleMesh &mesh = model.getTetModels ()[cm]->getParticleMesh ();
358358 for (unsigned int i = 0 ; i < nTets; i++)
359359 {
@@ -365,9 +365,8 @@ void createMesh()
365365 model.addStrainTetConstraint (v1, v2, v3, v4);
366366 }
367367 }
368- else if (sim. getSimulationMethod () == 4 )
368+ else if (simulationMethod == 4 )
369369 {
370- const unsigned int offset = model.getTetModels ()[cm]->getIndexOffset ();
371370 TetModel::ParticleMesh &mesh = model.getTetModels ()[cm]->getParticleMesh ();
372371 for (unsigned int i = 0 ; i < nTets; i++)
373372 {
@@ -388,35 +387,35 @@ void createMesh()
388387
389388void TW_CALL setTimeStep (const void *value, void *clientData)
390389{
391- const float val = *(const float *)(value);
390+ const Real val = *(const Real *)(value);
392391 TimeManager::getCurrent ()->setTimeStepSize (val);
393392}
394393
395394void TW_CALL getTimeStep (void *value, void *clientData)
396395{
397- *(float *)(value) = TimeManager::getCurrent ()->getTimeStepSize ();
396+ *(Real *)(value) = TimeManager::getCurrent ()->getTimeStepSize ();
398397}
399398
400399void TW_CALL setStiffness (const void *value, void *clientData)
401400{
402- const float val = *(const float *)(value);
401+ const Real val = *(const Real *)(value);
403402 ((SimulationModel*) clientData)->setSolidStiffness (val);
404403}
405404
406405void TW_CALL getStiffness (void *value, void *clientData)
407406{
408- *(float *)(value) = ((SimulationModel*)clientData)->getSolidStiffness ();
407+ *(Real *)(value) = ((SimulationModel*)clientData)->getSolidStiffness ();
409408}
410409
411410void TW_CALL setPoissonRatio (const void *value, void *clientData)
412411{
413- const float val = *(const float *)(value);
412+ const Real val = *(const Real *)(value);
414413 ((SimulationModel*)clientData)->setSolidPoissonRatio (val);
415414}
416415
417416void TW_CALL getPoissonRatio (void *value, void *clientData)
418417{
419- *(float *)(value) = ((SimulationModel*)clientData)->getSolidPoissonRatio ();
418+ *(Real *)(value) = ((SimulationModel*)clientData)->getSolidPoissonRatio ();
420419}
421420
422421void TW_CALL setNormalizeStretch (const void *value, void *clientData)
@@ -444,13 +443,13 @@ void TW_CALL getNormalizeShear(void *value, void *clientData)
444443void TW_CALL setSimulationMethod (const void *value, void *clientData)
445444{
446445 const short val = *(const short *)(value);
447- ((TimeStepController *)clientData)-> setSimulationMethod (( unsigned int ) val) ;
446+ *(( short *)clientData) = val;
448447 reset ();
449448}
450449
451450void TW_CALL getSimulationMethod (void *value, void *clientData)
452451{
453- *(short *)(value) = ( short )((TimeStepController *)clientData)-> getSimulationMethod ( );
452+ *(short *)(value) = *(( short *)clientData);
454453}
455454
456455void TW_CALL setVelocityUpdateMethod (const void *value, void *clientData)
0 commit comments