Convert Figma logo to code with AI

bulletphysics logobullet3

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

12,417
2,860
12,417
328

Top Related Projects

88,735

Godot Engine – Multi-platform 2D and 3D game engine

8,069

Box2D is a 2D physics engine for games

3,152

NVIDIA PhysX SDK

2D physics engine for games

Quick Overview

Bullet3 is an open-source physics engine primarily used for collision detection, soft and rigid body dynamics simulation. It is widely adopted in game development, robotics, and visual effects industries, providing a robust and efficient solution for real-time physics simulations.

Pros

  • High performance and optimized for real-time applications
  • Cross-platform compatibility (Windows, Linux, macOS, and mobile platforms)
  • Extensive feature set including rigid body dynamics, soft body simulation, and vehicle dynamics
  • Active community and ongoing development

Cons

  • Steep learning curve for beginners
  • Documentation can be inconsistent or outdated in some areas
  • Limited built-in support for certain advanced physics features (e.g., fluid dynamics)
  • Performance can degrade with very complex simulations

Code Examples

  1. Creating a rigid body:
btCollisionShape* shape = new btSphereShape(1.0);
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
btRigidBody::btRigidBodyConstructionInfo rbInfo(1.0, motionState, shape);
btRigidBody* body = new btRigidBody(rbInfo);
dynamicsWorld->addRigidBody(body);
  1. Applying force to a rigid body:
btVector3 force(10.0, 0.0, 0.0);
btVector3 relativePos(0.0, 0.0, 0.0);
body->applyForce(force, relativePos);
  1. Performing a raycast:
btVector3 from(0, 0, 0);
btVector3 to(10, 0, 0);
btCollisionWorld::ClosestRayResultCallback rayCallback(from, to);
dynamicsWorld->rayTest(from, to, rayCallback);

if (rayCallback.hasHit()) {
    btVector3 hitPoint = rayCallback.m_hitPointWorld;
    // Process hit point
}

Getting Started

  1. Clone the repository:

    git clone https://github.com/bulletphysics/bullet3.git
    
  2. Build the library:

    cd bullet3
    mkdir build && cd build
    cmake ..
    make
    
  3. Include Bullet in your project:

    #include <btBulletDynamicsCommon.h>
    
  4. Initialize the physics world:

    btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
    btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
    btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
    btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
    btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);
    dynamicsWorld->setGravity(btVector3(0, -9.81, 0));
    

Competitor Comparisons

88,735

Godot Engine – Multi-platform 2D and 3D game engine

Pros of Godot

  • Complete game engine with built-in editor, scripting, and asset management
  • Cross-platform support for multiple desktop and mobile platforms
  • Active community and extensive documentation

Cons of Godot

  • Less specialized for physics simulations compared to Bullet
  • Potentially higher resource usage due to full engine overhead

Code Comparison

Godot (GDScript):

var body = RigidBody.new()
body.mass = 10
body.apply_impulse(Vector3.ZERO, Vector3(0, 10, 0))
add_child(body)

Bullet (C++):

btRigidBody* body = new btRigidBody(10, nullptr, nullptr);
btVector3 impulse(0, 10, 0);
body->applyCentralImpulse(impulse);
dynamicsWorld->addRigidBody(body);

Summary

Godot is a full-featured game engine offering a complete development environment, while Bullet is a specialized physics library. Godot provides an all-in-one solution for game development with built-in tools and cross-platform support. However, Bullet may offer more advanced physics simulations and potentially better performance for physics-heavy applications. The choice between them depends on the specific project requirements and the developer's focus on general game development versus specialized physics simulations.

8,069

Box2D is a 2D physics engine for games

Pros of Box2D

  • Simpler and more lightweight, ideal for 2D games and simulations
  • Easier to learn and implement, with a focus on 2D physics
  • Better performance for 2D-specific scenarios

Cons of Box2D

  • Limited to 2D physics, lacking 3D capabilities
  • Less feature-rich compared to Bullet, with fewer advanced physics simulations
  • Smaller community and ecosystem

Code Comparison

Box2D (C++):

b2Vec2 gravity(0.0f, -10.0f);
b2World world(gravity);
b2BodyDef groundBodyDef;
b2Body* groundBody = world.CreateBody(&groundBodyDef);

Bullet (C++):

btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btBroadphaseInterface* overlappingPairCache = new btDbvtBroadphase();
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;

Box2D is a 2D physics engine, while Bullet is a more comprehensive 3D physics library. Box2D is simpler and more focused, making it easier to use for 2D projects. Bullet offers more advanced features and 3D capabilities but has a steeper learning curve. The code comparison shows the difference in complexity, with Box2D requiring less setup for basic physics simulations.

3,152

NVIDIA PhysX SDK

Pros of PhysX

  • Highly optimized for NVIDIA GPUs, offering excellent performance on supported hardware
  • More extensive documentation and support from NVIDIA
  • Wider adoption in commercial game engines and AAA titles

Cons of PhysX

  • Closed-source and proprietary, limiting customization options
  • Platform-dependent, with best performance on NVIDIA hardware
  • Potentially higher licensing costs for commercial projects

Code Comparison

PhysX:

PxRigidDynamic* dynamicActor = physics.createRigidDynamic(PxTransform(0, 0, 0));
PxRigidStatic* staticActor = physics.createRigidStatic(PxTransform(0, 0, 0));
PxShape* shape = physics.createShape(PxSphereGeometry(1.0f), *material);
dynamicActor->attachShape(*shape);

Bullet:

btCollisionShape* shape = new btSphereShape(1.0f);
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, 0, 0)));
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, motionState, shape, localInertia);
btRigidBody* body = new btRigidBody(rbInfo);

Both libraries offer similar functionality for creating rigid bodies and shapes, but with different syntax and object structures. PhysX uses a more object-oriented approach, while Bullet's API is more C-like.

2D physics engine for games

Pros of LiquidFun

  • Specialized in fluid and soft-body simulations
  • Optimized for mobile devices and web browsers
  • Includes particle-based fluid, cloth, and soft-body simulations

Cons of LiquidFun

  • Less active development and community support
  • More limited in scope compared to Bullet's broader physics capabilities
  • Fewer features for rigid body dynamics and constraints

Code Comparison

LiquidFun:

b2World world(gravity);
b2ParticleSystemDef particleSystemDef;
b2ParticleSystem* particleSystem = world.CreateParticleSystem(&particleSystemDef);
b2ParticleGroupDef pd;
pd.flags = b2_waterParticle;
particleSystem->CreateParticleGroup(pd);

Bullet:

btDiscreteDynamicsWorld* dynamicsWorld;
btRigidBody* body = new btRigidBody(rbInfo);
dynamicsWorld->addRigidBody(body);
dynamicsWorld->stepSimulation(1.f/60.f, 10);

Summary

Bullet3 is a comprehensive physics engine with broad capabilities, while LiquidFun focuses on fluid and soft-body simulations. Bullet3 offers more features and active development, making it suitable for a wider range of applications. LiquidFun, however, excels in specialized fluid simulations and is optimized for mobile and web platforms. The choice between them depends on the specific requirements of your project, with Bullet3 being more versatile and LiquidFun offering specialized fluid dynamics.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Travis Build Status Appveyor Build status

Bullet Physics SDK

This is the official C++ source code repository of the Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

PyBullet

Issues

The Issue tracker was flooded with support questions and is closed until it is cleaned up. Use the PyBullet forums to discuss with others.

PyBullet

It is highly recommended to use PyBullet Python bindings for improved support for robotics, reinforcement learning and VR. Use pip install pybullet and checkout the PyBullet Quickstart Guide.

Installation is simple:

pip3 install pybullet --upgrade --user
python3 -m pybullet_envs.examples.enjoy_TF_AntBulletEnv_v0_2017may
python3 -m pybullet_envs.examples.enjoy_TF_HumanoidFlagrunHarderBulletEnv_v1_2017jul
python3 -m pybullet_envs.deep_mimic.testrl --arg_file run_humanoid3d_backflip_args.txt

If you use PyBullet in your research, please cite it like this:

