void Number::UpdateCollision() { GameEngine::getInstance()->AddToCollisionQuadtree(&mySprite); Colliding( GameEngine::getInstance()->DetectCollision(&mySprite,"Minus.PNG") , GameEngine::getInstance()->DetectCollision(&mySprite,"Plus.PNG" ) ); myWeapon->UpdateCollision(); }
void Enemy::UpdateCollision() { if( myAI != DEAD ) { GameEngine::getInstance()->AddToCollisionQuadtree(&mySprite); if( isX ) Colliding( GameEngine::getInstance()->DetectCollision(&mySprite,"Derivative.PNG") , GameEngine::getInstance()->DetectCollision(&mySprite,"Integral.PNG" ) ); else Colliding( GameEngine::getInstance()->DetectCollision(&mySprite,"Minus.PNG") , GameEngine::getInstance()->DetectCollision(&mySprite,"Plus.PNG" ) ); TypeSwichColliding(); } myWeapon->UpdateCollision(); }
//------------------------------------------------------------------------------- // @ SimObject::HandleCollision() //------------------------------------------------------------------------------- // Handle collisions between this object and another one //------------------------------------------------------------------------------- void SimObject::HandleCollision( SimObject* other ) { IvVector3 collisionNormal, collisionPoint; float penetration; // if the two objects are colliding if (Colliding(other, collisionNormal, collisionPoint, penetration)) { // push out by penetration, scaled by relative masses float relativeMass = mMass/(mMass + other->mMass); mTranslate -= (1.0f-relativeMass)*penetration*collisionNormal; other->mTranslate += relativeMass*penetration*collisionNormal; // compute relative velocity IvVector3 r1 = collisionPoint - mTranslate; IvVector3 r2 = collisionPoint - other->mTranslate; IvVector3 vel1 = mVelocity + Cross( mAngularVelocity, r1 ); IvVector3 vel2 = other->mVelocity + Cross( other->mAngularVelocity, r2 ); IvVector3 relativeVelocity = vel1 - vel2; // determine if we're heading away from each other float vDotN = relativeVelocity.Dot( collisionNormal ); if (vDotN < 0) return; // compute impulse factor float denominator = (1.0f/mMass + 1.0f/other->mMass)*(collisionNormal.Dot(collisionNormal)); // compute angular factors IvVector3 cross1 = Cross(r1, collisionNormal); IvVector3 cross2 = Cross(r2, collisionNormal); cross1 = mWorldMomentsInverse*cross1; cross2 = other->mWorldMomentsInverse*cross2; IvVector3 sum = Cross(cross1, r1) + Cross(cross2, r2); denominator += (sum.Dot(collisionNormal)); // compute j float modifiedVel = vDotN/denominator; float j1 = -(1.0f+mElasticity)*modifiedVel; float j2 = (1.0f+mElasticity)*modifiedVel; // update velocities mVelocity += j1/mMass*collisionNormal; other->mVelocity += j2/other->mMass*collisionNormal; // update angular velocities mAngularMomentum += Cross(r1, j1*collisionNormal); mAngularVelocity = mWorldMomentsInverse*mAngularMomentum; other->mAngularMomentum += Cross(r2, j2*collisionNormal); other->mAngularVelocity = other->mWorldMomentsInverse*other->mAngularMomentum; } } // End of SimObject::HandleCollision()