# HG changeset patch # User insilmaril # Date 1252501026 0 # Node ID cac93797c58032dca1bb0661fdf2858c067fa420 # Parent 7d67be709091158d00c2f68dc5863892602d991a more fixes for collision detection diff -r 7d67be709091 -r cac93797c580 branchobj.cpp --- a/branchobj.cpp Tue Sep 08 12:15:39 2009 +0000 +++ b/branchobj.cpp Wed Sep 09 12:57:06 2009 +0000 @@ -713,6 +713,19 @@ return bboxTotal; } +ConvexPolygon BranchObj::getBoundingPolygon() +{ + if (treeItem->branchCount()==0) + return MapObj::getBoundingPolygon(); + + QPolygonF p; + p<<bboxTotal.topLeft(); + p<<bboxTotal.topRight(); + p<<bboxTotal.bottomRight(); + p<<bboxTotal.bottomLeft(); + return p; +} + void BranchObj::calcBBoxSizeWithChildren() { // This is initially called only from reposition and diff -r 7d67be709091 -r cac93797c580 branchobj.h --- a/branchobj.h Tue Sep 08 12:15:39 2009 +0000 +++ b/branchobj.h Wed Sep 09 12:57:06 2009 +0000 @@ -56,6 +56,7 @@ virtual QPolygonF shape(); //!< Returns arbitrary bounding polygon virtual QRectF getTotalBBox(); // return BBox including children virtual QRectF getBBoxSizeWithChildren(); // return size of BBox including children + virtual ConvexPolygon getBoundingPolygon(); virtual void calcBBoxSizeWithChildren(); // calc size of BBox including children recursivly virtual QString getSelectString(); diff -r 7d67be709091 -r cac93797c580 mainwindow.cpp --- a/mainwindow.cpp Tue Sep 08 12:15:39 2009 +0000 +++ b/mainwindow.cpp Wed Sep 09 12:57:06 2009 +0000 @@ -1478,6 +1478,7 @@ a = new QAction( "Test function 2" , this); a->setStatusTip( "Call test function 2" ); + a->setShortcut (Qt::SHIFT + Qt::Key_T); testMenu->addAction (a); connect( a, SIGNAL( triggered() ), this, SLOT( testFunction2() ) ); diff -r 7d67be709091 -r cac93797c580 mapeditor.cpp --- a/mapeditor.cpp Tue Sep 08 12:15:39 2009 +0000 +++ b/mapeditor.cpp Wed Sep 09 12:57:06 2009 +0000 @@ -562,11 +562,15 @@ // Create list with all bounding polygons QList <MapObj*> mapobjects; QList <ConvexPolygon> polys; + ConvexPolygon p; QList <Vector> vectors; QList <Vector> orgpos; + QStringList headings; //FIXME-3 testing only + Vector v; BranchItem *bi; + BranchItem *bi2; BranchObj *bo; - TreeItem *ri=model->getRootItem(); + BranchItem *ri=model->getRootItem(); for (int i=0;i<ri->branchCount();++i) { bi=ri->getBranchNum (i); @@ -574,11 +578,28 @@ if (bo) { mapobjects.append (bo); - polys.append(bo->getBoundingPolygon()); - polys[i].calcCentroid(); + p=bo->getBoundingPolygon(); + p.calcCentroid(); + polys.append(p); vectors.append (QPointF(0,0)); - orgpos.append (polys[i].at(0)); - } + orgpos.append (p.at(0)); + headings.append (bi->getHeading()); + } + for (int j=0;j<bi->branchCount();++j) + { + bi2=bi->getBranchNum (j); + bo=(BranchObj*)bi2->getLMO(); + if (bo) + { + mapobjects.append (bo); + p=bo->getBoundingPolygon(); + p.calcCentroid(); + polys.append(p); + vectors.append (QPointF(0,0)); + orgpos.append (p.at(0)); + headings.append (bi2->getHeading()); + } + } } // Iterate moving bounding polygons until we have no more collisions @@ -593,25 +614,31 @@ if (polygonCollision (polys.at(i),polys.at(j), QPointF(0,0)).intersect ) { collisions++; - Vector v=polys.at(j).centroid()-polys.at(i).centroid(); + v=polys.at(j).centroid()-polys.at(i).centroid(); // Move also away if centroids are identical if (v.isNull()) { + //cout << "v==0="<<polys[i].centroid()<<polys[j].centroid()<<" "<<v<<" "<<headings[i].toStdString()<<" - "<<headings[j].toStdString()<<" "; v.setX (rand()%200 -100); v.setY (rand()%200 -100); + //cout << v; } v.normalize(); - cout << "v="<<v<<endl; v.scale (2); + //cout << " "<<v<<endl; vectors[j]=v; vectors[i]=v; vectors[i].invert(); - } + } } } for (int i=0;i<vectors.size();i++) + { + //cout << " v="<<vectors[i]<<" "<<headings[i].toStdString()<<endl; polys[i].translate (vectors[i]); + } //cout << "Collisions: "<<collisions<<endl; + //collisions=0; } // Finally move the real objects and update diff -r 7d67be709091 -r cac93797c580 treemodel.cpp --- a/treemodel.cpp Tue Sep 08 12:15:39 2009 +0000 +++ b/treemodel.cpp Wed Sep 09 12:57:06 2009 +0000 @@ -277,7 +277,7 @@ return NULL; } -TreeItem *TreeModel::getRootItem() +BranchItem *TreeModel::getRootItem() { return rootItem; } diff -r 7d67be709091 -r cac93797c580 treemodel.h --- a/treemodel.h Tue Sep 08 12:15:39 2009 +0000 +++ b/treemodel.h Wed Sep 09 12:57:06 2009 +0000 @@ -35,11 +35,11 @@ const QModelIndex & parent = QModelIndex() ); TreeItem* getItem (const QModelIndex &index) const; - TreeItem* getRootItem(); + BranchItem* getRootItem(); protected: - TreeItem *rootItem; + BranchItem *rootItem; }; #endif diff -r 7d67be709091 -r cac93797c580 version.h --- a/version.h Tue Sep 08 12:15:39 2009 +0000 +++ b/version.h Wed Sep 09 12:57:06 2009 +0000 @@ -7,7 +7,7 @@ #define __VYM_VERSION "1.13.0" //#define __VYM_CODENAME "Codename: RC-1" #define __VYM_CODENAME "Codename: development version, not for production!" -#define __VYM_BUILD_DATE "2009-09-08" +#define __VYM_BUILD_DATE "2009-09-09" bool checkVersion(const QString &);