Again oF + Box2d - Diamonds alchemy

It is just another example of using Box2D with oF.

http://www.youtube.com/watch?v=Rr-3n1ovYZk

openframeworks - platform,
openCV - background removal (codebooks method) and contour filtering,
box2D - physics.

The interesting thing is how I apply objects from camera to box2D.
It is made not by inserting object’s contours into box2D world directly,
but changing positions of box2D objects and applying forces.

Using this engine, we also made Basketball game:

http://www.youtube.com/watch?v=S2FQZnFQxB8

Demo (for Windows):
http://www.playbat.net/en/products/basketball.html


Sources (for Visual Studio 2008):
http://www.playbat.net/download/basketball/Basketball.src.zip

See GettingStarted.pdf for explanation how to work with.
Notes

  1. there is no Configurer, mentioned in GettingStarted - instead you should change data/settings.ini manually.
  2. OpenCV2.1 needed to be installed in C:\Program Files\OpenCV2.1
1 Like

The interesting thing is how I apply objects from camera to box2D.
It is made not by inserting object’s contours into box2D world directly,
but changing positions of box2D objects and applying forces.

I’m currently working on the same issue and facing some problems making the contour (a box2d linestrip in my case) really interactive, i.e. my contour can’t push other objects, yet.

I understand that you can’t put a new linestrip from the opencv blob every frame in order to solve that problem.
So what do you mean exactly by saying you change the positions of box2d objects and apply forces?

Your help is much appreciated. I’m stuck here for days now.

have you done the workaround of aligning boxes around the contour?

I’m analyzing relative position of the balls and the opencv contours:
when the ball is inside the contour, I’m adding the force to the ball in the shortest direction to push it out from the contour. (Currently I’m not managing ball rotation - so you can see some artifacts on this.)

Wow!
I’ve been trying to do this for so long. Could I ask you for a bit more information? how did you managed to use contour filtering and turn it into a box2d object that can transfer energy onto other box2d objects?

I’ve used the Delaunay method that is somewhere here in this forum but your method seems much better!
=D

Thanks for the interest. Please check the code:

http://www.playbat.net/download/basketball/Basketball.src.zip
and void applyForces( IplImage *mask ) in testApp.cpp is that you interested for.


See GettingStarted.pdf for explanation how to work with.
Notes

  1. there is no Configurer, mentioned in GettingStarted - instead you should change data/settings.ini manually.
  2. OpenCV2.1 needed to be installed in C:\Program Files\OpenCV2.1

Thank you VERY much! :o
I have much to learn from it! thank you :stuck_out_tongue:

Hi Perevalovds,

Love your nice background removal. Very clean.

Anyway you could release your Diamond Alchemy and/or Basketball codes in either Mac version, or in Windows code::blocks version? I am not too familiar with Visual Studio. Thanks.

–Oze

could you pls release the mac (xcode) version for the same. I am very much interested in trying the same with kinect. can you guide me. thanks

Here is updated link to sources:

Code is still for Windows only.

We published ofxKuBox2d addon which combines Box2D and binary masks (from depth or web camera).
It implements the technique of working with Box2D used in Diamonds Alchemy.

1 Like