So to start with I need to select a physics engine and compile it for my computer running Ubuntu Jaunty 9.04 64-bit. I have chosen to use the Physics Abstraction Layer (PAL) since it looks relatively easy to use and includes some buoyancy functionality (which I intend to improve). It requires an actual physics engine back end, there are many to choose from such as ODE, Tomahawk, Box2D, .... I have chosen the BULLET physics engine.
Now to set up the programming environment. How to compile and build PAL physics abstraction layer with the BULLET physics engine on Linux. The lines starting with a $ are to be executed on the command line.
Get the Subversion source control client (svn):
$ sudo apt-get install subversionCheckout read-only copies of PAL and BULLET from svn:
$ svn co https://pal.svn.sourceforge.net/svnroot/pal/pal palGet some of their dependencies:
$ svn checkout http://bullet.googlecode.com/svn/trunk/ bullet-read-only
$ sudo apt-get install freeglut3 freeglut3-dev cmake g++ cmake cmake-gui libsdl1.2-devCompile BULLET.
$ cd bullet-read-onlyEdit install.sh, replacing all Window's line endings (\r\n) with UNIX line endings (\n)
$ gedit install.sh &
Menu->Search->Replace, Search for \r\n, Replace with \n, click Find. Save, Quit.
$ ./autogenIf you have a multicore CPU then include the --enable-multithreaded option. It may give you better real-time performance.
$ ./configure --enable-multithreadedCompile using make.
$ make -j 2The -j 2 option tells make to do two jobs at once, i.e., use two CPU cores.
Install the Bullet libraries to /usr/local/lib/ and the Header files to /usr/local/include/bullet/
$ sudo make installI had to manually copy the btActionInterface.h file to get PAL to compile, it appears it was left out of the install script.
$ sudo cp src/BulletDynamics/Dynamics/btActionInterface.h /usr/local/include/bullet/BulletDynamics/Dynamics/Compile PAL.
Do not use the premake instructions for building PAL. I believe they are old. Use the Cmake system instead.
$ cd ../pal/Open the Cmake GUI
$ cmake-gui &Enter the source and build directories at the top to the current directory (pal). The window below will list a bunch of variables. Select the tick box for PAL_BUILD_BULLET. Click "Configure". A window will show up. Select the default Unix make file option.
Some more variables will be shown in the main window.
- Set the BULLET_SINGLE_THREADED if you didn't build the multi-threaded version before.
- Fix the BULLET_INCLUDE_DIR -> /usr/local/include/bullet and the
- BULLET_LIBRARY_??? variables -> /usr/local/lib/lib???.so if they haven't been found.
- Change from simple view to advanced view and find the CMAKE_CXX_FLAGS variable and add -fPIC to it.
Click Generate. This will setup the project for you.
Now make a few quick edits to get the demo to work. In pal/Config.h change the default engine from "BULLET" to "Bullet". In pal/example/begin.cpp change line 7 from PF->LoadPALfromDLL(); to PF->LoadPALfromDLL("/usr/local/lib/"); so it know's where to find the Bullet physics libraries.
Now compile it.
$ make -j 2And install it.
$ sudo make installTell the operating system about the new libraries.
$ sudo ldconfigNow we should be able to test the demo/test program. It has been compiled into the bin/ directory. Run it.
$ bin/palbeginnerShould get output like:
Found dll 'liblibpal_bullet.so'Fin.
Found dll 'libbulletmultithreaded.so'
Found dll 'libbulletcollision.so'
Found dll 'libbulletdynamics.so'
Found dll 'libbulletmath.so'
Found dll 'libbulletsoftbody.so'
Current box position is 1.49902 at time 0.01
Current box position is 1.49706 at time 0.02
Current box position is 1.49412 at time 0.03