Group3_FinalProject/Collision.cpp
// Checks to see if the simplex is over the origin
Checks to see if the simplex is over the origin
Checks to see if the simplex is over the origin
bool Collision::simplexContainsOrigin( vector<vec2>* simplex, vec2* searchDir )
{
	vec2 a = simplex->back();
	vec2 ao = -a;
	if( simplex->size() == 3 )
	{
		vec2 b = simplex->at( 0 );
		vec2 c = simplex->at( 1 );
		vec2 ab = b - a;
		vec2 ac = c - a;
		vec2 temp = ac * ab;
		vec2 abPerp = tripleProduct( ac, ab, ab );
		vec2 acPerp = tripleProduct( ab, ac, ac );
		if( abPerp * ao > 0 )
		{
			simplex->erase( simplex->begin() + 1 );
			*searchDir = abPerp;
		}
		else
		{
			if( acPerp * ao > 0 )
			{
				simplex->erase( simplex->begin() + 0 );
				*searchDir = acPerp;
			}
			else
				return true;
		}
	}
	else
	{
		vec2 b = simplex->front();
		vec2 ab = b - a;
		vec2 abPerp = ( ab * ab * ao ) - ( ab * ao * ab );
		*searchDir = abPerp;
	}
	return false;
}
bool Collision :: simplexContainsOrigin ( vector < vec2 > * simplex , vec2 * searchDir ) { vec2 a = simplex -> back ( ) ; vec2 ao = - a ; if ( simplex -> size ( ) == 3 ) { vec2 b = simplex -> at ( 0 ) ; vec2 c = simplex -> at ( 1 ) ; vec2 ab = b - a ; vec2 ac = c - a ; vec2 temp = ac * ab ; vec2 abPerp = tripleProduct ( ac , ab , ab ) ; vec2 acPerp = tripleProduct ( ab , ac , ac ) ; if ( abPerp * ao > 0 ) { simplex -> erase ( simplex -> begin ( ) + 1 ) ; * searchDir = abPerp ; } else { if ( acPerp * ao > 0 ) { simplex -> erase ( simplex -> begin ( ) + 0 ) ; * searchDir = acPerp ; } else return true ; } } else { vec2 b = simplex -> front ( ) ; vec2 ab = b - a ; vec2 abPerp = ( ab * ab * ao ) - ( ab * ao * ab ) ; * searchDir = abPerp ; } return false ; }
Checks to see if the simplex is over the origin
Checks to see if the simplex is over the origin
// If the simplex is a triangle // vector b // vector c // Error stem // ac X ab X ab // ab X ac X ac // Check region 1 // Remove c // Check region 2 // Remove b // Simplex contains origin // Simplex needs another point before checking for the origin //ab X ao X ab