2

I'm trying to implement weld joints for my box2d bodies:

for(pos = _contactListener->_contacts.begin(); 
    pos != _contactListener->_contacts.end(); ++pos) {
    MyContact contact = *pos;


    b2Body *bodyA = contact.fixtureA->GetBody();
    b2Body *bodyB = contact.fixtureB->GetBody();

    b2Vec2 worldCoordsAnchorPoint = bodyA->GetWorldPoint (b2Vec2(0,0)); 
    b2WeldJointDef weldJointDef;
    weldJointDef.bodyA = bodyA;
    weldJointDef.bodyB = bodyB;

    weldJointDef.localAnchorA = weldJointDef.bodyA->GetLocalPoint(worldCoordsAnchorPoint);
    weldJointDef.localAnchorB = weldJointDef.bodyB->GetLocalPoint(worldCoordsAnchorPoint);
    weldJointDef.referenceAngle = weldJointDef.bodyB->GetAngle() - weldJointDef.bodyA->GetAngle();
    weldJointDef.collideConnected = true;
    weldJointDef.userData = @"tile";

    weldJointDef.Initialize(bodyA, bodyB, worldCoordsAnchorPoint);
    world->CreateJoint(&weldJointDef);
    //}
}

but my fps are very low. I think it because I don't check that bodies are the ones to weld. How can I check that body are weld? Thanks.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
my_name
  • 31
  • 5

1 Answers1

0

Based on your code, I assume that you are trying to attach all the objects in contact using weld joints. Because these objects are in contact, they may have overlapping or collision happening when you are welding them together. However you set collideConnected = true. Which means if they are colliding right now, they will keep colliding and they cannot be apart because of the weld joint. This should yield a lot of not so meaningful computation and thus drag your fps down.