@MISC{coumans2021,
author =   {Erwin Coumans and Yunfei Bai},
title =    {PyBullet, a Python module for physics simulation for games, robotics and machine learning},
howpublished = {\url{http://pybullet.org}},
year = {2016--2021}
}

Requirements for Bullet Physics C++

A C++ compiler for C++ 2003. The library is tested on Windows, Linux, Mac OSX, iOS, Android, but should likely work on any platform with C++ compiler. Some optional demos require OpenGL 2 or OpenGL 3, there are some non-graphical demos and unit tests too.

Contributors and Coding Style information

https://docs.google.com/document/d/1u9vyzPtrVoVhYqQOGNWUgjRbfwfCdIts_NzmvgiJ144/edit

Requirements for experimental OpenCL GPGPU support

The entire collision detection and rigid body dynamics can be executed on the GPU.

A high-end desktop GPU, such as an AMD Radeon 7970 or NVIDIA GTX 680 or better. We succesfully tested the software under Windows, Linux and Mac OSX. The software currently doesn't work on OpenCL CPU devices. It might run on a laptop GPU but performance will not likely be very good. Note that often an OpenCL drivers fails to compile a kernel. Some unit tests exist to track down the issue, but more work is required to cover all OpenCL kernels.

License

All source code files are licensed under the permissive zlib license (http://opensource.org/licenses/Zlib) unless marked differently in a particular folder/file.

Build instructions for Bullet using vcpkg

You can download and install Bullet using the vcpkg dependency manager:

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install bullet3

The Bullet port in vcpkg is kept up to date by Microsoft team members and community contributors. If the version is out of date, please create an issue or pull request on the vcpkg repository.

Build instructions for Bullet using premake. You can also use cmake instead.

Windows

Click on build_visual_studio_vr_pybullet_double.bat and open build3/vs2010/0_Bullet3Solution.sln When asked, convert the projects to a newer version of Visual Studio. If you installed Python in the C:\ root directory, the batch file should find it automatically. Otherwise, edit this batch file to choose where Python include/lib directories are located.

Windows Virtual Reality sandbox for HTC Vive and Oculus Rift

Build and run the App_SharedMemoryPhysics_VR project, preferably in Release/optimized build. You can connect from Python pybullet to the sandbox using:

import pybullet as p
p.connect(p.SHARED_MEMORY) #or (p.TCP, "localhost", 6667) or (p.UDP, "192.168.86.10",1234)

Linux and Mac OSX gnu make

Make sure gcc and cmake is installed (sudo apt-get install build-essential and sudo apt-get install cmake for Linux, brew install cmake for Mac, or https://cmake.org)

In a terminal type:

./build_cmake_pybullet_double.sh

This script will invoke cmake and build in the build_cmake directory. You can find pybullet in Bullet/examples/pybullet. The BulletExampleBrowser binary will be in Bullet/examples/ExampleBrowser.

You can also build Bullet using premake. There are premake executables in the build3 folder. Depending on your system (Linux 32bit, 64bit or Mac OSX) use one of the following lines Using premake:

cd build3
./premake4_linux --double gmake
./premake4_linux64 --double gmake
./premake4_osx --double --enable_pybullet gmake

Then

cd gmake
make

Note that on Linux, you need to use cmake to build pybullet, since the compiler has issues of mixing shared and static libraries.

Mac OSX Xcode

Click on build3/xcode4.command or in a terminal window execute

./premake_osx xcode4

Usage

The App_ExampleBrowser executables will be located in the bin folder. You can just run it though a terminal/command prompt, or by clicking it.

[--start_demo_name="Demo Name"]     Start with a selected demo  
[--mp4=moviename.mp4]               Create a mp4 movie of the window, requires ffmpeg installed
[--mouse_move_multiplier=0.400000]  Set the mouse move sensitivity
[--mouse_wheel_multiplier=0.01]     Set the mouse wheel sensitivity
[--background_color_red= 0.9]       Set the red component for background color. Same for green and blue
[--fixed_timestep= 0.0]             Use either a real-time delta time (0.0) or a fixed step size (0.016666)

You can use mouse picking to grab objects. When holding the ALT or CONTROL key, you have Maya style camera mouse controls. Press F1 to create a series of screenshots. Hit ESCAPE to exit the demo app.

Check out the docs folder and the Bullet physics forums for further information.