diff -r 53ef954e90b6 -r 11f9124c1cca geometry.cpp --- a/geometry.cpp Wed Jan 16 15:45:19 2008 +0000 +++ b/geometry.cpp Mon Aug 04 10:43:06 2008 +0000 @@ -1,7 +1,10 @@ #include "geometry.h" #include +#include +#include "misc.h" +using namespace std; QRectF addBBox(QRectF r1, QRectF r2) { @@ -44,8 +47,9 @@ QPointF normalize (const QPointF &p) { - qreal n=sqrt ( p.x()*p.x() + p.y()*p.y() ); - return QPointF (p.x()/n,p.y()/n); + if (p==QPointF(0,0)) return p; + qreal l=sqrt ( p.x()*p.x() + p.y()*p.y() ); + return QPointF (p.x()/l,p.y()/l); } // Dot product of two vectors @@ -54,19 +58,6 @@ return a.x()*b.x() + a.y()*b.y(); } -// Structure that stores the results of the PolygonCollision function -class PolygonCollisionResult { -public: - // Are the polygons going to intersect forward in time? - bool WillIntersect; - - // Are the polygons currently intersecting? - bool Intersect; - - // The translation to apply to the first polygon to push the polygons apart. - QPointF MinimumTranslationVector; -}; - /* Calculate the projection of a polygon on an axis and returns it as a [min, max] interval @@ -110,8 +101,8 @@ PolygonCollisionResult PolygonCollision(QPolygonF polygonA, QPolygonF polygonB, QPointF velocity) { PolygonCollisionResult result; - result.Intersect = true; - result.WillIntersect = true; + result.intersect = true; + result.willIntersect = true; int edgeCountA = polygonA.size(); int edgeCountB = polygonB.size(); @@ -119,14 +110,42 @@ QPointF translationAxis; QPointF edge; + cout << "\nA: "; + for (int k=0; k 0)\ - result.Intersect = false; + if (intervalDistance(minA, maxA, minB, maxB) > 0) + result.intersect = false; + else + result.intersect = true; // ===== 2. Now find if the polygons *will* intersect ===== @@ -156,42 +177,58 @@ // Get the projection of polygon A during the movement - if (velocityProjection < 0) { + if (velocityProjection < 0) minA += velocityProjection; - } else { + else maxA += velocityProjection; - } + // Do the same test as above for the new projection qreal d = intervalDistance(minA, maxA, minB, maxB); - if (d > 0) result.WillIntersect = false; + if (d > 0) result.willIntersect = false; + /* + */ + cout <<" "; + cout <<"minA="<