geometry.h
author insilmaril
Thu, 01 Oct 2009 11:28:50 +0000
changeset 798 d251c7b2de54
parent 792 7d67be709091
child 824 36eb4b8f409e
permissions -rw-r--r--
Various fixes for relinking and selecting
     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 
    10 class Vector:public QPointF
    11 {
    12 public:
    13 	Vector ();
    14 	Vector (const QPointF &p);
    15 	Vector (qreal x, qreal y);
    16 
    17 	friend inline bool operator==(const Vector &v1, const Vector &v2 )
    18 	{ return v1.x()==v2.x() && v1.y()==v2.y(); }
    19 
    20 	virtual void normalize ();
    21 	virtual qreal dotProduct (const QPointF &b);
    22 	virtual void scale  (const qreal &f);
    23 	virtual void invert ();
    24 	virtual QPointF toQPointF();
    25 };
    26 
    27 class ConvexPolygon:public QPolygonF
    28 {
    29 public:
    30 	ConvexPolygon ();
    31 	ConvexPolygon (QPolygonF p);
    32 	void calcCentroid() ;
    33 	QPointF centroid() const;
    34 	qreal weight() const;
    35 	std::string toStdString ();
    36 	Vector at (const int &i) const ; 
    37 	virtual void translate ( const Vector &offset );
    38 	virtual void translate ( qreal dx, qreal dy );
    39 private:
    40 	Vector _centroid;
    41 	qreal _area;
    42 };
    43 
    44 class PolygonCollisionResult {
    45 public:
    46     // Are the polygons going to intersect forward in time?
    47     bool willIntersect;
    48 
    49     // Are the polygons currently intersecting?
    50     bool intersect;
    51 
    52     // The translation to apply to the first polygon to push the polygons apart.
    53     QPointF minTranslation;
    54 };
    55 
    56 
    57 void projectPolygon(Vector axis, ConvexPolygon polygon, qreal &min, qreal &max) ;
    58 
    59 qreal intervalDistance(qreal minA, qreal maxA, qreal minB, qreal maxB);
    60 PolygonCollisionResult polygonCollision(ConvexPolygon polygonA, 
    61                               ConvexPolygon polygonB, Vector velocity);
    62 
    63 #endif