Results 1 to 7 of 7

Thread: Collision direction

  1. #1
    Join Date
    Nov 2013
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Collision direction

    I'm trying to make a simple game. I have some items in QGraphicsView, and I'm trying to make a ball to bounce off of them. Here's the problem: I can detect when a collision happens, but I don't know in which direction the ball should bounce. For that I would need to find out the tangent of the surface of the item. The items can be of any shape, and the collision should look physically correct. Any help appreciated.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Collision direction

    you will need to know the bounding shape. Is this splined/smooth? or straight line polygons?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2013
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Collision direction

    I'm sorry, I didn't fully understand the question. Most of the items are circles. In addition, there's one item that restricts the game area, it has curves which can be practically any shape. It can be thought of as a rectangle with rounded corners, and the ball must stay within it. Is there any way to get the cutting points of the shapes of these 2 colliding items? In that case, the angle of the tangent would be (y2-y1)/(x2-x1).

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Collision direction

    get the path() and use toFillPolygon to get a polygon representation of the item shape. The rest is up to you to look for algorithms. You need to match the collision point to somewhere on the path boundary path, and then determine the tangent. I don't think Qt will help you here.


    Added after 9 minutes:


    You might like to look into cinder.
    Last edited by amleto; 2nd November 2013 at 22:06.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Collision direction

    The best approach is external library. Box2d will do this quite well. Once I've used it with QGraphicsView and results where very good.

  6. #6
    Join Date
    Nov 2013
    Posts
    6
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Windows

    Default Re: Collision direction

    Thanks for the advice, but because this is a course project, I'm not allowed to use external libraries.

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Collision direction

    Maybe QPainterPath::angleAtPercent() will be of use.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Need Help Regarding Qt GraphicsItem Collision
    By RE in forum Qt Programming
    Replies: 4
    Last Post: 28th September 2012, 11:12
  2. Collision between QGraphicsItem -
    By been_1990 in forum General Discussion
    Replies: 6
    Last Post: 19th November 2010, 12:32
  3. collision detection...
    By Muffin in forum Newbie
    Replies: 1
    Last Post: 8th January 2010, 10:28
  4. direction
    By panduro in forum Qt Programming
    Replies: 1
    Last Post: 23rd July 2008, 19:51
  5. Collision handling 101
    By Morea in forum Qt Programming
    Replies: 9
    Last Post: 25th November 2006, 20:17

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.