deviant art





Login
Join deviantART for FREE Take the Tour Lost Password?
Deviant Login
Shop
 Join deviantART for FREE Take the Tour
[x]

More from ~wonderwhy-ER

Featured in Groups:

Details

September 26, 2008
22.2 KB
600×600
Link
Thumb

Statistics

Comments: 37
Favourites: 17 [who?]
Views: 2,125 (0 today)
Downloads: 80 (0 today)

License

Creative Commons License
Some rights reserved. This work is licensed under a
Creative Commons Attribution-Noncommercial-Share Alike 3.0 License.
[x]
:iconwonderwhy-er:
So this was initiated by :iconaxcho: who recently asked me about algorithm I would recommend for collision detection broad phase and in particular mentioned sweep+prune [link]

This initiated series of tests and thinking on my part as I found this algorithm to be interesting. So result was that I tested different algorithms of sorting/finding/inserting items in arrays in flash [link] and came to a conclusion that Array.sort and Array.indexOf work so fast that probably should win over even faster algorithms of collision detection if I manage to make algorithm based on those core procedures.

Also I digged out my previous algorithm which turned out to be something like QuadTree algorithm(found out that recently :D) and exchanged it to my realization of sweep+prune.

Usage and performance information/comparison
Usage. Well there is one bull under your cursor which you control and you can input ball count in box in Left-Bottom corner.

MoveAndRemove - step at which algorithm runs trough all balls and moves them and check if it is needed to remove those which flew beyond the screen.

SortAxis - there are separate array for each axis in which balls are contained. On this step those arrays are resorted.

checkSortedForColission - on this step sorted axis arrays are checked for object bondings intersections in pretty fast way. From what I can say a very fast way. Problem is then to find same pairs that intersected on both axis X and Y. And this so far is biggest slow down in this step. Need to think some more on it.

finalPairCheckAndResolve - on this step pairs that intersected on both axis are checked for collision more precisely and if determined to collide then collision is resolved.

Memory: Determines how much memory program currently uses.

Update
After some thinking and performance testings made changes to the algorithm. In short I changed how checkSortedForColission works and combined second part of checkSortedForColission with finalPairCheckAndResolve. As a result I got some 50% of performance boost :D Check journal to see results.

And extended explanation. Well Sweep+Prune sorts objects in separate arrays according to one of the axis of space. In those arrays those those objects are represented as one dimensional intervals which are easy to check for intersection. So in the end we have groups of intersections on each axis. Then we need to combine our results so that object pairs that intersect on all axis are pushed further to more precise/resource intensive checking and others are filtered out. Most resource taking part here is finding pairs that are contained in all axis arrays. Well before I was using Object for this. Turned out that I can use integers instead of strings as keys which makes it much faster but in the end made an algorithm based on Array and custom hashing function. So now bottleneck is sorting which is ridiculously fast :D Though I may try some more ideas on how to speed up this part.

Also before I was creating final pair list and looping trough it in separate loop but now understood that that was not necessary and merged it with last axis loop.
:icon:
Add a Comment:
 
love 0 0 joy 1 1 wow 0 0 mad 0 0 sad 0 0 fear 0 0 neutral 0 0
:iconaxcho:
Wow, thanks for the breakdown on sweep and prune! I'll be interested in comparing when I get around to writing my own implementation of it. :)

--
I believe that games will be as significant a new medium as the printed word ever was, and as powerful a force for change.

I am here to make that happen. Making life more fun
Reply
:iconwonderwhy-er:
Welcome :) Was interesting to do it anyways. Seems it is wining because of possibility to use Array.sort :)

--
There is only a Flash between the past and future, and exactly that is what I call life… at least for Flasher/Scripter/Designer :D
Reply
:iconrocketship123:
coordinate rotation??
Thats fun stuff!!
Nice job!!

--
Flashism.

I support DA Sound Dimension [link]
Reply
:iconwonderwhy-er:
Nut shore what you mean by coordinate rotation...

--
There is only a Flash between the past and future, and exactly that is what I call life… at least for Flasher/Scripter/Designer :D
Reply
:iconrocketship123:
its rotating the entire stage, invisibly.. like instead of bouncing angles at angles, you rotate everything bounce it, rotate it back and continue

--
Flashism.

I support DA Sound Dimension [link]
Reply
:iconwonderwhy-er:
Ouh no nothing like that :)

--
There is only a Flash between the past and future, and exactly that is what I call life… at least for Flasher/Scripter/Designer :D
Reply
:iconrocketship123:
figured youd have a better way :)

--
Flashism.

I support DA Sound Dimension [link]
Reply
:iconwonderwhy-er:
Well what you described seems too processor intensive... I just used projection of force vector and calculated energy transfer according to it. Calculation intensive thing actuality and sometimes there are few ways to do it faster but most expendable. Direction, forces involved etc etc may be retrieved if needed and used to parametrize effects or different events like "this punch was too weak" :)

--
There is only a Flash between the past and future, and exactly that is what I call life… at least for Flasher/Scripter/Designer :D
Reply
:iconrocketship123:
oh.. that makes sense...
when I first heard about coodinate rotation, i though its would be way to processor intensive... but when i tried it, it was the opposite.. when I post my new particle system, i have it in there...

--
Flashism.

I support DA Sound Dimension [link]
Reply
:iconwonderwhy-er:
Well thing is that you don't really need to rotate one direction make calculation and rotate beck for pair that collided. It is enough to leave coordinates of balls intact but trough projections get needed information about collision. Though it will be interesting to see your experiment :)

--
There is only a Flash between the past and future, and exactly that is what I call life… at least for Flasher/Scripter/Designer :D
Reply
(1 Reply)
:icon:
Add a Comment: