# HG changeset patch # User insilmaril # Date 1201879715 0 # Node ID 9abdd5e6c3dc315ee1545c988e90bf4fef6c7d1d # Parent 6a5e2c27f8a4da1b1723da9ba4016812844cbb31 Added brasilian translation by Amadeu JĂșnior diff -r 6a5e2c27f8a4 -r 9abdd5e6c3dc geometry.cpp --- a/geometry.cpp Fri Feb 01 15:28:35 2008 +0000 +++ b/geometry.cpp Fri Feb 01 15:28:35 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="<