我正在尝试为我的box2d车身实现焊接接头:
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);
//}
}
但我的fps很低。我认为这是因为我不检查身体是否是要焊接的。怎样才能检查车身是焊接的呢?谢谢。
发布于 2013-02-16 14:23:31
根据您的代码,我假设您正在尝试使用焊缝连接所有接触的对象。因为这些物体是有接触的,所以当你把它们焊接在一起时,它们可能会发生重叠或碰撞。但是,将collideConnected = true设置为true。这意味着,如果他们现在正在碰撞,他们将继续碰撞,他们不能分开,因为焊接接头。这应该会产生很多不那么有意义的计算,从而拖低fp。
https://stackoverflow.com/questions/11798352
复制相似问题