//----------------------------------------------------------------------------
void BouncingSpheres::DoCollisionResponse ()
{
    if (mNumContacts > 0)
    {
        float* preRelVelocities = new1<float>(mNumContacts);
        float* impulseMagnitudes = new1<float>(mNumContacts);

        ComputePreimpulseVelocity(preRelVelocities);
        ComputeImpulseMagnitude(preRelVelocities, impulseMagnitudes);

        for (int i = 0; i < mNumContacts; ++i)
        {
            Contact& contact = mBoundaryContacts[i];
            RigidBodyf& bodyA = *contact.A;
            RigidBodyf& bodyB = *contact.B;

            Vector3f impulse = impulseMagnitudes[i]*contact.N;
            bodyA.SetLinearMomentum(bodyA.GetLinearMomentum() + impulse);
            bodyB.SetLinearMomentum(bodyB.GetLinearMomentum() - impulse);
        }

        delete1(preRelVelocities);
        delete1(impulseMagnitudes);
    }

    for (int i = 0; i < NUM_BALLS; ++i)
    {
        mBalls[i]->Update(mSimTime, mSimDeltaTime);
    }
}
Beispiel #2
0
void World::DoCollisionResponse()
{
    if(!contacts_.empty()) //  m_iNumContacts > 0 )
    {
        vector<float> preRelVel;
        preRelVel.resize(contacts_.size());
        vector<float> impulseMag;
        impulseMag.resize(contacts_.size());

        ComputePreimpulseVelocity(preRelVel);
        ComputeImpulseMagnitude(preRelVel, impulseMag);
        DoImpulse(impulseMag);
    }
}
//----------------------------------------------------------------------------
void BouncingTetrahedra::DoCollisionResponse ()
{
    if (mNumContacts > 0)
    {
        float* preRelVelocities = new1<float>(mNumContacts);
        float* impulseMagnitudes = new1<float>(mNumContacts);

        ComputePreimpulseVelocity(preRelVelocities);
        ComputeImpulseMagnitude(preRelVelocities, impulseMagnitudes);
        DoImpulse(impulseMagnitudes);

        delete1(preRelVelocities);
        delete1(impulseMagnitudes);
    }

    for (int i = 0; i < NUM_TETRA; ++i)
    {
        mTetras[i]->Update(mSimTime, mSimDeltaTime);
    }
}