Openframework wrapper for box2d

Related tags

Physics ofxBox2d
Overview

ofxBox2d

ofxBox2d

Introduction

This is a simple wrapper for box2d using Openframeworks. The examples below are still in progressive, but should be stable for the most part. Please open up a issue if you have suggestions or find bugs. The wrapper is using the version Box2D v2.3

Thanks, Todd

Installation

First, pick the branch that matches your version of openFrameworks:

Instructions

When making a vector of objects you need to be careful. You either need to make a vector of pointers of use the shared_ptr object.

Everytime you push into the vector circles the object is destroyed and the created. This causing issues for the b2dBody body object owned by box2d.

Incorrect way to store objects.

vector <ofxBox2dCircle> circles;
ofxBox2dCircle circle;
circles.push_back(circle);

Here is the how to create a vector of box2d objects.

// in your header files
vector <shared_ptr<ofxBox2dCircle> > circles;

// now add a circle to the vector
auto circle = std::make_shared<ofxBox2dCircle>();

// to grab the pointer you use the get() function of shared_ptr (std::shared_ptr)
circle->setPhysics(3.0, 0.53, 0.1);
circle->setup(box2d.getWorld(), 100, 100, 10);
circles.push_back(circle);

Installation

Place ofxBox2d within a folder in the apps folder of the OF dir tree:

openframeworks/addons/ofxBox2d

Compatibility

ofxBox2d is developed against the current version of OpenFramewroks.

If you are using a stable version (007, 0071, ...) of OpenFrameworks then you want to use a git tag of ofxBox2d for that version. You can select the tag in the Github "Current Branch" menu or clone and check it out using git.

For example, the following commands will clone ofxBox2d and switch to the OF 008 tagged version:

git clone git://github.com/vanderlin/ofxBox2d.git
cd ofxBox2d
git checkout 008
Comments
  • Variable length arrays in Visual Studio

    Variable length arrays in Visual Studio

    In Visual Studio it does not compile due to the use of variable length arrays.

    Problematic code (one of many): https://github.com/vanderlin/ofxBox2d/blob/stable/src/ofxBox2dPolygonUtils.h#L115

    If you are using GCC to compile, add the -pedantic during compilation. http://stackoverflow.com/a/20011090/1890362

    opened by MatillaMartin 7
  • issues compiling in Visual Studio

    issues compiling in Visual Studio

    Main issues with triangle_impl.hpp First issue defining sys/time.h, renamed to just time.h to fix this, then i get all these errors.

    1>dpoint.hpp(634): warning C4244: 'return' : conversion from 'double' to 'float', possible loss of data 1>triangle_impl.hpp(3334): warning C4101: 'k' : unreferenced local variable 1>triangle_impl.hpp(3334): warning C4101: 'workstring' : unreferenced local variable 1>triangle_impl.hpp(12536): warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\string.h(105) : see declaration of 'strcpy' 1>triangle_impl.hpp(15374): warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. 1> c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdio.h(234) : see declaration of 'fopen' 1>triangle_impl.hpp(15784): error C2079: 'tv0' uses undefined struct 'piyush::triangulate::timeval' 1>triangle_impl.hpp(15784): error C2079: 'tv1' uses undefined struct 'piyush::triangulate::timeval' 1>triangle_impl.hpp(15784): error C2079: 'tv2' uses undefined struct 'piyush::triangulate::timeval' 1>triangle_impl.hpp(15784): error C2079: 'tv3' uses undefined struct 'piyush::triangulate::timeval' 1>triangle_impl.hpp(15784): error C2079: 'tv4' uses undefined struct 'piyush::triangulate::timeval' 1>triangle_impl.hpp(15784): error C2079: 'tv5' uses undefined struct 'piyush::triangulate::timeval' 1>triangle_impl.hpp(15784): error C2079: 'tv6' uses undefined struct 'piyush::triangulate::timeval' 1>triangle_impl.hpp(15785): error C2079: 'tz' uses undefined struct 'piyush::triangulate::timezone' 1>triangle_impl.hpp(15789): error C3861: 'gettimeofday': identifier not found 1>triangle_impl.hpp(15810): error C3861: 'gettimeofday': identifier not found 1>triangle_impl.hpp(15837): error C3861: 'gettimeofday': identifier not found 1>triangle_impl.hpp(15843): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15843): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15844): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15844): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15869): error C3861: 'gettimeofday': identifier not found 1>triangle_impl.hpp(15872): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15872): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15873): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15873): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15902): error C3861: 'gettimeofday': identifier not found 1>triangle_impl.hpp(15904): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15904): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15905): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15905): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(15918): error C3861: 'gettimeofday': identifier not found 1>triangle_impl.hpp(16065): error C3861: 'gettimeofday': identifier not found 1>triangle_impl.hpp(16067): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(16067): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(16068): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(16068): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(16070): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(16070): error C2228: left of '.tv_sec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(16071): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int' 1>triangle_impl.hpp(16071): error C2228: left of '.tv_usec' must have class/struct/union 1> type is 'int'

    opened by cboctor 6
  • Compiler errors on OSX 10.10/ OF 0.8.4 release

    Compiler errors on OSX 10.10/ OF 0.8.4 release

    Hello,

    I'm trying to help a student with her Box2D code but seem to be getting a bunch of compile errors when running either the examples or a new test app with OSX 10.10 and OF v 0.8.4 release. I initially thought the errors had something to do with compiler language Dialect ("use of undeclared static_assert") but I now think it might have more to do with my version of OF. Do I need to pull a specific 084 tag, or is there a preferred OSX setup for using this addon? Thanks in advance!

    opened by indefinit 5
  • reorganzied/renamed folder structure to follow ofxAddonTemplate, generated projects

    reorganzied/renamed folder structure to follow ofxAddonTemplate, generated projects

    Changes:

    • reorganzied/renamed folder structure to follow ofxAddonTemplate
    • ofxBox2d now works with the OF ProjectGenerator
    • generated project files for OSX, Win VS, and Linux CB
    • updated readme, gitignore, and install.xml

    Also, I found your commits which coincided with version updates (0062-007, 007-0071) and tagged them. There is info in the readme so people know to get a tag if they are using an older version of OF. All you have to do is make a new tag when you are updating for a new OF version in the future.

    I don't think this will be part of the Pull Request, so you can tag them manually:

    • 007: a578ccfb2439812df3e73c7b6963aa2ac6c4cbb6
    • 0062: 793635fe0fe23415e5dddade6755d69431ddb353

    I did it like this:

    git checkout 793635fe0fe23415e5dddade6755d69431ddb353
    git tag 0062
    git checkout a578ccfb2439812df3e73c7b6963aa2ac6c4cbb6
    git tag 007
    git checkout master
    git push --tags  
    
    opened by danomatika 5
  • stable branch should remove project files & rename testApp to ofApp

    stable branch should remove project files & rename testApp to ofApp

    ping @kylemcdonald @bakercp

    This is related to #103.

    The current stable branch has a host of project files, many of which may or may not build. I'd suggest removing all project files and add notes on how generate them with the PG. I ran into this with a room full of students today as I assumed it was fixed with my PR last year: https://github.com/vanderlin/ofxBox2d/pull/105

    Also, the stable branch examples still use "testApp" instead of "ofApp", so they do not work with the PG. This was also fixed my PR. This means the current state of the "stable" branch is that the included example Xcode projects do not work with the latest stable OF 0.9.8 AND the PG chokes since the base app class has the wrong name. Not fun for beginners!

    Another thing, the readme still refers to develop and master branches at the bottom. That should probably be removed. I would also remove the develop branch if it is no longer needed.

    If needed, I have a set of instructions on how to use the PG for my class examples. We could use this text as a template for updating the readme: https://github.com/danomatika/CreativeCodingExamples#generating-project-files

    opened by danomatika 4
  • updates for latest OF & a few bug fixes

    updates for latest OF & a few bug fixes

    Updates

    Updated all examples. Renamed testApp to ofApp. Regenerated Xcode projects. A bunch of whitespace consistency fixes.

    Fixes

    Fixed deprecations with latest OF.

    Added an add-on_config.make with the -DNO_TIMER define needed to build the triangle lib in Visual Studio aka #49.

    Added body getWorldPosition() to fix #99. Tested and works as desired.

    Suggestion

    Since testApp is now ofApp, the project files for the other platforms need to be regenerated as well. At this point, the ProjectGenerator is pretty reliable so I suggest we remove all the project files. People can simply generate them with the PG. This works very well for my addons since I don't have to keep the project files up to date myself.

    If desired, I can do go ahead and remove them in another commit to this PR.

    opened by danomatika 4
  • there are no tags to checkout

    there are no tags to checkout

    README says that I can get a compatible release by checking out a tag with OF version name, but..

    % git clone git://github.com/vanderlin/ofxBox2d.git
    % cd ofxBox2d
    % git checkout 008
    error: pathspec '008' did not match any file(s) known to git.
    % git tag
    %
    

    If we cannot support older version of OF, we should remove this section from README.

    Thanks,

    opened by sidestepism 4
  • weird ofxBox2dRect scaling behavior

    weird ofxBox2dRect scaling behavior

    Hey Todd,

    I was trying to draw an ofImage inside a ofxBox2dRect and had to do some weird stuff to do it

    I uploaded a simple test if you want to check it out https://github.com/jvcleave/Box2dIssueExample

    The first weird part is here: https://github.com/jvcleave/Box2dIssueExample/blob/master/src/testApp.cpp#L77

    And the second here: https://github.com/jvcleave/Box2dIssueExample/blob/master/src/ImageBox.cpp#L16

    Digging in I thought that this line may be a bug https://github.com/vanderlin/ofxBox2d/blob/master/addon/ofxBox2d/src/ofxBox2dRect.cpp#L32

    as OF_RECTMODE_CORNER will always return 0, I think this should be if(ofGetRectMode() == OF_RECTMODE_CORNER)

    but changing that didn't fix my project. I have the workaround for now but am not sure if I am just misunderstanding something, if there is a box2D issue or if it could be an OF bug...

    Hope all is well!

    opened by jvcleave 4
  • Find the vector ID of a shape during a collision

    Find the vector ID of a shape during a collision

    Hi,

    I am playing with collisions using the ContactListenerExample. I wonder if it is possible to get the vector ID ( by vector ID, I mean for example: " circles[0] " 0 would be the ID of this circle. I am not sure to use the right term though ) to find out which shape have been hit.

    here the code in the example: if(e.a->GetType() == b2Shape::e_circle && e.b->GetType() == b2Shape::e_circle) {

    }

    is there any e.b->GetID() that would gave me the item number into the vector circle ?

    Thanks very much.

    opened by LimeJuice 4
  • Error with a new qtcreator 4.0

    Error with a new qtcreator 4.0

    I ve updated the qt creator to new version I mean 4.0 and after this I am receiving the following error. zaznaczenie_003

    I tried to change the following line : zaznaczenie_004

    to this: zaznaczenie_005. After this change the program compiles succesfully but I do not see rectangles in my game. In old qt creator everything is fine ;(

    opened by FieryCod 3
  • Draw functions not working?

    Draw functions not working?

    Hi,

    I am using the last version of ofxBox2d and it's throwing errors in all draw functions (ofDrawLine, ofDrawCircle, etc.). I tested it with all 0.8 releases (0.8.0 to 0.8.4).

    The errors:

    screen shot 2015-04-17 at 17 24 40

    Do you have any idea about why this is happening?

    opened by jorditost 3
  • Some stuff I found useful.

    Some stuff I found useful.

    • ofxBox2dRect: added get and set rectangle functions.
    • ofxBox2dCircle: added getRect() function.
    • ofxBox2dBaseShape: using ofIsFloatEqual to check float value equality. Recalculating mass data when setting density.
    opened by roymacdonald 0
  • compilation error in Qtcreator

    compilation error in Qtcreator

    When I import the ComplexPolygon example into QtCreator, a few errors come up, like:

    ofApp.cpp:56:3: error: cannot initialize object parameter of type 'ofxBox2dBaseShape' with an expression of type 'std::__shared_ptr_access<ofxBox2dCircle, __gnu_cxx::_S_atomic, false, false>::element_type' (aka 'ofxBox2dCircle')

    on line 56 of ofApp.cpp circle->setPhysics(0.3, 0.5, 0.1);

    If I try to compile with Make (just using make from the command line at the root folder of the example), it works. Any ideas?

    I'm using Ubuntu 20.04 Of 0.11.0 with ofxBox2d branch master. Could that be the problem? There is no branch for 0.11.

    opened by brunovianna 0
  • collisions with openCv blobs

    collisions with openCv blobs

    It would be great to have an example that showed how to have ofxBox2d interact with ofxOpenCv. Most of the examples that are out there are old and no longer work. I tried my hand at it, and put it here: https://github.com/david-sullivan/box2dCamera

    Maybe not the best code, but it works (for the most part).

    thanks for the addon!

    opened by david-sullivan 0
  • Revolute Joint

    Revolute Joint

    I've added in ofxBox2dRevoluteJoint. I'm guessing from the fact that there's a jointType member in ofxBox2dJoint that you had intended that class to encapsulate all joints but seemed to make more sense as a separate class. Maybe ofxBox2dJoint could be renamed to ofxBox2dDistanceJoint with a typedef of ofxBox2dJoint for backwards compatibility. Also, haven't added an example but could do if you want...

    opened by neilmendoza 0
  • unified mouse and touch joints and extended beyond 5 touch limit

    unified mouse and touch joints and extended beyond 5 touch limit

    hey @vanderlin & @kylemcdonald,

    ive unified mouse and touch joints, and extended to support any number of touches (previously max limit was 5).

    this will be good for touch screen interactives which usually support 10+ touches.

    have tested, but would be good if someone could give it a once-eye-over.

    opened by julapy 0
Owner
Vanderlin
Vanderlin
Box2D is a 2D physics engine for games

Build Status Box2D Box2D is a 2D physics engine for games. Contributing Please do not submit pull requests with new features or core library changes.

Erin Catto 5.9k Sep 22, 2022
CMake wrapper for Box2D, since it uses premake5

Box2D CMake Support This is a wrapper around the C++ library Box2D. The Source code can be found on Github Status LICENSE Linux / macOS Windows Issues

Tobias Hienzsch 11 Aug 22, 2022
Box2D is a 2D physics engine for games

Build Status Box2D Box2D is a 2D physics engine for games. Contributing Please do not submit pull requests with new features or core library changes.

Erin Catto 5.9k Sep 22, 2022
Box2D is a 2D physics engine for games

Build Status Box2D Box2D is a 2D physics engine for games. Contributing Please do not submit pull requests with new features or core library changes.

Erin Catto 5.9k Sep 17, 2022
Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!

Do you have a question that doesn't require you to open an issue? Join the gitter channel. If you use uvw and you want to say thanks or support the pr

Michele Caini 1.5k Sep 15, 2022
a simple RPC wrapper generator to C/C++ functions

This project initiated from the following practical problem. To control experimental equipment via computers, manufactures provide software drivers wi

Pearu Peterson 32 Jan 25, 2022
An object oriented C++ wrapper for CURL (libcurl)

curlcpp An object-oriented C++ wrapper for cURL tool If you want to know a bit more about cURL and libcurl, you should go on the official website http

Giuseppe Persico 543 Sep 17, 2022
Sol3 (sol2 v3.0) - a C++ <-> Lua API wrapper with advanced features and top notch performance - is here, and it's great! Documentation:

sol2 sol2 is a C++ library binding to Lua. It currently supports all Lua versions 5.1+ (LuaJIT 2.0+ and MoonJIT included). sol2 aims to be easy to use

The Phantom Derpstorm 3.1k Sep 13, 2022
A small C OpenCL wrapper

oclkit, plain and stupid OpenCL helper oclkit is a small set of C functions, to avoid writing the same OpenCL boiler plate over and over again, yet ke

Matthias Vogelgesang 15 Jul 22, 2022
Wrapper library for the BSD sockets API with a nicer C99 interface

A wrapper library for the BSD sockets API. Why? This library trades the series of getaddrinfo, socket, connect, bind, listen, etc. functions and their

Scott Vokes 132 Jun 19, 2022
Implement yolov5 with Tensorrt C++ api, and integrate batchedNMSPlugin. A Python wrapper is also provided.

yolov5 Original codes from tensorrtx. I modified the yololayer and integrated batchedNMSPlugin. A yolov5s.wts is provided for fast demo. How to genera

weiwei zhou 42 Aug 24, 2022
The Ultimate Raylib gaming library wrapper for Nim

NimraylibNow! - The Ultimate Raylib wrapper for Nim The most idiomatic and up-to-date wrapper for Raylib gaming C library. Use this library if you wan

Dmitry Matveyev 124 Sep 9, 2022
cudnn_frontend provides a c++ wrapper for the cudnn backend API and samples on how to use it

cuDNN Frontend API Introduction The cuDNN Frontend API is a C++ header-only library that demonstrates how to use the cuDNN C backend API. The cuDNN C

NVIDIA Corporation 115 Sep 12, 2022
SQLite3++ - C++ wrapper of SQLite3 API

ANNOUNCEMENTS Use files in headeronly_src directory. The files in src are exactly same but in the form of h/cpp files, which you need to compile and l

Wongoo Lee 499 Sep 9, 2022
PhysFS++ is a C++ wrapper for the PhysicsFS library.

PhysFS++ PhysFS++ is a C++ wrapper for the excellent PhysicsFS library by Ryan C. Gordon and others. It is licensed under the zlib license - same as P

Kevin Howell 79 Sep 19, 2022
An Arduino wrapper to @sdima1357's usb_soft_host esp-idf example

ESP32 USB Soft Host library for Arduino IDE This is mainly a wrapper around the excellent work of Dmitry Samsonov (@sdima1357) with esp32_usb_soft_hos

tobozo 121 Sep 15, 2022
libffi wrapper for quickjs

Libffi wrapper for QuickJS. Now supports almost every features of C including primitive types, structs, callbacks and so on License MIT License Copyri

null 44 Sep 5, 2022
A cross-platform wrapper for using SDL2 with ImGui

ImSDL2 ImSDL2 is an open source "wrapper" of imgui backends available for SDL2. It aims to provide a backend-independent yet simple interface for inte

terens 5 Feb 2, 2022
C Wrapper for skottie

Skottie can only be linked statically on the windows platform. If you use SkottieWrapper, you don’t need to directly link the Skottie library and allow C language projects to use Skottie indirectly

Jiong Chang 7 Apr 21, 2022
A simple wrapper for 'pacman' with a syntax similar to 'apt' to help people transitioning to Arch and Arch based distributions like Manjaro.

aptpac aptpac is a program which helps with the transition to Arch Linux and Arch based distros like Manjaro. It simplifies using pacman as it works l

Itai Nelken 16 Sep 22, 2022