Fixed bug in friend item collision detection
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 8 Jul 2010 11:51:51 +0000 (14:51 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 8 Jul 2010 11:51:51 +0000 (14:51 +0300)
 - collision detection in FriendItemsHandler::collides() method
   did not work correctly when item2 was over the world limits
   and item1 was near the world limit at the opposite side
   of the world

 - update only previously grouped friend items isPartOfGroup status
   when destructing all groups

src/map/friendgroupitem.cpp
src/map/frienditemshandler.cpp
src/map/frienditemshandler.h

index 1fa53ed..e812832 100644 (file)
@@ -58,8 +58,8 @@ bool FriendGroupItem::dropFriends(int zoomLevel)
     qDebug() << __PRETTY_FUNCTION__;
 
     foreach (FriendLocationItem *friendItem, m_friends) {
-        if (!friendItem->sceneTransformedBoundingRect(zoomLevel)
-            .intersects(sceneTransformedBoundingRect(zoomLevel)))
+//        if (!friendItem->sceneTransformedBoundingRect(zoomLevel)
+//            .intersects(sceneTransformedBoundingRect(zoomLevel)))
             dropFriend(friendItem);
     }
 
index a790125..aa24d54 100644 (file)
@@ -155,20 +155,21 @@ void FriendItemsHandler::checkGroupForCollidingGroups(FriendGroupItem *group)
 
 bool FriendItemsHandler::collides(BaseLocationItem *item1, BaseLocationItem *item2)
 {
-    QRect rect = item1->sceneTransformedBoundingRect(m_zoomLevel);
+    QRect item1Rect = item1->sceneTransformedBoundingRect(m_zoomLevel);
+    QRect item2Rect = item2->sceneTransformedBoundingRect(m_zoomLevel);
 
-    if (rect.intersects(item2->sceneTransformedBoundingRect(m_zoomLevel)))
+    if (item1Rect.intersects(item2Rect))
         return true;
 
-    if (rect.left() < MAP_MIN_PIXEL_X) {
-        QRect translated = rect.translated(MAP_PIXELS_X, 0);
-        if (translated.intersects(item2->sceneTransformedBoundingRect(m_zoomLevel)))
+    if (item1Rect.left() < MAP_MIN_PIXEL_X + item1Rect.width() / 2) {
+        QRect translated = item1Rect.translated(MAP_PIXELS_X, 0);
+        if (translated.intersects(item2Rect))
             return true;
     }
 
-    if (rect.right() > MAP_MAX_PIXEL_X) {
-        QRect translated = rect.translated(-MAP_PIXELS_X, 0);
-        if (translated.intersects(item2->sceneTransformedBoundingRect(m_zoomLevel)))
+    if (item1Rect.right() > MAP_MAX_PIXEL_X  - item1Rect.width() / 2) {
+        QRect translated = item1Rect.translated(-MAP_PIXELS_X, 0);
+        if (translated.intersects(item2Rect))
             return true;
     }
 
@@ -186,11 +187,14 @@ void FriendItemsHandler::deleteFriendItem(FriendLocationItem *item)
 
 void FriendItemsHandler::destructGroups()
 {
+    foreach (FriendGroupItem *group, m_friendGroupItems)
+        group->dropFriends(0);
+
     qDeleteAll(m_friendGroupItems);
     m_friendGroupItems.clear();
 
-    foreach (FriendLocationItem *item, m_friendItems)
-        item->setPartOfGroup(false);
+//    foreach (FriendLocationItem *item, m_friendItems)
+//        item->setPartOfGroup(false);
 }
 
 void FriendItemsHandler::dropFriendFromAllGroups(FriendLocationItem *item)
index 7ce25af..20942ff 100644 (file)
@@ -124,9 +124,9 @@ private:
     /**
     * @brief Check if items collide
     *
-    * Does check if items sceneTransformedBoundingRect() does intersect. If item1's rect is
-    * over the limits of the map, then rect is translated to opposite side of the map and
-    * intersections are tested there too.
+    * Does check if items sceneTransformedBoundingRect() does intersect. If item1's rect is max
+    * half of the rect width from the vertical limits of the map (from inside), then rect is
+    * translated to opposite side of the map and intersections are tested there too.
     *
     * @param item1 First item
     * @param item2 Secont item