Collision between QGraphicsItem -
Does it matter if I check collision of a GraphicsItem to every other item in a scene or if I check collision of an item against the parent of these items?
Ex:
Option 1:
Code:
[...]
mainItem.collidesWithItem(generic1);
mainItem.collidesWithItem(generic2);
[...]
mainItem.collidesWithItem(generic30);
Option2:
Code:
[...]
mainItem.collidesWithItem(genericItemParent);
Which one is faster?
Re: Collision between QGraphicsItem -
I would partition my scene to minimize the number of objects I am tracking for collision.
Re: Collision between QGraphicsItem -
How do I partion the scene? Never heard of that...
Re: Collision between QGraphicsItem -
Re: Collision between QGraphicsItem -
Sorry, "how to do it in QT?" should be the question.
So, if I mapToScene() my graphicsView viewport rect, then check any colliding items, then check if those items collide with the "mainItem"?
Example (pseudo-code):
Code:
[...]
//-------------------------------------//
void addSceneItems(){/* add all items to scene */ }
view.setScene(scene);
polygon = view.mapToScene(0,0,view.width(),view.height);
//--> make poligon "invisible" somehow...
void itemVSpoli()
{
for(int i=0;i<scene.items().count();i++)
{
if(scene.itemAt(i).collidesWithItem(polygon))
//send item to function that checks if
// it collides with mainItem.
}
}
Re: Collision between QGraphicsItem -
So it was simpler than that:
Code:
QPolygonF poli
= sceneView
->mapToScene
(0,
0,sceneView
->width
(),sceneView
->height
());
QList<QGraphicsItem *> sceneItems;
sceneItems = scene->items(poli); //this only returns items that are drawn in the screen
Re: Collision between QGraphicsItem -
And why not just do this?
Code:
//...
QList<QGraphicsItem*> collisions = scene->collidingItems(myItem);