courses/columbia-cg-animation/week05/FOSSSim/HybridCollisionHandler.cpp
bool HybridCollisionHandler::applyIterativeImpulses(const TwoDScene &scene, const VectorXs &qs, const VectorXs &qe, const VectorXs &qdote, double dt, VectorXs &qefinal, VectorXs &qdotefinal)
{	
    qefinal = qe;
	qdotefinal = qdote;
	for (int i = 0; i < m_maxiters; i++)
	{
		auto collisions = detectCollisions(scene, qs, qefinal);
		if (collisions.size() == 0)
			return true;
		else 
		{
			VectorXs newqe = qefinal;
			VectorXs newqdote = qdotefinal;
			applyImpulses(scene, collisions, qs, newqe, newqdote, dt, qefinal, qdotefinal);
		}
	}
    return false;
}
// Iteratively performs collision detection and interative impulse response until either there are no more detected collisions, or the maximum number of
// iterations has been reached. See the assignment instructions for more details.
// The maximum number of iterations is stored in the member variable m_maxiters.
// Inputs:
//   scene:   The simulation scene. Get masses, radii, edge endpoint indices, etc. from here. Do *NOT* get any positions or velocities from here.
//   qs:      The positions of the particles at the start of the time step.
//   qe:      The predicted end-of-time-step positions.
//   qdote:   The predicted end-of-time-step velocities.
//   dt:      The time step size.
// Outputs:
//   qefinal:    The collision-free end-of-time-step positions (if no new collisions are detected), or the last set of predicted end-of-time-step positions
//               (if maximum number of iterations reached).
//   qdotefinal: Same as qefinal, but for velocities.
//   Returns true if the algorithm found a collision-free state. Returns false if the maximum number of iterations was reached without finding a collision-
//   free state.
// Possibly useful functions: detectCollisions, applyImpulses.
Iteratively performs collision detection and interative impulse response until either there are no more detected collisions, or the maximum number of
iterations has been reached. See the assignment instructions for more details.
The maximum number of iterations is stored in the member variable m_maxiters.
Inputs:
scene:   The simulation scene. Get masses, radii, edge endpoint indices, etc. from here. Do *NOT* get any positions or velocities from here.
qs:      The positions of the particles at the start of the time step.
qe:      The predicted end-of-time-step positions.
qdote:   The predicted end-of-time-step velocities.
dt:      The time step size.
Iteratively performs collision detection and interative impulse response until either there are no more detected collisions or the maximum number of iterations has been reached . See the assignment instructions for more details . The maximum number of iterations is stored in the member variable m_maxiters . Inputs : scene : The simulation scene . Get masses radii edge endpoint indices etc . from here . Do * NOT * get any positions or velocities from here . qs : The positions of the particles at the start of the time step . qe : The predicted end - of - time - step positions . qdote : The predicted end - of - time - step velocities . dt : The time step size .
bool HybridCollisionHandler::applyIterativeImpulses(const TwoDScene &scene, const VectorXs &qs, const VectorXs &qe, const VectorXs &qdote, double dt, VectorXs &qefinal, VectorXs &qdotefinal)
{	
    qefinal = qe;
	qdotefinal = qdote;
	for (int i = 0; i < m_maxiters; i++)
	{
		auto collisions = detectCollisions(scene, qs, qefinal);
		if (collisions.size() == 0)
			return true;
		else 
		{
			VectorXs newqe = qefinal;
			VectorXs newqdote = qdotefinal;
			applyImpulses(scene, collisions, qs, newqe, newqdote, dt, qefinal, qdotefinal);
		}
	}
    return false;
}
bool HybridCollisionHandler :: applyIterativeImpulses ( const TwoDScene & scene , const VectorXs & qs , const VectorXs & qe , const VectorXs & qdote , double dt , VectorXs & qefinal , VectorXs & qdotefinal ) { qefinal = qe ; qdotefinal = qdote ; for ( int i = 0 ; i < m_maxiters ; i ++ ) { auto collisions = detectCollisions ( scene , qs , qefinal ) ; if ( collisions . size ( ) == 0 ) return true ; else { VectorXs newqe = qefinal ; VectorXs newqdote = qdotefinal ; applyImpulses ( scene , collisions , qs , newqe , newqdote , dt , qefinal , qdotefinal ) ; } } return false ; }
Iteratively performs collision detection and interative impulse response until either there are no more detected collisions, or the maximum number of
iterations has been reached.
Iteratively performs collision detection and interative impulse response until either there are no more detected collisions or the maximum number of iterations has been reached .