0
我想將質量中心設置爲類似物體的矛。下面是相關代碼:Box2D質量中心
// Create spear body and shape
b2BodyDef spearBodyDef;
spearBodyDef.type = b2_dynamicBody;
spearBodyDef.position.Set(100.0/PTM_RATIO, 100.0/PTM_RATIO);
//spearBodyDef.angle = 45.0 * (180.0f/b2_pi);
spearBodyDef.userData = _spear;
_spearBody = _world->CreateBody(&spearBodyDef);
b2PolygonShape spearShape;
spearShape.Set(verts, num);
b2FixtureDef spearShapeDef;
spearShapeDef.shape = &spearShape;
spearShapeDef.density = 100.0f;
spearShapeDef.friction = 0.9f;
spearShapeDef.restitution = 0.1f;
_spearBody->CreateFixture(&spearShapeDef);
b2MassData massD;
_spearBody->GetMassData(&massD);
b2Vec2 centerV;
centerV.x = 25.0;
centerV.y = -1.0f;
massD.center = centerV;
_spearBody->SetMassData(&massD);
這崩潰,因爲斷言失敗的應用程序:
Jul 5 02:52:23 unknown UIKitApplication:com.youcompany.box[0xb15c][10311] <Notice>: Assertion failed: (m_I > 0.0f),
Jul 5 02:52:23 unknown UIKitApplication:com.youcompany.box[0xb15c][10311] <Notice>: function SetMassData, file /User
Jul 5 02:52:23 unknown UIKitApplication:com.youcompany.box[0xb15c][10311] <Notice>: s/~/Desktop/box/box/libs/Box
Jul 5 02:52:23 unknown UIKitApplication:com.youcompany.box[0xb15c][10311] <Notice>: 2D/Dynamics/b2Body.cpp, line 357
Jul 5 02:52:23 unknown UIKitApplication:com.youcompany.box[0xb15c][10311] <Notice>: .
我在做什麼錯?謝謝
由於某些原因,慣性矩小於零 – Andrew