13
\$\begingroup\$

I downloaded the release file found here, but I'm just not sure where to start. In my game I have a number of oblongs and a sphere, I want all of these to collide with one another. (They all have meshes and associated bounding volumes)

edit - I just realised the cuboids actually have AABB's associated with them. I guess I'll have to change that at least.

What are the steps I need to follow?

\$\endgroup\$
5
  • 2
    \$\begingroup\$ did you take a look into the manual under chapter 4.4 Integration overview I know it's very spartan but it does describe the basic process. So if you look at that and the code for the example Demos then you shouldn't have too many problems. \$\endgroup\$
    – PeterT
    Commented Feb 4, 2012 at 9:26
  • \$\begingroup\$ Also check the examples in the bullet folder, there are a bunch of 'em \$\endgroup\$ Commented Feb 4, 2012 at 12:38
  • \$\begingroup\$ @MaikSemder I wasn't quite sure how to open specific ones. are make files linux only? \$\endgroup\$ Commented Feb 4, 2012 at 13:13
  • \$\begingroup\$ actually notes on how to open the examples would be incredibly helpful, then I could just see how they've linked things together there. I will google around for this but I thought I should ask while I can. \$\endgroup\$ Commented Feb 4, 2012 at 13:18
  • \$\begingroup\$ That depends on what platform you are. For visual studio on windows there is an .sln file for the examples, i assume that is what you use. Just search for the sln file in the bullet folder. \$\endgroup\$ Commented Feb 5, 2012 at 2:26

1 Answer 1

25
\$\begingroup\$

Here's the basic steps you'll need to folow:

  1. First create a world object (i.e. btDiscreteDynamicsWorld) to drive your physics simulation.

  2. You should already have a class such as GameObject that perhaps stores a model along with its bounding box and position/orientation in the world. Replace the position/orientation information with an instance of a physics body object (i.e. btRigidBody) and when rendering the model, use the information provided by the body instead. When creating the body you'll need to provide its mass and collision shape which should match the bounding volumes you already have. I've talked about this in your other question too.

  3. Add each of your game object's bodies to the world object.

  4. Update the simulation by stepping the world (i.e. calling stepSimulation on your world).

And take some time to read the manual as it has a lot of information too.


Edit to address comment

I cringe before I ask but... how do I do the very very basic stuff like simply including the right files in my game? If you need specifics I'm looking for the files that will deal with rigid body collisions. Also thank you very much for the help so far!

Well, it would appear from your comment that you've never worked with external C++ libraries before. It's been a while since I did this, but this is how I remember the process to be (in Visual Studio).

For starters I quote the manual which already explains what you need:

- #include “btBulletDynamicsCommon.h” in your source file 
- Required include path: Bullet/src folder 
- Required libraries: BulletDynamics, BulletCollision, LinearMath

And here's the basic steps you will have to follow to fulfill the conditions above...

1. Preparation Step

First of all, extract the file you downloaded into a known directory, e.g. C:\Bullet. You'll need to know the path to this folder later.

Inside there are two folders that you will need to reference in your project. The first is the src folder which holds the .h header files that you will include in your source code. The second is the lib folder which will hold the .lib library files that you will link to your project. Notice that including and linking are two different things.

But the lib folder should be empty for now, because you haven't built the engine yet. So refer to the manual on how to build the project using CMake and Visual Studio for instance. It's on page 7.

After you succeed, you should have at least three files in the libfolder: BulletDynamics.lib, BulletCollision.lib and LinearMath.lib (I am guessing from the manual). Now to make the connection between Bullet and your project...

2. Include Headers

First of all, you'll need to add the C:\Bullet\src folder to your project's include path options. You can do so in Visual Studio by right-clicking on your project, navigating to Configuration Properties -> C/C++ -> General -> Additional Include Directories and writing the directory path in there.

After setting that up, you can simply do #include “btBulletDynamicsCommon.h” on your code. That header seems to serve as an hub to all features you require.

3. Link Libraries

Finally you'll need to link the libraries mentioned above. Frist, under Configuration Properties -> Linker -> General -> Additional Library Directories add the path to the lib folder, or in other words, C:\Bullet\lib.

Then, under Configuration Properties -> Linker -> Input-> Additional Dependencies, add the name of the libraries to the list of dependencies. Separate each library with a ; and don't forget the file extension. So for instance, you might add this to the end of the list: BulletDynamics.lib;BulletCollision.lib;LinearMath.lib.

After this you should be able to build and run your project.

\$\endgroup\$
6
  • \$\begingroup\$ I cringe before I ask but... how do I do the very very basic stuff like simply including the right files in my game? If you need specifics I'm looking for the files that will deal with rigid body collisions. Also thank you very much for the help so far! \$\endgroup\$ Commented Feb 4, 2012 at 13:14
  • \$\begingroup\$ @AsherEinhorn Check my edit. \$\endgroup\$ Commented Feb 4, 2012 at 13:52
  • \$\begingroup\$ @AsherEinhorn No problem, this did stumble me too the first time I worked with C++ libraries a couple of years ago. \$\endgroup\$ Commented Feb 4, 2012 at 14:00
  • \$\begingroup\$ Yeah, it's one of those things I've just kind of avoided up until now, all the code in my games is mine, but trying to write my own physics engine is just a waste of time when other people have done them better than I probably ever will. \$\endgroup\$ Commented Feb 4, 2012 at 14:02
  • \$\begingroup\$ @AsherEinhorn Yes, don't bother writing your own physics engine even if the game appears simple. The first time I used a physics engine was after trying to implement it myself on a simple 2D game. I implemented OBB-OBB collision detection using the separating axis theorem, but when I reached the point where I needed collision response, I was completely stuck. Then I figured I might as well try a physics engine (in particular I used Box2D) and in under one hour I had everything up and running. \$\endgroup\$ Commented Feb 4, 2012 at 14:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .