i use box2d in OF.
what’s your problem?
what’s the error msg?
what platform are you on?
i just followed the instructions in the user manual and it worked.
just make sure that you use the right scale: http://www.box2d.org/manual.html#units
that means: objects should be between 0.1 and 10 units large. otherwise you get all kinds of strange effects. it took me quite a while to figure that out.
I was yesterday looking for a physical engine. I was indeed trying ode, when i saw this post and decided to give Box2d a try as all I need is 2d.
I’ ve been trying with small measures between 0.1 and 10 an then multiplying positions and sizes by 100 when drawing, it more or less works at the beginning, but gets pretty innacurate in not much time.
Any clue on how to convert meters to pixels?, I’ve read in the manual that they use openGL viewport transform, but I don’t know very much about openGL, also the reverse coordinate system in OF is an issue when I try to adapt code from their examples.
you can invent your own way of converting meters to pixels. i decided that my screen is 10m wide. so one pixel is 10/maxx.
you don’t have to care about reverse coordinate systems. the only difference might be that gravity pulls your shapes upwards. if you don’t like that just invert the direction of gravity.
you have to tweak the other parameters like mass. be sure to calculate mass, inertia and inv-inertia with the supplied functions.
That helped, indeed I was also trying to draw shapes appliying the body’s angle as rotation and then getting it’s coordinates, so I ended with really strange effects like objects floating or not colliding as they should.
About the scaling, yes you have to scale the rendering, in the code you post, your bodies will measure 300x300 m, apart that it’s strange working with that dimensions, Box2d only works well with objects between 0.1 and 10 meters. So you’ll end with strange behaviours.
Try what jroge suggests, give your screen a measure in meters and then find the proportions between that and the pixels width and height then when rendering multiply every position by that proportions, it works really well for me.
i found some severe limitations in box2d. if i add more than 150 bodies (all rectangles) and speed them up quite a bit they seem to collide very often so there are some assertions in box2d-code that fail.
under 150 bodies i don’t have this problem. of course you can always change the limits in the box2d header and recompile but i fear the performance will decrease.
chipmunk used to be much more tolerant in this regard but it was much less reliable (although much faster). for my inkscape plugin i was able to use more than 1000 shapes, but i won’t recommend it for realtime.
i started with chipmunk and made a first prototype with it but decided to switch to box2d. i had so many problems with chipmunk (bodies falling through floors etc.). but maybe it was some wrong code i wrote. for the non-realtime physics plugin i wrote for inkscape it worked alright.
I’ve been testing chipmunk also, here’s what i’ve seen…
much more accurate
uses preconditions assertion, so if you create an object that it’s not going to work (concave for example), it advice you with an error, that hangs the app, although I suppose is just an exception that can be chaught.
more elements, like bullets
properties names are more intuitive than chipmunk where everything is called p, u, v…
perhaps a little bit faster
allows many more vertex in a shape by default
allows linear objects, for example to draw terrain curves
doesn’t have measure limitations, so you can work directly with pixels
Can someone post testApp.h and testApp.cpp for Box2D?
I am including the header Box2D.h and try to implement the trivial “hello world” example found at the beginning of Box2D doc. But the compiler produces a weird error when I declare the world variable in testApp.h ie:
…\src\main.cpp | | In function int main()':| ...\src\main.cpp |14| error: no matching function for call totestApp::testApp()’|
…\src\testApp.h |6|note: candidates are: testApp::testApp(const testApp&)|
||=== Build finished: 1 errors, 0 warnings ===|
Most probably I am doing something wrong, although I can’t figure out what…
and the error is very strange…
The box2d “hello world” example is not supposed to render anything, but I am thinking that the error might have to do with the internal renderer of Box2D getting mixed up with the OF one…I’ll have to dig-on…
if you want to zip up anything that I can recreate in 0.05 codeblocks I’ll give it a try… I’m curious about this error occuring on two different compilers, it’s a bit weird and would like to see it in action. if you do upload, be sure to include any libs (box2d, etc) that are needed to compile.