void GB2ShapeCache::addFixturesToBody(b2Body *body, const std::string &shape,float scale) { /*if(scale == 1.0f) { addFixturesToBody(body,shape); return; }*/ std::map<std::string, BodyDef *>::iterator pos = shapeObjects.find(shape); assert(pos != shapeObjects.end()); BodyDef *so = (*pos).second; FixtureDef *fix = so->fixtures; while (fix) { const b2Shape* shape = fix->fixture.shape; b2FixtureDef fixtureDef; b2FixtureDef oldFixtureDef = fix->fixture; if(shape->GetType() == b2Shape::e_circle ) { b2CircleShape* oldCircle = (b2CircleShape*)fix->fixture.shape; b2CircleShape newCircle; newCircle.m_radius = oldCircle->m_radius * scale; newCircle.m_p = scale * oldCircle->m_p; fixtureDef.shape = &newCircle; fixtureDef.density = oldFixtureDef.density; fixtureDef.filter = oldFixtureDef.filter; fixtureDef.friction = oldFixtureDef.friction; fixtureDef.isSensor = oldFixtureDef.isSensor; fixtureDef.restitution = oldFixtureDef.restitution; fixtureDef.userData = oldFixtureDef.userData; body->CreateFixture(&fixtureDef); } if(shape->GetType() == b2Shape::e_polygon) { b2PolygonShape* polygon = (b2PolygonShape*)fix->fixture.shape; int count = polygon->GetVertexCount(); b2Vec2 *m_newVertices = new b2Vec2[count]; for(int i = 0;i<count;i++) { m_newVertices[i] = scale * polygon->GetVertex(i); } b2PolygonShape newPolygon; newPolygon.Set(m_newVertices, count); fixtureDef.shape = &newPolygon; fixtureDef.density = oldFixtureDef.density; fixtureDef.filter = oldFixtureDef.filter; fixtureDef.friction = oldFixtureDef.friction; fixtureDef.isSensor = oldFixtureDef.isSensor; fixtureDef.restitution = oldFixtureDef.restitution; fixtureDef.userData = oldFixtureDef.userData; body->CreateFixture(&fixtureDef); } fix = fix->next; } }