At 7/1/09 06:41 AM, Bezman wrote:
I don't see how you can call this collision detection - I mean I can't see any of the pixels moving, let along colliding. :-/
Despite your snide comments I'm sure folk - including myself - WOULD care if you bothered to clearly explain what's going on.
Okay in the example you have a coordynate space of 400 x 400 pixels. 100'000 points (blue pixels) get created and spread randomly over that space.
The camera is represented by a darker blue square that is attached to the mouse. When you move the mouse the camera moves.
A collision detection between the camera rectangle and every point is performed by querying the quad tree. It returns all points that are in the camera area or that could be colliding with it.
So you go and try doing a hittest of 100'000 movieclips vs. another movieclip and see if it works. This approach here runs a lot faster by bypassing all objects that are too far away to collide and only gives you the objects that could be colliding to do hittests with.
The points that are colliding with the camera are drawn 4 times bigger and in red, to make them more visible.
No the points are not moving, but they could be! I just have not made such an example (yet).
Instead of testing 1 cam against points you could also be testing every point against every other point with just O(n log n) instead of O(n * n) if checking every object with brute force against every other object.