나는 게임에서 연체 물리학을 사용하여 공을 만들었습니다. 이제 공이 b2Bodies이거나 GrounBody 인 플랫폼에서 완전히 부서져 & 모양이 변경되었습니다.어떻게 softbody 공이 box2d에서 파괴되는 것을 막으시겠습니까?
나는이 링크를 언급 한: http://www.uchidacoonga.com/2012/04/soft-body-physics-with-box2d-and-cocos2d-part-44/
하지만 난 반경, frequencyHz 같은 값의 일부를 변경하려고 할 때, dampingRatio 등 다음 내 첫 번째 이미지에 따라 결과를 제공가있는 내 볼이 때문에 형태가 이루어지지 않은 모양 & 파괴되었다. 이 이러한 상황을 피하기 위해 임의의 솔루션을 here.Is 같이
- (void) createPhysicsObject:(b2World *)world {
// Center is the position of the circle that is in the center (inner circle)
b2Vec2 center = b2Vec2(240/PTM_RATIO, 160/PTM_RATIO);
b2CircleShape circleShape;
circleShape.m_radius = 0.20f;
b2FixtureDef fixtureDef;
fixtureDef.shape = &circleShape;
fixtureDef.density = 0.1;
fixtureDef.restitution = -2;
fixtureDef.friction = 1.0;
// Delta angle to step by
deltaAngle = (2.f * M_PI)/NUM_SEGMENTS;
// Radius of the wheel
float radius = 50;
// Need to store the bodies so that we can refer back
// to it when we connect the joints
bodies = [[NSMutableArray alloc] init];
for (int i = 0; i < NUM_SEGMENTS; i++) {
// Current angle
float theta = deltaAngle*i;
// Calculate x and y based on theta
float x = radius*cosf(theta);
float y = radius*sinf(theta);
// Remember to divide by PTM_RATIO to convert to Box2d coordinate
b2Vec2 circlePosition = b2Vec2(x/PTM_RATIO, y/PTM_RATIO);
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
// Position should be relative to the center
bodyDef.position = (center + circlePosition);
// Create the body and fixture
b2Body *body;
body = world->CreateBody(&bodyDef);
body->CreateFixture(&fixtureDef);
// Add the body to the array to connect joints to it
// later. b2Body is a C++ object, so must wrap it
// in NSValue when inserting into it NSMutableArray
[bodies addObject:[NSValue valueWithPointer:body]];
}
// Circle at the center (inner circle)
b2BodyDef innerCircleBodyDef;
// Make the inner circle larger
circleShape.m_radius = 0.8f;
innerCircleBodyDef.type = b2_dynamicBody;
// Position is at the center
innerCircleBodyDef.position = center;
innerCircleBody = world->CreateBody(&innerCircleBodyDef);
innerCircleBody->CreateFixture(&fixtureDef);
// Connect the joints
b2DistanceJointDef jointDef;
for (int i = 0; i < NUM_SEGMENTS; i++) {
// The neighbor
const int neighborIndex = (i + 1) % NUM_SEGMENTS;
// Get current body and neighbor
b2Body *currentBody = (b2Body*)[[bodies objectAtIndex:i] pointerValue];
b2Body *neighborBody = (b2Body*)[[bodies objectAtIndex:neighborIndex] pointerValue];
// Connect the outer circles to each other
jointDef.Initialize(currentBody, neighborBody,
currentBody->GetWorldCenter(),
neighborBody->GetWorldCenter());
// Specifies whether the two connected bodies should collide with each other
jointDef.collideConnected = true;
jointDef.frequencyHz = 25.0f;
jointDef.dampingRatio = 0.5f;
world->CreateJoint(&jointDef);
// Connect the center circle with other circles
jointDef.Initialize(currentBody, innerCircleBody, currentBody->GetWorldCenter(), center);
jointDef.collideConnected = true;
jointDef.frequencyHz = 25.0;
jointDef.dampingRatio = 0.5;
world->CreateJoint(&jointDef);
}
}
이 코드
나에게 결과를 제공 ???나는이 같은 출력이 내가 만든해야 어떤 변화 줄까? 어떤 제안 !! 도와주세요. 나는 또한 이것의 뒤에 이유를 알고 싶다.
내가 같이 힘을 적용한 mynode.m 파일의 저를 반송 방법 13 –
#DEFINE NUM_SEGMENTS 있습니다 - (무효) 바운스 (CGPoint) 위치 { b2Vec2 임펄스; if (location.x> innerCircleBody-> GetPosition(). x * PTM_RATIO) { impulse = b2Vec2 (10,0); } else { impulse = b2Vec2 (-10,0); } b2Vec2 impulsePoint = innerCircleBody-> GetPosition(); innerCircleBody-> ApplyLinearImpulse (impulse, impulsePoint); } –