Results 1 to 16 of 16

Thread: Collision detection on circle outside of BoundingRect

Hybrid View

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

    Default Re: Collision detection on circle outside of BoundingRect

    Basically the fastest approach is to go through a list of items that can collide with your tower (which is easy to keep or calculate using a bounding rectangle of the circle) and then iterate through the list and check the euclidean distance between the tower and the item. It can even be distributed among many threads if available.
    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.


  2. #2
    Join Date
    Feb 2014
    Posts
    23
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Collision detection on circle outside of BoundingRect

    Actually somehow I stumbled across the idea to limit all of my collision detecting to using the bounding rectangles and I created a new dummy class that I add to the scene and use it to detect the rectangular collisions for any given object. The problem that is now occurring is handling the collision detection for many objects becomes far too expensive a task to be handled in a single thread. This is my first experience trying to use QThread, or any type of threading for that matter, so I'm a little confused as to where and how I would send the collision detecting tasks to different threads.

    Currently I have all of my collision detecting taking place in the advance(step=0) function for any of the graphicsobjects. By doing so, when the advance(step=1) call is made, the graphicsobjects can simply perform the proper task based on their current situation. Thus there should be no issue with threading out the collision detection for each object into different threads, but I'm unclear where I should put the threading code.

    Should the threading be declared as its own class and then the object and scene that need to be processed for some kind of detection be passed into that class?

    Or should the thread be declared within each graphicsobject and called when that object attempts to detect any collision that is occurring.

    Also, would I still want to declare a main thread? It seems as though the answer would be no, as I would not want the main thread getting ahead of the collision processing and starting up the advance(step=1) processing while some of the collision detection processing is still occurring.

    Thanks!

  3. #3
    Join Date
    Feb 2014
    Posts
    23
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: Collision detection on circle outside of BoundingRect

    So after posting my previous question, I went to my professor to see if he could also provide some insight into threading. Well after about thirty minutes of showing him that only threading would improve the performance further from where I was, he told me to lower the frame rate and not to attempt threading.

    Well, I'm not that kind of student. Shortly after I finally found an example of use that made sense and translated well into my usage, applied it to my code and everything seems to be working. Checking the processor usage on the Linux machines in our lab shows that all of the processors are taking on a shared load, where one was being over-ran before I inserted the threading.

    BUT, after a few objects get on the scene, suddenly my project closes and the Debug display reads "The program has finished unexpectedly"

    The only thing I can determine that would be causing the program to suddenly close without error, is I don't have a thread created to handle the "main" program, so the scene/view and everything suddenly are left without an active thread, which causes the entire program to finish.

    I've tried to find different manners to create a separate thread to handle the main execution of the program so it stays active continuously when the other threading occurs, but I can't seem to figure out how/where to put the view/scene into their own thread. Adding the view returns an error about trying to thread a QWidget, and the scene isn't adding properly into a thread and running within the view.

    If anyone could help me get through this last step, it would be pretty awesome to go back to my professor and say, "hey I know you said dont do this, but I did anyways, and it works, so give me an A"

    Thanks

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Collision detection on circle outside of BoundingRect

    I went to my professor to see if he could also provide some insight into threading. Well after about thirty minutes of showing him that only threading would improve the performance further from where I was, he told me to lower the frame rate and not to attempt threading.
    Your professor is a wise man. Threads add complexity.

    You cannot put a QGraphicsView into a thread because GUI objects must be in the GUI thread. Leave the GUI and scene in the main thread. As wysota said you can delegate the work of detailed collision checks (on candidates identified by quick checks) to threads by passing the centre and radius of each object to a processor in the other thread(s). You might like to look at QtConcurrent.

    The "The program has finished unexpectedly" message is usually the result of using a null, undefined, or no-longer-valid pointer. It could also be the result of multiple threads sharing a data structure with protection. Your debugger will tell you exactly which line the crash occurred on and allow you to inspect variables while step back through callers to identify the culprit.

Similar Threads

  1. Replies: 3
    Last Post: 16th July 2012, 11:01
  2. QGraphicsPixmapItem collision detection
    By sophister in forum Qt Programming
    Replies: 7
    Last Post: 4th July 2010, 19:36
  3. collision detection...
    By Muffin in forum Newbie
    Replies: 1
    Last Post: 8th January 2010, 10:28
  4. turn off collision detection?
    By Deacon in forum Qt Programming
    Replies: 14
    Last Post: 30th December 2008, 17:37
  5. 2D Race Car collision detection
    By neonnds in forum Qt Programming
    Replies: 0
    Last Post: 6th July 2008, 08:10

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.