Ejemplo n.º 1
0
bool SteerLib::GJK_EPA::Triangulate(const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB)
{
	std::vector<struct triangle> trianglesA, trianglesB;
	// Pairs edges from original polygon together and also gets the triangulated points
	GetEdges(trianglesA, _shapeA);
	GetEdges(trianglesB, _shapeB);
		
	std::vector<Util::Vector> _simplex;
	for (int i = 0; i < trianglesA.size(); i++) {
		// Get points of a triangle from shapeA
		std::vector<Util::Vector> a;
		a.push_back(trianglesA[i].p1);
		a.push_back(trianglesA[i].p2);
		a.push_back(trianglesA[i].p3);

		for (int j = 0; j < trianglesB.size(); j++) {
			_simplex.clear();

			// Get points of a triangle from shapeB
			std::vector<Util::Vector> b;
			b.push_back(trianglesB[j].p1);
			b.push_back(trianglesB[j].p2);
			b.push_back(trianglesB[j].p3);
			
			// Perform GJK on every pair of trianlges from the two polygons
			if (GJK(a, b, _simplex))
				return true;
		}
	}

	return false;
}
Ejemplo n.º 2
0
//Look at the GJK_EPA.h header file for documentation and instructions
bool SteerLib::GJK_EPA::intersect(float& return_penetration_depth, Util::Vector& return_penetration_vector, const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB)
{
	std::vector<Util::Vector> masterSimplex;
	// run decomposition
	/*
	std::vector<std::vector<Util::Vector>> triangleListA = decompose(_shapeA);
	std::vector<std::vector<Util::Vector>> triangleListB = decompose(_shapeB);
	*/
	bool collision = false;
	/*
	// check GJK for every triangle in B with every triangle in A
	for (int i = 0; i < triangleListA.size(); i++) {
		for (int j = 0; j < triangleListB.size(); j++) {
			if (GJK(masterSimplex, triangleListA.at(i), triangleListB.at(j))) {
				collision = true;
			}
		}
	}
	*/
	collision = GJK(masterSimplex, _shapeA, _shapeB);
	
	// return result of EPA over total decomposed convex sets
	if (collision) {
		return_penetration_depth = EPA(masterSimplex, return_penetration_vector, _shapeA, _shapeB);
	}
	else {
		return_penetration_depth = 0.0;
	}
	// return result of GJK over decomposed convex sets
	return collision;
}
Ejemplo n.º 3
0
//Look at the GJK_EPA.h header file for documentation and instructions
bool SteerLib::GJK_EPA::intersect(float& return_penetration_depth, Util::Vector& return_penetration_vector, const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB)
{

/*
intersect(Polygon A, Polygon B)
             *  {
             *      (Simplex, is_colliding) = GJK(A, B)
             *      if ( is_colliding == true)
             *      {
             *          (penetration_depth, penetration_vector) = EPA(A, B, Simplex)
             *          return (true, penetration_depth, penetration_vector)
             *      }
             *      else
             *      {
             *          return (false, 0, NULL)    
             *      }    
             *  }
*/
	std::vector<Util::Vector> simplex;
	bool is_colliding = GJK(_shapeA, _shapeB, simplex);
	     if (is_colliding == true)
	{
		return true;
	
	}
	else
	{
		return false;
	}

}
Ejemplo n.º 4
0
//Look at the GJK_EPA.h header file for documentation and instructions
bool SteerLib::GJK_EPA::intersect(float& return_penetration_depth, Util::Vector& return_penetration_vector, const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB)
{
	std::vector<Util::Vector> simplex;
	bool col =  GJK(_shapeA, _shapeB, simplex);
	if(col==false)
		return false;
	//EPA(_shapeA, _shapeB, simplex, return_penetration_depth, return_penetration_vector);
	return true;
}
Ejemplo n.º 5
0
//Look at the GJK_EPA.h header file for documentation and instructions
bool SteerLib::GJK_EPA::intersect(float& return_penetration_depth, Util::Vector& return_penetration_vector, const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB)
{
    std::vector<Util::Vector> simplex;
    
    bool isColliding = GJK(_shapeA, _shapeB, simplex);
    
    if (isColliding) {
        epa(_shapeA, _shapeB, simplex, return_penetration_depth, return_penetration_vector);
    }
    
    return isColliding;
}
Ejemplo n.º 6
0
bool SteerLib::GJK_EPA::intersect(float& return_penetration_depth, Util::Vector& return_penetration_vector, const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB)
{
	std::vector<Util::Vector> _simplex;
	if (GJK(_shapeA, _shapeB, _simplex))
	{
		SteerLib::GJK_EPA::EPA(return_penetration_depth, return_penetration_vector, _shapeA, _shapeB, _simplex);
		return true;
	}
	else
	{
		return false;
	}
}
Ejemplo n.º 7
0
//Look at the GJK_EPA.h header file for documentation and instructions
bool SteerLib::GJK_EPA::intersect(float& return_penetration_depth, Util::Vector& return_penetration_vector, const std::vector<Util::Vector>& _shapeA, const std::vector<Util::Vector>& _shapeB)
{
	std::vector<Util::Vector> _simplex;
	bool colliding;

	colliding = GJK(_simplex, _shapeA, _shapeB);
	if (colliding)
	{
		EPA(return_penetration_depth, return_penetration_vector, _simplex, _shapeA, _shapeB);
		return true;
	}
	else
	{
		return_penetration_depth = 0;
		return_penetration_vector.zero();
		return false;
	}
}
Ejemplo n.º 8
0
static bool TestEPA(const MyConvex& hull0, const MyConvex& hull1)
{
	static btSimplexSolverInterface simplexSolver;
#ifdef COMPARE_WITH_SOLID35_AND_OTHER_EPA
//	static Solid3JohnsonSimplexSolver simplexSolver2;
#endif //COMPARE_WITH_SOLID35_AND_OTHER_EPA

	simplexSolver.reset();

	btConvexHullShape convexA((btScalar*)hull0.mVerts, hull0.mNbVerts, sizeof(btVector3));
	btConvexHullShape convexB((btScalar*)hull1.mVerts, hull1.mNbVerts, sizeof(btVector3));

	static btGjkEpaPenetrationDepthSolver Solver0;
	static btMinkowskiPenetrationDepthSolver Solver1;

#ifdef COMPARE_WITH_SOLID35_AND_OTHER_EPA
	static Solid3EpaPenetrationDepth Solver2;
	static EpaPenetrationDepthSolver Solver3;
#endif
	

	btConvexPenetrationDepthSolver* Solver = NULL ;
			if(gMethod==0)	
				Solver = &Solver0;
	else	if(gMethod==1)	
				Solver = &Solver1;
#ifdef COMPARE_WITH_SOLID35_AND_OTHER_EPA
	else	if(gMethod==2)	
				Solver = &Solver2;
	else					
				Solver = &Solver3;
#endif //COMPARE_WITH_SOLID35_AND_OTHER_EPA


#ifdef USE_ORIGINAL

	btGjkPairDetector GJK(&convexA, &convexB, &simplexSolver, Solver);
	GJK.m_catchDegeneracies = 1;
	convexA.setMargin(0.01f);
	convexB.setMargin(0.01f);

	btDiscreteCollisionDetectorInterface::ClosestPointInput input;
	input.m_transformA = hull0.mTransform;
	input.m_transformB = hull1.mTransform;
	input.m_stackAlloc = &gStackAlloc;

	MyResult output;
	GJK.getClosestPoints(input, output, 0);
	gLastUsedMethod = GJK.m_lastUsedMethod;
	gNumGjkIterations = GJK.m_curIter;
	gLastDegenerateSimplex= GJK.m_degenerateSimplex;
#else
	MyResult output;
	btVector3	witnesses[2];
	btVector3	normal;
	btScalar	depth;

	btGjkEpaSolver::sResults results;
	btScalar radialMargin = 0.01f;

	btGjkEpaSolver::Collide(&convexA,hull0.mTransform,
		&convexB,hull1.mTransform,
		radialMargin,
		results);
	if (results.depth>0)
	{
		output.addContactPoint(results.normal,results.witnesses[1],-results.depth);
	}
#endif
	return true;
}