Setting up Bullet Physics for iOS in XCode 4

Claudia picture Claudia · Jul 4, 2011 · Viewed 10.4k times · Source

So, I have downloaded the latest Bullet Physics package (2.78) and I have read the "Getting Started" documentation, which even includes an article on setting up a project in XCode from scratch (but not targeted at iOS nor XCode 4, which is what I'm using). Even so, I am still not able to set this up.

The following are the steps I'm currently taking:

  1. I'm adding the Bullet Physics "src" folder in the classes of the Xcode

  2. I'm including the Bullet Physics "src" folder path in the debug and release "Header Search Paths" in XCode

  3. I add #include "btBulletDynamicsCommon.h" to the file where I want to use Bullet Physics

  4. I change the Objective-C file to Objective-C++ by changing its file extension from "m" to "mm". This is the file where the "btBulletDynamicsCommon.h" is included

After I follow these steps, the compiler complaints about missing files (first few errors, there are 999+ errors shown when I try to build).

These are the first few headers missing in the btSoftBodySolverVertexBuffer_DX11.h:

#include <windows.h>
#include <crtdbg.h>
#include <d3d11.h>
#include <d3dx11.h>
#include <d3dcompiler.h>

Now, I'm pretty new with XCode and iOS, so the fact that these are missing doesn't really tell me much on how to solve this issue, and it makes me even wonder if they are at all needed for iOS development given the appended "DX11" on the file name that is having this issue.

So, what I would appreciate is either information on what's possibly wrong, or information on how to set up Bullet Physics to be used with iOS in XCode 4, from scratch.

Thanks.

Update: I have completely removed the DX11 and OpenCL and I'm now able to compile after step 4 above. I have not yet actually tested the Bullet Physics framework to see if it works without issues. But this now leads me to ask:

What are the specific source files/folders that are strictly necessary to run Bullet Physics in iOS?

Answer

Orbitus007 picture Orbitus007 · Aug 30, 2011

How to insert Bullet Physics into iOS: iOS OpenGL BulletPhysics Sample Code

Download the sample code or follow on a new project form Xcode with iOS openGL template:

  1. Download bullet physics... put it into a folder like the following:

*(notice that there is a folder for the project that contains the Xcode project file)

/MyProjectFolder/bullet-2.78/
/MyProjectFolder/MyProject/MyProject.xcproj

1.5. Run CMake in the physics directory to compile the frameworks (assuming you installed cmake already CMake) This step is optional with the sample code I uploaded since it already included the compiled frameworks in it....that made the file 100 megs but what is 100 megs these days anyway?

cmake . -G "Unix Makefiles" -DINSTALL_LIBS=ON -DBUILD_SHARED_LIBS=ON     -DFRAMEWORK=ON  -DCMAKE_OSX_ARCHITECTURES='i386;x86_64'     -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/Library/Frameworks     -DCMAKE_INSTALL_NAME_DIR=/Library/Frameworks -DBUILD_DEMOS:BOOL=OFF
make -j4
sudo make install
  1. Goto your MyProject.xcproj and open in Xcode...

in XCode goto any file you wish to add the physics code to... you must understand that cpp files are c++ and .m .h files are generally cocoa. You must change the Class you wish to add the physics engine code to have a .mm extension signifying it should be compiled as Objective-C++ code...

  1. In the particular class you want to add the physics which is now an Objective-C++ file or a cpp file, add the line

    #include "btBulletDynamicsCommon.h"
    

and you should compile...the error is that the file is not found...

  1. Next goto the MyProjectFolder/bullet-2.78/src and drag the src folder into your project.
  2. Delete the folder named BulletMultiThread...it will eliminate the error of trying to compile some openCL (.cl) files

  3. Last step, copy the following frameworks from the src folder of your bullet physics installation into your project:

    /MyProjectFolder/bullet-2.78/LinearMath/LinearMath.framework /MyProjectFolder/bullet-2.78/BulletCollision/BulletCollision.framework /MyProjectFolder/bullet-2.78/LinearMath/LinearMath.framework

  4. Build and Run... should compile smoothly to iOS and Mac now...