Results 1 to 2 of 2

Thread: collision detection...

  1. #1
    Join Date
    Oct 2009
    Location
    Sweden
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default collision detection...

    Hi

    I hava a problem with collision detection. in the picture below the lable Cargo5.5 dosn't detect collision with the QGraphicsPathItem belonging to Cargo6. The outline of the lables is the shape() of the item.

    http://www.tiny.cc/ShWEW

    the implementation of shape() looks like this

    Qt Code:
    1. QPainterPath SVGText::shape() const
    2. {
    3. path.addRect(this->boundingRect().adjusted(0,4,0,-4));
    4. return path;
    5. }
    To copy to clipboard, switch view to plain text mode 

    and the function where i test for collision, this is where the m_pTextItem e.g Cargo5.5 dosn't detect collision with the QGraphicsPathItem
    altough the shape of Cargo5.5 intersects/contains with the QGraphicsPathItem of Cargo6

    Qt Code:
    1. int SVGPath::TextCollitionCount()
    2. {
    3. int collCount = 0;
    4. QList<QGraphicsItem *> collidingWithList = m_pTextItem->collidingItems(Qt::ContainsItemShape);
    5. collCount = collidingWithList.count();
    6. if(collCount)
    7. {
    8. for(QList<QGraphicsItem*>::iterator it = collidingWithList.begin();it != collidingWithList.end();)
    9. {
    10. if((*it)->type() == SVGPath::Type)
    11. {
    12. SVGPath *item = qgraphicsitem_cast<SVGPath *>(*it);
    13. if(m_pTextItem->collidesWithPath(item->shape(),Qt::ContainsItemShape))
    14. it++;
    15. else
    16. it = collidingWithList.erase(it);
    17. }
    18. }
    19. }
    20. }
    To copy to clipboard, switch view to plain text mode 

    is there something i have missed? stacking of items shouldn't matter should it? this application has no paint event etc it's sort of a static presentation (for now) so everyting is added to the scene and later on i set scene to the view.

    Regards Muffin www.a-eon.com

  2. #2
    Join Date
    Oct 2009
    Location
    Sweden
    Posts
    8
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: collision detection...

    Qt::ContainsItemShape should not be there, leftovers from previous test.I now also have boundingRect() like this:
    Qt Code:
    1. QRectF SVGText::boundingRect() const
    2. {
    3. QRectF newRect = QGraphicsTextItem::boundingRect();
    4. newRect = newRect.adjusted(0,4,0,-4);
    5. return newRect;
    6. }
    7. QPainterPath SVGText::shape() const
    8. {
    9. path.addRect(this->boundingRect());
    10. return path;
    11. }
    To copy to clipboard, switch view to plain text mode 

    but that doesn't help much, the strange thing is that some lables report collision although they are no way near intersecting and others are clearly intersecting but doesn't detect that. ??? i'm confused

Similar Threads

  1. turn off collision detection?
    By Deacon in forum Qt Programming
    Replies: 14
    Last Post: 30th December 2008, 17:37
  2. 2D Race Car collision detection
    By neonnds in forum Qt Programming
    Replies: 0
    Last Post: 6th July 2008, 08:10
  3. Collision detection QGraphicsItem
    By Blade in forum Qt Programming
    Replies: 5
    Last Post: 5th January 2007, 10:20
  4. Painting and collision detection
    By aamer4yu in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2006, 08:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.