Box2D

I want to use box2d with SDL.can someone give me an example?

I’m not sure I see the need for an example. If you are familiar with a
rendering API, try out box2d from it. If you aren’t familiar with a
rendering API, then learn how to use SDL first. If you know box2d and
SDL, then wiring them together shouldn’t be too tricky. The main
complexity is deciding how you want to render rotations. If you use
OpenGL for drawing, it will be reasonably simple. Doing complex
rotations on the CPU using SDL (e.g. SDL_gfx) probably will not scale
to large, dynamic scenes.

If you have a specific question, then we can answer it. In general,
googling “box2d SDL” or “opengl box2d” gives some results, though I
will not vouch for the quality. Remember the golden rule of technical
questions: what have you tried

http://mattgemmell.com/2008/12/08/what-have-you-tried/On 10 May 2012 22:06, Olga Keskin wrote:

I want to use box2d with SDL.can someone give me an example?

Box2D doesn’t integrate with SDL in a way that makes answering this
question meaningful. In the end, you need to know to how use Box2D, and
then when you’re done, you render the result with SDL. So if Box2D tells
you that after collision, your rectangle is centered on 100,100 and it is
50x50 units in size, then draw a rectangle from (75,75) to (125,125). If
you can be more specific about what you need, then I think people could
help a bit more, but you’re still going to have to be proficient in Box2D
and SDL to avoid cargo cult programming. If you already know how to use SDL
pretty well, maybe you should be reading more about Box2D.

I don’t know how else to say it, but if you understand both well, then how
to use them together is probably obvious.

PatrickOn Thu, May 10, 2012 at 4:06 PM, Olga Keskin wrote:

I want to use box2d with SDL.can someone give me an example?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

It is pretty simple to integrate SDL and Box2D, it just takes a little time
to type it all out. If you can draw lines, polygons, and circles (via
Sprig or SDL_gfx, for example), then you have everything you need to draw
the collision shapes that Box2D uses. As mentioned already, rotated
sprites are nice, too, in case you want something that looks good instead
of just functional.

You will probably want to use a scaling factor instead of the implied scale
of 1px = 1 Box2D length unit. It’s usually best to treat the Box2D length
unit as 1 meter. Beside that, if you want to draw every b2Fixture of a
b2Body, you have to iterate over them all and use the b2Fixture interface
to get the geometry data. The Box2D headers are reasonable to read and the
Doxygen files they generate are good. You can find some online if you look
for them (here’s one: http://hodade.adam.ne.jp/box2d/API/html/index.html).
The worst part is that Box2D is popular in Flash games, so you run into a
lot of Actionscript code and references online.

Jonny D

I’m going to side with Brian and Jon, you’re going to want to look into a
graphics extension for SDL, like SDL_gfx or maybe even OpenGL (if you’re
comfortable with it). Probably to just test things out, SDL_gfx might be a
quick drop-in (as I’m not familiar with the suggested Sprig).
-AlexOn Thu, May 10, 2012 at 6:50 PM, Jonathan Dearborn wrote:

It is pretty simple to integrate SDL and Box2D, it just takes a little
time to type it all out. If you can draw lines, polygons, and circles (via
Sprig or SDL_gfx, for example), then you have everything you need to draw
the collision shapes that Box2D uses. As mentioned already, rotated
sprites are nice, too, in case you want something that looks good instead
of just functional.

You will probably want to use a scaling factor instead of the implied
scale of 1px = 1 Box2D length unit. It’s usually best to treat the Box2D
length unit as 1 meter. Beside that, if you want to draw every b2Fixture
of a b2Body, you have to iterate over them all and use the b2Fixture
interface to get the geometry data. The Box2D headers are reasonable to
read and the Doxygen files they generate are good. You can find some
online if you look for them (here’s one:
http://hodade.adam.ne.jp/box2d/API/html/index.html). The worst part is
that Box2D is popular in Flash games, so you run into a lot of Actionscript
code and references online.

Jonny D


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org