Results 1 to 10 of 10

Thread: determining how to bounce the ball

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: determining how to bounce the ball

    Quote Originally Posted by aamer4yu View Post
    When you get a list of items, u can check to which class it belongs using dynamic cast,,, or u can use a extra variable in the class.
    qgraphicsitem_cast() is the way to go.

  2. #2
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: determining how to bounce the ball

    Thanks i (think i) understand how to detect objects now.
    How about the second half of the question? Any ideas? Maybe if i try translating current position of the ball to the hit item's coordinate system and see if it does? Or is there a better way?

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

    Default Re: determining how to bounce the ball

    QGraphicsItem::collidingItems() returns a list of items colliding with a particular item.

  4. #4
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: determining how to bounce the ball

    Quote Originally Posted by wysota View Post
    QGraphicsItem::collidingItems() returns a list of items colliding with a particular item.
    I meant how to determine how to bounce the ball off the hit object. Or am i missing something?

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

    Default Re: determining how to bounce the ball

    Hmmm... what do you mean "how"? You mean physics?

    BTW. Have you seen this?
    http://doc.trolltech.com/qq/qq20-jambi.html

  6. #6
    Join Date
    Nov 2007
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: determining how to bounce the ball

    I have seen that example but except for some code for working with the scene there isnt really anything i need.
    And to explain what i need... right now i have a ball object which has x and y velocity. So every time a time trigger triggers i move it by that values. But now i dont know whether the ball hit something by its x axis (where i have to invert the x velocity) or y axis (where i have to invert the y velocity).
    One idea i had is to move the ball only by x or y every time i have a time trigger event and then check for collision but im not sure if its such a good idea.
    So if you have a better idea it would really mean a lot
    Thanks

    edit: damn im dumb.. if i get a list of items colliding with the ball i can simply check which coordinates equals those of the ball.
    Last edited by Binji; 29th December 2007 at 12:10.

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

    Default Re: determining how to bounce the ball

    Quote Originally Posted by Binji View Post
    edit: damn im dumb.. if i get a list of items colliding with the ball i can simply check which coordinates equals those of the ball.
    They might not be "equal". Collision is determined by shape, not by the centre point, so you can hit "by the corner" as well and "harder" in one direction than in the other. But these are all simple calculations.

  8. The following user says thank you to wysota for this useful post:

    Binji (30th December 2007)

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
  •  
Qt is a trademark of The Qt Company.