ODEDomain::~ODEDomain() { dJointGroupEmpty (contactgroup); dJointGroupDestroy (contactgroup); //deleting Heightfields starting from the end for (int i=heightfields.size()-1; i>=0; i--) DeleteHeightfield(i); heightfields.clear(); //deleting trimeshes starting from the end for (int i=trimeshes.size()-1; i>=0; i--) DeleteTriMesh(i); trimeshes.clear(); //deleting bodies starting from the end for (int i=bodies.size()-1; i>=0; i--) DeleteBody(i); bodies.clear(); //deleting Kinematic_bodies starting from the end for (int i=kinematic_bodies.size()-1; i>=0; i--) DeleteKinematicBody(i); kinematic_bodies.clear(); dSpaceDestroy (space); dWorldDestroy (world); dCloseODE(); printf("ODEDomain destructor\n"); }
//cleaning existing bodies before uploading saved data from prev .simulation void ODEDomain::RemoveExistingBodies() { printf("Cleaning existing bodies\n"); //deleting bodies starting from the end printf(" -Before %lu\n",bodies.size()); for (int i=bodies.size()-1; i>=0; i--) DeleteBody(i); bodies.clear(); printf(" -After %lu\n",bodies.size()); }
RigidBodyData::~RigidBodyData() { DeleteBody(); }
void ContactListener::BeginContact(b2Contact* contact) { b2Fixture* FixtuerA = contact->GetFixtureA(); b2Fixture* FixtuerB = contact->GetFixtureB(); b2Vec2 gravity = b2Vec2(0.0f, 0.0f); //_worldの重力を設定 b2World* testworld = new b2World(gravity); //FixtureのNullチェック CCAssert(FixtuerA != NULL,"FixtureA is NULL"); CCAssert(FixtuerB != NULL,"FixtureB is NULL"); //接触したオブジェクトのbodyを取得 b2Body* BodyA = FixtuerA->GetBody(); b2Body* BodyB = FixtuerB->GetBody(); //BodyのNullチェック CCAssert(BodyA != NULL,"BodyAがNULL"); CCAssert(BodyB != NULL,"BodyBがNULL"); //Bodyのタイプを取得 int BodyTypeA = BodyA->GetType(); int BodyTypeB = BodyB->GetType(); //接触した物体が両方とも動的なものの場合に実行 if((BodyTypeA == b2_dynamicBody)&&(BodyTypeB == b2_dynamicBody)) { //接触したオブジェクトのuserdataを取得 CCSprite* SpriteA = (CCSprite*)BodyA->GetUserData(); CCSprite* SpriteB = (CCSprite*)BodyB->GetUserData(); //AとBのオブジェクトのタグを取得 int TagA = SpriteA->getTag(); int TagB = SpriteB->getTag(); //タグがEnemyの場合削除 if(TagA == TAG_ENEMY) { //InvisibleSprite(SpriteA); //SpritAを非表示 HeWorld->AddScore(10); //scoreに10加算 DeleteBody(BodyA, thisWorld); } if(TagB == TAG_ENEMY) { InvisibleSprite(SpriteB); //SpritAを非表示 HeWorld->AddScore(10); //scoreに10加算 DeleteBody(BodyB, thisWorld); } //タグがBombの場合削除 if(TagA == TAG_BOMB) { InvisibleSprite(SpriteA); DeleteBody(BodyA, thisWorld); } if(TagB == TAG_BOMB) { InvisibleSprite(SpriteB); DeleteBody(BodyB, thisWorld); } } //片方が静的(画面端など)オブジェクトだった場合 else if(BodyTypeA == b2_dynamicBody) { //接触したオブジェクトのuserdataを取得 CCSprite* SpriteA = (CCSprite*)BodyA->GetUserData(); //AとBのオブジェクトのタグを取得 int TagA = SpriteA->getTag(); //タグがBombの場合削除 if((TagA == TAG_BOMB)||(TagA == TAG_ENEMY)) { InvisibleSprite(SpriteA); } } else if(BodyTypeB == b2_dynamicBody) { //接触したオブジェクトのuserdataを取得 CCSprite* SpriteB = (CCSprite*)BodyB->GetUserData(); //AとBのオブジェクトのタグを取得 int TagB = SpriteB->getTag(); //タグがBombの場合削除 if((TagB == TAG_BOMB)||(TagB == TAG_ENEMY)) { InvisibleSprite(SpriteB); } } }