← Back

ofxBox3d

github.com/danoli3/ofxBox3d · @danoli3
OF 0.12 Physics

Box3D is a 3D physics engine for games - The addon includes a world manager that supports fixed-timestep stepping for consistent physics simulation.

2 0 Last commit 2mo ago Created 2mo ago

README

ofxBox3d



openFrameworks wrapper for Box3D — Erin Catto's open-source 3D rigid-body physics engine (the 3D successor to Box2D).

Status: Alpha, matching the vendored Box3D revision

Features



Requirements



Installation



cd openFrameworks/addons
git clone https://github.com/YOUR_USERNAME/ofxBox3d.git
cd ofxBox3d
git submodule update --init --recursive   # or manually clone box3d into libs/box3d


Integrating Box3D



Recommended: git submodule

cd libs
git submodule add https://github.com/erincatto/box3d.git box3d


Then either:

1. Preferred (CMake projects): Use FetchContent or add_subdirectory(libs/box3d) in your app’s CMakeLists and link box3d::box3d. 2. Classic OF Makefile / Project Generator: The addon’s addon_config.mk will list the Box3D sources so they are compiled into your project. (You may need to adjust for your platform / SIMD flags.)

See docs/integration.md for details.

Quick Start



#include "ofxBox3dAll.h"

ofxBox3d physics;

void ofApp::setup() {
    physics.setup();                       // default gravity (0, -10, 0)
    // physics.setGravity({0, -9.81f, 0});
    // ofxBox3dUtils::setScale(100.f);     // 100 OF units = 1 meter (optional)

    auto ground = make_shared<ofxBox3dBox>();
    ground->setup(physics, {0, -1, 0}, {20, 1, 20});  // pos, half-extents
    physics.addBody(ground);

    auto box = make_shared<ofxBox3dBox>();
    box->setup(physics, {0, 5, 0}, {0.5f, 0.5f, 0.5f});
    box->setDensity(1.f);
    box->setFriction(0.3f);
    physics.addBody(box);
}

void ofApp::update() {
    physics.update();   // steps at 60 Hz with 4 sub-steps by default
}

void ofApp::draw() {
    ofEnableDepthTest();
    cam.begin();
    physics.draw();     // debug draw all registered bodies
    // or draw individual bodies / your own meshes driven by body transforms
    cam.end();
}


Examples



License



MIT (same as Box3D and typical OF addons)

Box3D itself is MIT — © Erin Catto.

Credits



Get this addon

HTTPS
SSH