hi all
so i am trying to get certain particles to change on collision. I understand that I should be able to use a box2d body’s userdata to store a pointer to my objects. so i create my particles with something like:
BubbleParticle p;//extends ofxBox2dCircle
p.setup(box2d.getWorld(), x, y, 10);
p.body->SetUserData(&p);
bubbleParticles.push_back(p);
then in my contact listener i have:
void Add(const b2ContactPoint* point) {
b2Vec2 p = point->position;
p *= OFX_BOX2D_SCALE;
contactAdd(ofPoint(p.x, p.y));
b2Body * b1 = point->shape1->GetBody();
if (b1->GetUserData() != NULL) { //must be bubble
BubbleParticle * bp = (BubbleParticle*)b1->GetUserData();
bp->collide();
contact_points.push_back(p);
}
this seems to detect the collisions correctly as the contact_points vector gets updated correctly. However, bp->collide(); does not work. I seem to be unable to call anything inside the object. am I doing something wrong when I add the bubble particle to the vector not as a pointer? any help on how to do this greatly appreciated.