Collision Detection

Hi there,

I’m very new to C++ OF. I usually code AS3.0.
The reason for me to look into OF is due to performance reasons in flash.

I would like to have text on stage collision tested against each other.
Now in AS3.0 Grant-Skinner’s pixel perfect collision approach is pretty straight forward by simply drawing a textfield object into a bitmapData object, performing a bounding box test and , if true, blending those two bitmapData objects into a third. An alpha map then makes it fairly easy to figure out if objects are colliding or not.

:?: Is there a similar way of testing collision in OF?

Can anyone help me out on this?

Thx

Gabor

Hi,

I am new here as well, and I have the same background, so I will try my best to help.

Not sure if there is a similar technique in OF, I am sure it can be done, but how about using one of the physics addons? ofxBox2d for example? it has everything you need, I manage to get ofxBox2d up and running in no time, so you just have to worry on making your project pretty and not spend time in reinventing a collision detection code.

Well I recommend that but I am not sure if that will be the best way to go for your project, I can give you some source code (very basic) using ofxBox2d if you need it, so let me know.

Cheers
rS

Hey nardove,

thx for your reply.

Yeah, I have read about “Box2DFlash” a little.
I would then probably create a shape like a box for example and skin it with some texture, right? But could I then also collision detect that box, carrying my texture, against ofCircle (no Box2D body or shape) for example? I’d like to bounce off ofxContourFinder outline just like http://forum.openframeworks.cc/t/circle-to-circle-collisions-and-physics/2004/5

I will have another, more detailed look into Box2D now and will report back, if it suits my purpose.

I fear that adding effects to the texture (ie. onCollision or scaling) could prove difficult though.

What have you achieved with Box2D?

Cheers

g

I would then probably create a shape like a box for example and skin it with some texture, right?

Yes, that is how you do it

But could I then also collision detect that box, carrying my texture, against ofCircle (no Box2D body or shape) for example?

No, every collision has to be against another box2d body, box2d have no idea what ofCircle is

I’d like to bounce off ofxContourFinder outline just like

Looks pretty cool, but I havent play with that kind of stuff yet, have you check the openCV example app? I think you can see how its implemented there

Once I get home I will share my box2d “helloWorld” sketch, it is for the ofxiPhone Of version but the source code works on both

Cheers
rS

1 Like

Thanks mate. Much appreciated. 8)

There may be a solution to getting around using the skinning approach by utilizing

  
void b2PolygonShape::Set(const b2Vec2* vertices, int32 count)  

Looks to me as if I only had to pass on a list of points as a vector and b2PolygonShape::set() draws me a custom Polygon shape. The vector of points could be received through

  
ofTTFContour.pts  

which should return a vector of points describing the contour of my TrueTypeFont loaded.

Now this sounds all pretty good by looking at it but I’m quite sure I have missed something that will spoil my current excitement about a possible approach.

For example:

  • what about wholes inside a poly shape (i.e. in the letter ‘B’) will they be drawn correctly or at all?
  • the max. amount of vertices to be supplied
  • concave and convex shape issue

But oh well…at this point I haven’t even gotten Box2D to successfully compile. Receiving like 3400something errors.

Cheers

g

Found an interesting post in OF Forum with a very cool outcome.

http://www.openframeworks.cc/forum/search.php?st=0&sk=t&sd=d&keywords=box2d&start=15

g

[quote author=“GaborZins”]
But oh well…at this point I haven’t even gotten Box2D to successfully compile. Receiving like 3400something errors.
g[/quote]

For everyone with the same problem on XCode:

Installation:
Firstly make sure you read the Building.txt I haven’t at first. :roll:
Follow the steps listed in order to install Box2D.

In Xcode:
Make sure you have added Box2D path to your header search paths and have it ticked.
Make sure “Always search user paths” is ticked

Should work now.

g

Hi there, sorry for the delay.

Attach you can find the source files I mention, they for ofxiPhone but you can take all the box2d stuff to copy and paste in you project and it should work

Hope this helps
rS

src.zip

Hey nardove,

thanks for the file :smiley:

g

very nice.

thanks.

do you think there is a way to have outer boundaries that can take on any shape.
i would like to have the circles arrange themselves inside an ellipse.

thanks for any advice.
stephan.

You might want to look at http://opensteer.sourceforge.net/

ok. i figured it out.

in the example you i can draw lineshapes. those lineshapes can be used to keep objects (circles) contained.
but i had to make sure i am drawing this lineshape counter clock wise, otherwise objects will fall right through the lineshape.

thanks everyone.
stephan