Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Box2D physics for Allegro

This thread is locked; no one can reply to it. rss feed Print
Box2D physics for Allegro
Johan Peitz
Member #9
April 2000
avatar

Hello Allegators!

{"name":"591296","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/8\/b8da1efc57ceb750f7a17d27b1cad77e.png","w":649,"h":514,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/b\/8\/b8da1efc57ceb750f7a17d27b1cad77e"}591296{"name":"591297","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/1\/71a56b49b1aa3dae3edb92b7cc60f6af.png","w":648,"h":514,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/1\/71a56b49b1aa3dae3edb92b7cc60f6af"}591297

I've been busy porting Erin Catto's Box2D physics tutorial to Allegro and it went pretty smooth. Not much porting to do really since most of it is math which didn't require any porting so mostly I've been converting openGl calls to Allegro. Other than that I've rearranged the demos a bit and made the main code a bit easier to use (less pointers - more stl).

I'd like to work more on it and make it easily plugin able to any game but I don't know how much time I have for that... In the meantime I thought I might as well present what I've got and see if anyone of you guys might need some box physics. Feel free to do whatever you want with it (more or less).

Also, feel free to comment give me some tips on what to improve etc etc.

Soruce and binary (win) attached.

--
johan peitz :: things I made

kazzmir
Member #1,786
December 2001
avatar

$ g++ *.cpp -o game `allegro-config --libs`
main.cpp:775: error: `main' must return `int'

The physics is really cool. I can't say that I understand that math after looking through the source but it doesn't look that complicated. I'll wait for someone else to explain it in laymen's terms I suppose.

Two things
1. the cpu usage was always 100%. I changed rest(0) to rest(1) and the usage dropped to 70% which is still fairly high for an amd 2.2 ghz which leads me to believe this kind of physics is difficult to use in games.
2. after a while the game hung, I dont think it crashed because the cpu usage was constant. maybe an infinite loop or something.

GrantG
Member #8,173
December 2006
avatar

Yea I got it to freeze as well, after I filled half of the screen with boxes, but it didn't slowly start lagging (it was running quite fast actually), it just suddenly froze.

Johan Peitz
Member #9
April 2000
avatar

Actually, it doesn't freeze. The physics algo is currently O(n^2) and once there are too many boxes it never has the time to draw anything at all, but it still runs. Press 1 or any other demo key to reset it.

--
johan peitz :: things I made

Albin Engström
Member #8,110
December 2006
avatar

if i could kiss you.. i would.

nonnus29
Member #2,606
August 2002
avatar

Yep, cool. Now somebody make a platformer with it, for the love of Alex...

:o

Paul Pridham
Member #250
April 2000
avatar

Johan said:

The physics algo is currently O(n^2)

Ahh, it would be nice if the interactions could be sectorized. That would help a ton for platformery type games.

Johan Peitz
Member #9
April 2000
avatar

Luckily, that's what I'm working on right now! (Sectors.) I found someone elses addon to Box2D and it does this except that it is a bit wonky on my end so I'm trying to get it working properly.

--
johan peitz :: things I made

Paul Pridham
Member #250
April 2000
avatar

Cool stuff. Did you notice any extensions for shapes other than boxes on your travels? ;) Not that boxes wouldn't be good enough for 95% of most gameplay.

Johan Peitz
Member #9
April 2000
avatar

Thanks!

Currently I've got circles as well.
{"name":"591304","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/7\/779d319efdf3a7e97d1293884e25a08b.png","w":535,"h":412,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/7\/779d319efdf3a7e97d1293884e25a08b"}591304

I've got a really stupid bug right now that makes random objects fly around. It's probably because I only used parts of the updated code I found, so I'll just compare what's left of it. Some time. :)

--
johan peitz :: things I made

Ceagon Xylas
Member #5,495
February 2005
avatar

Oh how fun! Can't wait!

Paul whoknows
Member #5,081
September 2004
avatar

Those demos are really nice.
However it freezes when I put a lot of objects.
Great work!

____

"The unlimited potential has been replaced by the concrete reality of what I programmed today." - Jordan Mechner.

Kauhiz
Member #4,798
July 2004

Peitz said:

Actually, it doesn't freeze. The physics algo is currently O(n^2) and once there are too many boxes it never has the time to draw anything at all, but it still runs. Press 1 or any other demo key to reset it.

---
It's Ridge Racer! RIIIIIDGE RAAAAACER!

Go to: