Setting up Bullet on Visual Studio 2010 and beyond

Introduction-

At some stage during your game development endeavours, you will come across a situation where you will want to implement a physics simulation module in your engine.

For those people who make their games the “easy” way, i.e. using Unity3D/Blender, etc, the physics library comes with their softwares.
But for real game programmers, who are using low level APIs such as, OpenGL or DirectX , you will either have to setup your own physics library, or use libraries created by other people.

To create and implement your own library you will need to be good at physics, and you must know the intricacies of the subject. Which will need a work of several years, but if you want a quick solution you can use libraries already made by others.

When you want to start working on physics in 3D, you’re presented with two main options,

  • PhysX library (NVIDIA)
  • Bullet Physics library (Erwin Coumans, et al.)

PhysX is NVIDIA’s proprietary library and will work only on NVIDIA graphics cards. If you have an AMD GPU like me, you will have to go with Bullet.
Bullet is an open source library created and maintained by Erwin Courmans.
Bullet library is used for many games, most famous ones being, Crysis, GTA. It’s also been used in several movies, Yes!!, I said movies, 2012 by Digital Domain, Hancock by Sony Pictures, Bolt by Walt Disney, are the ones that come to mind.
Along with this, it’s been used in many 3D modelling softwares. Blender and Unity use bullet for their physics simulations.

Now, let’s have a look at how you can include this library in your projects.

Prerequisites

  • You have a working 3D OpenGL/DirectX application.
  • You know how to use Visual Studio, and comfortable with setting up libraries.

Bullet doesn’t come like some of the other libraries that you may have used, e.g. if you download GLUT, { you’re awesome if you don’t use GLUT, and use WIN32 API to create windows for your 3D programs :) } you see 3 standard folders, include, lib, bin.
They are quite self-explanatory, include folder path you give to your projects include path for header files, lib folder contains the library files created by the build, which you tell compiler using #pragma, and bin path contains the DLL needed for GLUT.

When you extract bullet from its ZIP file you will not find any of these. It’s a bit confusing at start, but once you get hang of it, it’s quite easy.

Now, we can directly go through the process step-by-step, and I will try to explain issues that I came across while doing so. Hopefully these might solve any issues that you might be getting.

  • Download the latest bullet build from its website.
  • Extract the lib
  • Download CMake: you will need this library to build bullet for your applications.
  • Follow the steps given here. Although they further ask you to open VS, do not open VS.
  • Once you done configuring and generating the projects, open VS
  • In your OpenGL/DX project, right click solution->add->existing project.
  • Navigate to where you build the bullet lib using CMake. For me it was-
    C:\GLLibs\bullet-2.81-rev2613\build2
  • You will find src folder here, go inside that, and add the 3 main projects needed for bullet to execute
    1. BulletCollision
    2. BulletDynamics
    3. LinearMath
    4. 1- Now right click your main project, and click on Project dependencies, select the 3 projects.2345345
      8.2- Now go to the properties of each of the 3 projects BulletCollision, BulletDynamics, LinearMath, make sure the Librarian->Link Library Dependencies is set to YES.4sdfsd

If at this step, you see a dialog box saying “the project file ‘’ has been renamed or removed” you will have to delete the build and start over again. It means that you have messed up one of the .sln files for a project. Its hard to find for which project its been messed up, so its easier to start from beginning.

  • Now go to your main project properties, in the Linker->Input section add the Additional Dependencies of the lib files generated in the folder lib.
    for me it was- “C:\GLLibs\bullet-2.81-rev2613\build2\lib\Debug”Capture
  • Add the include ‘src’ path for bullet.
  • 1244

Add the code for Hello World Bullet from here; And Finally hit the build solution button.

If you’re in luck, you will be seeing that beautiful message,

========= Build: 1 succeeded, 0 failed, 3 up-to-date, 0 skipped ==========

One thing to keep in mind while setting up bullet is, it’s one of the tough libraries to link with your project successfully. It took me 2 days to set it up properly. One of the comments which I came across while doing this was very interesting and I would like to mention it here,

“After about 4 and half hours I was able to get the bullet 2.82 compiled and running the demos. I still can’t get this program to compile after another 2 and half hours. Does it take this long for everyone else. I don’t know how people survive this. I have also spent about 5 hours trying to get OpenGL 3 + to compile on my computer… I am thinking the hardware won’t do it. This has been over the course of about 2 weeks. Sometimes I feel like I am just gong out to slam my balls in the car door again.”
– Some frustrated guy.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s