두 가지 질문이 있습니다. 먼저 Clone
전에 b2BlockAllocator
을 만든 다음 복제 후 (?)를 삭제해야합니까? 엑스 코드 프로파일 링 악기는 법선을 계산하는 설정하고 몸에 반대 할당 정점을 수정, 그것을 복제, 내가 캐시 모양 객체를 가지고이 코드에서Box2D 할당기를 사용하는 방법?
b2FixtureDef fixd = fix->fixture;
const b2Shape *shape = fixd.shape;
if(shape->GetType()== b2Shape::e_polygon && flip)
{
b2PolygonShape* ps = (b2PolygonShape*)shape->Clone(new b2BlockAllocator());
for(int i=0;i<ps->m_vertexCount;i++)
{
ps->m_vertices[i].x *= -1;
ps->m_vertices[i].y *= -1;
}
ps->Set(&ps->m_vertices[0], ps->m_vertexCount);
body->CreateFixture(ps, 1.0f);
...
... C++ 누수를 표시하지 않습니다. 질문 -이게 합법적입니까?
업데이트 : 나는 b2Shape::Clone
방법을 사용하지 않기 때문에
-(void) addFixturesToBody:(b2Body*)body forShapeName:(NSString*)shapeName flip:(BOOL)flip
{
BodyDef *so = [shapeObjects_ objectForKey:shapeName];
assert(so);
FixtureDef *fix = so->fixtures;
while(fix)
{
b2FixtureDef fixd = fix->fixture;
const b2Shape *shape = fixd.shape;
if(shape->GetType()== b2Shape::e_polygon && flip)
{
b2BlockAllocator allocator;
b2PolygonShape* ps = (b2PolygonShape*)shape->Clone(&allocator);
for(int i=0;i<ps->m_vertexCount;i++)
{
ps->m_vertices[i].x *= -1;
ps->m_vertices[i].y *= -1;
}
ps->Set(&ps->m_vertices[0], ps->m_vertexCount);
body->CreateFixture(ps, 1.0f);
}
else
{
NSLog(@"noflip...%@", shapeName);
body->CreateFixture(&fix->fixture);
}
fix = fix->next;
}
}
당신이하려는 일에 대해 설명해 주시겠습니까? Box2D의 전형적인 사용을 위해서 allocator와 clone 함수를 다룰 필요는 없다. – iforce2d
@ iforce2d : 물론. 나는 셰이프와 함수를 캐싱하여 몸체, 모양 ID를주고, 발견 된 모양을 기반으로 그 몸체를위한 조명기를 만듭니다. 이제는 함수도 flip 속성을 가지고 있으므로 TRUE 일 때마다 뒤집힌 fixture를 만들어야합니다. 따라서 조명기를 만들기 전에 캐시에서 일반적인 모양을 가져 와서 뒤집은 다음 조명기를 만듭니다. 플립 할 필요가 없으면 캐시 된 모양에서 조명기를 만듭니다. 뒤집기 부분은 위에 나와 있습니다. – Pablo
아직 명확하지 않은 경우 전체 기능을 게시합니다. – Pablo