FISICAS is an abstraction layer for some of the most popular physics engines, providing an unified interface for them.
At the moment, it supports two physics engines widely used:
First, install the physics engines you want to use. Once the engine(s) you want to use are installed, follow the installation instructions of FISICAS itself.
Here are some indications to avoid problems:
Bullet
Download it from the Bullet website ( tested with version 2.77 ).
If you build the demos, your computer must have installed GLUT.
Run cmake with the desired options. FISICAS compiles as a shared library, so some Linux distributions could have problems if Bullet is compiled as static library:
cmake . -G "Unix Makefiles" -DBUILD_SHARED_LIBS=ON
Run make install. It’s recommended to use the default Bullet installation directory:
sudo make install
ODE
Download ODE from its site ( tested with version 0.11.1 ).
Follow the installation instructions for ODE, paying attention to build it as a shared library:
./configure --enabled-shared
make
make install
Inside the FISICAS directory, run:
make
This will create the configure file CMakeCache.txt in the build folder. Open CMakeCache.txt to edit it:
gedit build/CMakeCache.txt
Search the following lines:
FISICAS_BUILD_BULLET:BOOL=OFF
FISICAS_BUILD_ODE:BOOL=OFF
This lines indicate which physic engines are activated. Change their value to ON for each engine you want to use.
To install the Unit Test provided with FISICAS, its necessary to activate the following line:
FISICAS_BUILD_TEST:BOOL=OFF
Note that Unit Test use the Google Test framework, so you have to install it before compile.
It’s time to compile and install ( if necessary ):
make
make install
By default FISICAS is installed in /usr/local/lib.
First of all, FISICAS headers must be included:
#include "FISICASFactory.h"
In the main function, you have to select the engine you want use, and initialize the physics:
PF->SelectEngine("Bullet");
FISICASFactory* physics = PF->InitPhysics( FISICASVector( 0,-9.8,0 ) );
The vector passed to the InitPhysics function contains the gravity for our physics world. If no vector is passed, the default gravity ( Earth’s gravity ) is used.
After that, the bodies involved in the simulation must to be created. Here we are going to create very simple application with a box falling into the void.
The way to work with the bodies is always the same. We must create the body before use it:
FISICASDynamicBody* body = physics->CreateDynamicBody();
Put the body in the initial position:
FISICASVector bodyPosition( 0,10,0 );
body->SetPosition( bodyPosition );
Add the geometries to the body ( geometries deal with the collision detection system ). Here we are going to add a box geometry with 1 unit for each side. Also we are putting the box in the (1,0,0) relative to body position:
FISICASLocationMatrix geometryPosition;
geometryPosition.SetTranslation( FISICASVector(1,0,0) );
body->AddBoxGeometry( geometryPosition, 1,1,1 );
Our body is now created, but we have to put it in the simulation world. To do this, we have to initialize it, giving a mass:
body->Init( 1 );
Now we can run the simulation and our body will fall following the gravity to the void. To run the simulation call the StepTime function:
physics->StepTime( 1.0f ); // Time is given in seconds.
Don’t forget to destroy physics once the program is finished:
physics->DestroyPhysics();
This application is included with the default installation of FISICAS. You can find the code in the file main.cpp located inside the examples folder. If you want to run it, execute the mainApp:
./build/bin/mainApp
The output should be the following:
Body position: (0,10,0)
Body position: (0,9.95018,0)
Body position: (0,9.80237,0)
Body position: (0,9.55655,0)
Body position: (0,9.21273,0)
Body position: (0,8.77092,0)
Body position: (0,8.2311,0)
Body position: (0,7.59329,0)
Body position: (0,6.85748,0)
Body position: (0,6.02366,0)
Destroying bullet
Deleted bullet variables