Loading...

How to implement a simple falling particule with SOFA ?

Screenshot : the white dot is one falling particule
Screenshot : the white dot is one falling particule

The code

The code relative to this example is located in : sofa/applications/tutorials/oneParticule

There is just a Main.cpp with less than 100 lines. Open and observe it.

Compile and run this very simple tutorial

  • See HowToCompileATutorial to run it.
  • There is just one simple white particule rendered in a black background 3D scene.
    • Animate/stop the scene with the right-top button ANIM to see the falling particule.
    • To see the 3D axis of the scene press the key L and then the key R.
    • Navigate in the frame with the mouse
    • Click the tab "Help" to know more

The scene graph

The scene graph used for this example
The scene graph used for this example
  • SOFA works with a scene graph and its nodes represent all the component needed to simulate physical objects in interaction.
  • Click the tab "Graph" on your right to see the scene graph.
  • You can export this graph : click the "Export Graph" button, chose a name and than click "Export". Two files, .dot and .png, will be saved in sofa/applications/tutorials/oneParticule.

If you want to open the .dot file, use dotty, a graph editor in Graphviz package


More comments

  • The graph root node:
       sofa::simulation::tree::GNode* groot = new sofa::simulation::tree::GNode;
       groot->setName( "root" );
    
  • A solver, a gravity, the single particle and its properties compose the graph. To try the code, you can change the gravity with setGravity(...) or the initials conditions of the particule, i.e. its position particle->getX() and its velocity particle->getV().
  • First the scene is initialized and then the main loop is launched : at each step, the scene will be updated and drawn.
       sofa::simulation::tree::Simulation::init(groot);
    
       sofa::gui::fltk::MainLoop(argv[0],groot);
    
    or, depending on the graphic user interface (GUI) used:
       sofa::gui::qt::MainLoop(argv[0],groot,fileName.c_str());
    

Procedural scene versus loaded scene

  • In this example the scene is given proceduraly, that is defined within the C++ code.
  • At any time you can do File >> Save as ... to save the scene in its current state (for example into sofa/applications/tutorials/oneParticule/oneParticule.scn).
  • And then you can load this file. Click File >> Open and select: sofa/applications/tutorials/oneParticule/oneParticule.scn.
    You get the exactly same scene.

  • Edit this file and compare it with the code to understand how it works.
  • Editing this file allows you to experiment various scenes and parameters without recompiling the application.