geometry.h
author insilmaril
Mon, 24 Aug 2009 14:39:07 +0000
changeset 789 d85834ad8c54
parent 754 db0ec4bcf416
child 792 7d67be709091
permissions -rw-r--r--
Fixed collision methods, segfault for wrong flagname
     1 #ifndef GEOMETRY
     2 #define GEOMETRY
     3 
     4 #include <QPolygonF>
     5 
     6 QRectF addBBox(QRectF r1, QRectF r2);
     7 bool isInBox(const QPointF &p, const QRectF &box);
     8 
     9 class ConvexPolygon:public QPolygonF
    10 {
    11 public:
    12 	ConvexPolygon ();
    13 	ConvexPolygon (QPolygonF p);
    14 	void calcCentroid() ;
    15 	QPointF centroid() const;
    16 	qreal weight() const;
    17 private:
    18 	QPointF _centroid;
    19 	qreal _area;
    20 };
    21 
    22 QPointF normalize (const QPointF &p);
    23 
    24 
    25 qreal dotProduct (const QPointF &a, const QPointF &b);
    26 
    27 QPointF scale  (const QPointF &v,const qreal &f);
    28 QPointF invert (const QPointF &v);
    29 
    30 class PolygonCollisionResult {
    31 public:
    32     // Are the polygons going to intersect forward in time?
    33     bool willIntersect;
    34 
    35     // Are the polygons currently intersecting?
    36     bool intersect;
    37 
    38     // The translation to apply to the first polygon to push the polygons apart.
    39     QPointF minTranslation;
    40 };
    41 
    42 
    43 void projectPolygon(QPointF axis, QPolygonF polygon, qreal &min, qreal &max) ;
    44 
    45 qreal intervalDistance(qreal minA, qreal maxA, qreal minB, qreal maxB);
    46 PolygonCollisionResult polygonCollision(QPolygonF polygonA, 
    47                               QPolygonF polygonB, QPointF velocity);
    48 
    49 #endif