\chapter{Animation in \sofa}\label{chapter:as}
This section shows how the material presented in chapter \ref{chapter:pba} is implemented in \sofa. A class diagram of the mechanical core is presented in appendix \ref{sec:umlmeca}.
\section{Particles}
\subsection{Simple example}
Here we simulate two particles subject to gravity. An introduction to particle dynamics is given in section \ref{sec:particles}. 
Figure \ref{fig:singleParticleCollaboration} shows the collaboration diagram and the code used to model a set of particles subject to gravity. The code is available in project {\tt doc/src\_examples/example1}.


\begin{figure}[htp]
\begin{center} \begin{tabular}{cc}
\begin{minipage}[b]{6cm}
	\includegraphics*[width=6cm]{fig/singleParticleCollaboration.eps}  
	%\input{fig/singleParticleCollaboration.tex} 
\end{minipage}
 &
\begin{minipage}[b]{9cm} 
\begin{code_cpp}
#include "Sofa/Components/Scene.h"
#include "Sofa/Components/MassObject.h"
#include "Sofa/Components/EulerSolver.h"
#include "Sofa/GUI/FLTK/Main.h"

using namespace Sofa::Components;
using namespace Sofa::Core;
using namespace Sofa::GUI::FLTK;
typedef Sofa::Components::Common::Vec3Types MyTypes;
typedef MyTypes::Deriv Vec3;
        
int main(int argc, char** argv) 
{
    Scene* scene = new Scene;
    scene->setDt(0.04);
    
    MechanicalGroup* group = new MechanicalGroup;
    scene->addBehaviorModel(group);
    group->setSolver( new EulerSolver );
    
    MassObject<MyTypes>* particles = new MassObject<MyTypes>;
    group->addObject(particles);
    scene->addVisualModel(particles);                 
    particles->setGravity( Vec3( 0,-1,0 ) );
    particles->addMass( Vec3(2,0,0), Vec3(0,0,0), 1 ); 
    particles->addMass( Vec3(3,0,0), Vec3(0,0,0), 1 );


    scene->init();
    MainLoop(argv[0]);
    return 0;
}
\end{code_cpp}
\end{minipage}
\end{tabular}
\end{center}
\label{fig:singleParticleCollaboration} 
\caption{Collaboration diagram and code for the animation of free particles.}
\end{figure}

