本文整理汇总了C++中b2World::DestroyBody方法的典型用法代码示例。如果您正苦于以下问题:C++ b2World::DestroyBody方法的具体用法?C++ b2World::DestroyBody怎么用?C++ b2World::DestroyBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类b2World
的用法示例。
在下文中一共展示了b2World::DestroyBody方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processRemoval
void processRemoval(b2Vec2 removalPosition, float removalRadius, b2World& world, bool simplifyGeometry)
{
auto foundBodies = queryDestructibleBodies(removalPosition, removalRadius, world);
auto batch = matchBodiesToRings(foundBodies.begin(), foundBodies.end());
// Partition the shapes by area, so that elements to be processed are at the beginning
auto borderIt = std::partition(batch.begin(), batch.end(), [](const match_t& m) {
const double areaEpsilon = 0.02;
return bg::area(m.second) > areaEpsilon;
});
// Remove small shapes
std::for_each(borderIt, batch.end(), [&](const match_t& m) {
world.DestroyBody(m.first);
});
// Subtract the input polygon from each shape returned from the query
ring_t diff = makeConvexRing(removalPosition, removalRadius, 16);
boost::geometry::correct(diff);
typedef std::pair<std::unique_ptr<b2ChainShape>, b2Filter> shape_property_t;
std::vector<shape_property_t> resultShapes;
std::for_each(batch.begin(), borderIt, [&](const match_t& m) {
auto subtractionResult = subtract(m.second, diff);
// Simplify the results
if (simplifyGeometry)
{
simplify(subtractionResult);
}
// Convert the rings to b2ChainShapes and add to result shapes
auto converted = convertGeometry(subtractionResult);
auto moveBegin = std::make_move_iterator(converted.begin());
auto moveEnd = std::make_move_iterator(converted.end());
std::transform(moveBegin, moveEnd, std::back_inserter(resultShapes),
[&](std::unique_ptr<b2ChainShape> converted) {
auto filter = m.first->GetFixtureList()->GetFilterData();
return std::make_pair(std::move(converted), filter);
});
if (!subtractionResult.empty())
{
world.DestroyBody(m.first);
}
});
for (auto&& s : resultShapes)
{
b2BodyDef bd;
b2Body* body = world.CreateBody(&bd);
auto fixture = body->CreateFixture(s.first.get(), 0.0f);
fixture->SetFilterData(s.second);
}
}
示例2: ReleaseNormalKeyInput
void ReleaseNormalKeyInput (unsigned char key, int x, int y)
{
printf (" input %d\n", key );
switch (key)
{
case 'w':
break;
case 'f':
break;
case 'a':
break;
case 'r':
for ( b2Body * b = myWorld.GetBodyList (); b; b = b->GetNext () )
{
myWorld.DestroyBody (b);
}
delete agent;
agent = new Agent (myWorld);
readFile ("map.txt");
break;
case '1':
break;
default:
break;
}
}
示例3: clear
void Player::clear(b2World& world)
{
if (m_defender != nullptr)
{
world.DestroyBody(m_defender->getBody());
delete m_defender;
m_defender = nullptr;
}
if (m_gatherer != nullptr)
{
world.DestroyBody(m_gatherer->getBody());
delete m_gatherer;
m_gatherer = nullptr;
}
m_dead = false;
m_won = false;
m_points = 0.f;
}
示例4: ResetPosition
void CBox::ResetPosition(b2World & world) {
//destroy stuff (memory management, otherwise they build up)
m_body->DestroyFixture(m_body->GetFixtureList());
world.DestroyBody(m_body);
n++;
//m_shape.SetOrigin(5,5);
m_bodyDef.position.Set(300.0f/PPM,-300.0f/PPM-n*5/PPM);
m_bodyDef.angularVelocity = 0;
//m_bodyDef.angle = 270;
m_bodyDef.linearVelocity.Set(0, 60);
//reset fixture and body
SetWorld(world);
//reset shape
update();
}
示例5: Shape
FixtureShape::FixtureShape(b2World & world, b2Vec2 initialPos, b2Vec2 size,
unsigned ySize, float PPM, sf::Color color)
: Shape(world, initialPos, ySize, PPM)
{
mShape = std::unique_ptr<sf::RectangleShape>(new sf::RectangleShape(sf::Vector2f(size.x,size.y)));
mShape->setFillColor(color);
mShape->setOrigin(size.x/2.f, size.y/2.f);
world.DestroyBody(mBody);
mBodyDef.type = b2_staticBody;
mBody = world.CreateBody(&mBodyDef);
mBodyShape = std::unique_ptr<b2PolygonShape>(new b2PolygonShape());
static_cast<b2PolygonShape*>(mBodyShape.get())->SetAsBox(size.x/(2*mPPM),
size.y/(2*mPPM));
setBodyFix(0.3f, 0.5f, 0.25f);
update();
}
示例6: Box
void Ex52FixedObjectsApp::update() {
if (addBoxes) {
boxes.push_back( Box( world, mousePosition.x, mousePosition.y, Rand::randFloat(5.0f, 20.0f), Rand::randFloat(5.0f, 20.0f) ) );
}
// World step:
float32 timeStep = 1.0f / 60.0f;
int32 velocityIterations = 8;
int32 positionIterations = 3;
world->Step( timeStep, velocityIterations, positionIterations );
for ( std::vector<Box>::iterator iter = boxes.begin(); iter != boxes.end(); ) {
iter->update( world );
if (iter->isDead()) {
world->DestroyBody( iter->getBody() );
boxes.erase( iter );
} else {
++iter;
}
}
}
示例7: mContext
MapLevel::MapLevel(Context& context, std::size_t level, sf::Image& levelData, b2World& world)
: mContext(context)
, mWorld(LevelWidth, std::vector<Tile>(LevelHeight))
, mBoxWorld(world)
, mTexture(context.getTexture(Textures::GameAtlas))
, mDestinationList()
, mSourceList()
, mEntities()
{
LOG_CALL("MapLevel::MapLevel");
// Reset Box2D world
LOG_DEBUG("Clearing Box2D world from entities: %d to remove.", mBoxWorld.GetBodyCount());
b2Body* body = world.GetBodyList();
while (nullptr != body) {
b2Body* nextBody = body->GetNext();
world.DestroyBody(body);
body = nextBody;
}
// Create Box2D world boundaries
b2utils::createGround(mBoxWorld, 20.f, 300.f, 40.f, 600.f);
b2utils::createGround(mBoxWorld, 780.f, 300.f, 40.f, 600.f);
b2utils::createGround(mBoxWorld, 400.f, 18.f, 800.f, 36.f);
b2utils::createGround(mBoxWorld, 400.f, 582.f, 800.f, 36.f);
loadLevel(level, levelData);
initSprites();
//mDebugPlayerSpawn.setFillColor(sf::Color::Yellow);
//LOG_DEBUG("Player spawn position: (%d, %d)", mPlayerSpawnPos.x, mPlayerSpawnPos.y);
//mDebugPlayerSpawn.setPosition(WorldOffsetX + TileWidth * mPlayerSpawnPos.x, WorldOffsetY + TileHeight * mPlayerSpawnPos.y);
//mDebugPlayerSpawn.setSize(sf::Vector2f(24.f, 24.f));
}
示例8:
void Ex52FixedObjectsApp::shutdown() {
for (auto& b : boxes) {
world->DestroyBody( b.getBody() );
}
delete world;
}
示例9:
void Ex51aBox2DCustomApp::shutdown() {
for ( auto& b : boxes ) {
world->DestroyBody( b.getBody() );
}
delete world;
}