2010-09-09 19:41:14 +00:00
/********************************************************************************
* ReactPhysics3D physics library , http : //code.google.com/p/reactphysics3d/ *
* Copyright ( c ) 2010 Daniel Chappuis *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
* Permission is hereby granted , free of charge , to any person obtaining a copy *
* of this software and associated documentation files ( the " Software " ) , to deal *
* in the Software without restriction , including without limitation the rights *
* to use , copy , modify , merge , publish , distribute , sublicense , and / or sell *
* copies of the Software , and to permit persons to whom the Software is *
* furnished to do so , subject to the following conditions : *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software . *
* *
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR *
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY , *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER *
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM , *
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN *
* THE SOFTWARE . *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2009-10-08 21:56:58 +00:00
2010-02-06 18:42:04 +00:00
# ifndef SATALGORITHM_H
# define SATALGORITHM_H
2009-10-08 21:56:58 +00:00
// Libraries
# include "NarrowPhaseAlgorithm.h"
# include "../constraint/Contact.h"
# include "../body/OBB.h"
// ReactPhysics3D namespace
namespace reactphysics3d {
/* -------------------------------------------------------------------
2010-02-06 18:42:04 +00:00
Class SATAlgorithm :
2009-10-08 21:56:58 +00:00
This class implements a narrow - phase algorithm . This algorithm
uses a separating axis theorem ( SAT ) to check if two bounding
volumes collide or not . If the
two bounding volumes collide we have to create a contact object
to describe the collision contact . The idea is to check if there
exists an axis where , if we project the two bounding volumes on
this axis , the two projections are separated . If we find at
least an axis where the projections of the two bounding volumes
are separated then we know that the two bounding volumes don ' t
intersect .
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
2010-02-06 18:42:04 +00:00
class SATAlgorithm : public NarrowPhaseAlgorithm {
2009-10-08 21:56:58 +00:00
private :
2010-07-28 11:19:00 +00:00
bool computeCollisionTest ( const OBB * const obb1 , const OBB * const obb2 , ContactInfo * & contactInfo ) const ; // Return true and compute a contact info if the two OBB collide
double computePenetrationDepth ( double min1 , double max1 , double min2 , double max2 ) const ; // Compute the penetration depth of two projection intervals
Vector3D computeContactNormal ( const Vector3D & axis , const Vector3D & distanceOfOBBs ) const ; // Compute a contact normal
2009-12-23 10:06:34 +00:00
2009-10-08 21:56:58 +00:00
public :
2010-02-06 18:42:04 +00:00
SATAlgorithm ( ) ; // Constructor
~ SATAlgorithm ( ) ; // Destructor
2009-10-08 21:56:58 +00:00
2010-04-06 16:45:48 +00:00
virtual bool testCollision ( const BoundingVolume * const boundingVolume1 , const BoundingVolume * const boundingVolume2 , ContactInfo * & contactInfo ) ; // Return true and compute a contact info if the two bounding volume collide
2009-10-08 21:56:58 +00:00
} ;
2009-12-12 21:27:43 +00:00
// Return the contact normal with the correct sign (from obb1 toward obb2). "axis" is the axis vector direction where the
// collision occur and "distanceOfOBBs" is the vector (obb2.center - obb1.center).
2010-02-06 18:42:04 +00:00
inline Vector3D SATAlgorithm : : computeContactNormal ( const Vector3D & axis , const Vector3D & distanceOfOBBs ) const {
2009-12-25 09:39:02 +00:00
if ( distanceOfOBBs . scalarProduct ( axis ) > = 0.0 ) {
2009-12-12 21:27:43 +00:00
return axis ;
}
else {
return axis . getOpposite ( ) ;
}
}
2009-10-08 21:56:58 +00:00
} // End of the ReactPhysics3D namespace
# endif