2012-06-01 4 views
1

나는 다음과 같은 방법의 도움으로 만든 Box2D 샘플 앱에 약 10 개의 시체가 있습니다. 하지만 내 Update 메서드에서 나는 몸의 b2FixtureDef를 얻고 싶습니다. 왜냐하면 나는 각 body마다 다른 filter.groupIndex가 필요하기 때문입니다. 나는 모든 b2Body를 통해 반복되지만 다음과 같이 Update 메소드를 사용하지만 실제로 b2Body에서 b2FixtureDef를 가져 오는 방법을 찾지 못합니까?b2body Box2d의 b2Fixture 받기?

-(void) addNewSprite:(NSString *)spriteName AtPosition:(CGPoint)p isDynamic:(BOOL)dynamic 
{ 
    //CCNode *parent = [self getChildByTag:kTagParentNode]; 

PhysicsSprite *sprite = [PhysicsSprite spriteWithFile:spriteName]; 

[self addChild:sprite]; 

sprite.position = ccp(p.x, p.y); 

sprite.tag = check; 

// Define the dynamic body. 
//Set up a 1m squared box in the physics world 
b2BodyDef bodyDef; 
bodyDef.type = b2_dynamicBody; 
bodyDef.position.Set(sprite.position.x/PTM_RATIO, sprite.position.y/PTM_RATIO); 
bodyDef.userData = sprite; 
b2Body *body = world->CreateBody(&bodyDef); 

// Define another box shape for our dynamic body. 
b2PolygonShape dynamicBox; 
dynamicBox.SetAsBox((sprite.contentSize.width/PTM_RATIO/2)*(sprite.scaleX), 
        (sprite.contentSize.height/PTM_RATIO/2)*(sprite.scaleY));//These are mid points for our 1m box 

// Define the dynamic body fixture. 
b2FixtureDef fixtureDef; 
fixtureDef.shape = &dynamicBox; 
fixtureDef.density = 1.0f; 
fixtureDef.friction = 1.0f; 
fixtureDef.userData = sprite; 

switch (check) 
{ 
    case 1: 
     fixtureDef.filter.categoryBits = 0x0002; 

     fixtureDef.filter.maskBits = 0x0004; 
     break; 
    case 2: 
     fixtureDef.filter.categoryBits = 0x0004; 

     fixtureDef.filter.maskBits = 0x0002; 
     break; 
} 

body->CreateFixture(&fixtureDef); 

[sprite setPhysicsBody:body]; 

check++; 
} 

-(void) update: (ccTime) dt 
{ 
    //It is recommended that a fixed time step is used with Box2D for stability 
    //of the simulation, however, we are using a variable time step here. 
    //You need to make an informed choice, the following URL is useful 
    //http://gafferongames.com/game-physics/fix-your-timestep/ 

int32 velocityIterations = 8; 
int32 positionIterations = 1; 

// Instruct the world to perform a single step of simulation. It is 
// generally best to keep the time step and iterations fixed. 
world->Step(dt, velocityIterations, positionIterations);  

for(b2Body *b = world->GetBodyList(); b; b=b->GetNext()) {  

    if (b->GetUserData() != NULL) 
    { 

     //b2Fixture fixtureDef = *b->GetFixtureList(); 
     //b2Filter filter = fixtureDef.GetFilterData(); 

     // how to get b2FixtureDef from b 

    } 
} 

답변

3

실제로, 나는 당신이 당신의 업데이트 방법에서 왜이 정보를 얻을 필요가 있는지 상상할 수 없다. 조명기 생성에만 사용되므로 fixtureDef를 얻을 수 없습니다. 그러나 GetFilterData() 메소드를 사용하여 각 바디 픽스처에 대한 필터 데이터를 얻을 수 있습니다. 범주 비트, 마스크 비트 및 그룹 인덱스가 포함됩니다.

관련 문제