2011-03-23 83 views
0

我無法弄清楚如何使接點斷裂。基本上,一個旋轉關節被添加到b2PolygonShape的兩個b2Body中。但是當一輛汽車在它上面移動時,接頭不會中斷。而是汽車穿過多邊形的形狀。box2d b2RevoluteJoint not breaking

試過下面沒有運氣到目前爲止

  b2BodyDef bodyDef; 
    bodyDef.position.Set(xPos/PTM_RATIO, yPos/PTM_RATIO); 
    bodyDef.angle = atan(dy/dx); 

    bodyDef.userData = sp; 
    bodyDef.type = b2_dynamicBody; 

    b2Body* body = world->CreateBody(&bodyDef); 

    b2PolygonShape shape; 
    b2Vec2 rectangle1_vertices[4]; 
    rectangle1_vertices[0].Set(-len/2, -width/2); 
    rectangle1_vertices[1].Set(len/2, -width/2); 
    rectangle1_vertices[2].Set(len/2, width/2); 
    rectangle1_vertices[3].Set(-len/2, width/2); 
    shape.Set(rectangle1_vertices, 4); 

    b2FixtureDef fd; 
    fd.shape = &shape; 
    fd.density = 10.0f; 
    body->CreateFixture(&fd); 

    edge.body = body; 

// The code below is not breaking the joint even though enableLimit = true. 
       b2RevoluteJointDef jointDef; 
      b2Vec2 anchor = vertex.body->GetPosition(); 
      jointDef.lowerAngle = -10.0 * b2_pi/180.0f; 
      jointDef.upperAngle = 10.0 * b2_pi/180.0f; 
      jointDef.enableLimit = true; 
      jointDef.maxMotorTorque = 1000.0f; 
      jointDef.enableMotor = true; 

      //prevEdge and edge are b2Body with b2PolygonShape. 
      jointDef.Initialize(prevEdge.body, edge.body, anchor); 
      world->CreateJoint(&jointDef); 

感謝您對Box2D的幫助

回答

0

接頭不易碎。如果您的設置爲enableLimit = true,則表示box2D將使用您的lowerAngleapperAngle限制。在box2d測試平臺中有一個易碎的例子。看一看。

0

如果您對關節施加了如此大的力,以至於關節固定器位置分開,您可以檢測到他們何時移動得太遠而只是刪除關節。