I am trying to detect collisions between blobs and other objects, such as circles or boxes, but the usual Google search on the subject doesn’t seem to bring up much useful material, which is surprising as apparently it is quite a common project for beginners.
Does anybody know the best way to test the collision of an object against an ofxCvBlob please? Or know of any resources that might be of use?
I understand this is probably more of a maths related question, any help would be greatly appreciated.
i don’t really know how to answer you but:
ofxCvBlob has boundingRect for an approximate collision detection and
has also pts.
i think a solution should be write a little adapter class that contains (via composition or inheritance?) both ofxCvBlob and ofxBox2dPolygon and make collision detection with box2d
Absolutely amazing stuff, can’t seem to find the code for it anywhere though, none of the links work would love to see the techniques used.
I think this is the sort of thing I am looking for though, need to work out how to convert the contours of a blob into a Box2D shape and then use it for collision against other obstacles.
Ok, I have given it a go, tried the following in the update call, where polyLines is a vector.
Works ok, but I believe there is some sort of memory leak or other type of problem as after a while it becomes slugglish then finally breaks.
vector <ofPoint> pts = contourFinder.blobs[0].pts;
polyLines.clear();
ofxBox2dPolygon poly;
for (int i = 0; i < pts.size(); i++) {
poly.addVertex(pts[i]);
}
poly.create(box2d.getWorld());
polyLines.push_back(poly);
Can anybody comment on whether I am going about this the right way or is this completely the wrong approach, just trying to convert a blob contour into a Box2D shape for use with collision detection :).