Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

retrieval of object out side the node #6

Closed
vinujan59 opened this issue Sep 20, 2016 · 6 comments
Closed

retrieval of object out side the node #6

vinujan59 opened this issue Sep 20, 2016 · 6 comments

Comments

@vinujan59
Copy link

I am observing objects that are selected for collision which are not in the node even not in the boundry

@robblovell
Copy link

I think this manifests in the examples given. In the simple and dynamic examples, nodes that are far away from the cursor and corresponding quadtree bucket are highlighted. Why? They appear to be close to an x-y axis.

@robblovell
Copy link

Okay, I see what's going on. The GetIndex checks if the object is completely in the node. If it's not, the parent node is assumed. The objects that are along boundaries of the main four nodes just below the root, will always be considered to be close to all other objects.

@kfern
Copy link

kfern commented Feb 29, 2020

This simple screenshoot show the bug.

image

Any plan to solve it?

@timohausmann
Copy link
Owner

Hey, thanks for bringing this up again. Like @robblovell wrote, this behaviour stems from the tutorials design decision to store objects that don't fully fit into one quadrant on the parent node.

However, some years passed and I get how this just seems suboptimal. So I tried the other approach: only store objects on leaf nodes (lowest level). Now if an object overlaps multiple leaf nodes, it will simply be referenced multiple times (once in each matching leaf node). This indeed achieves smaller amounts of candidates and even faster retrievement in every browser I tested (Win10 IE11, Edge, Chrome, FF).

I put together two demos retrieving candidates from 10.000 objects with the old algorithm 1.1.3 and the new algorithm 1.2.0 and I'm thrilled by the improvements.

This repository, npm registry and the online examples are updated to 1.2.0.

I'd be happy about some feedback if this change fixes the issue or if I'm missing something. Then I will close this issue.

@kfern
Copy link

kfern commented Mar 2, 2020

@timohausmann Thanks 👍

Now works better

image

Can be detected only objects that intersect with the white box?

@timohausmann
Copy link
Owner

Collision detection is currently out of scope for this project.

You can code your own rectangle collision check after retrieving the green candidates:
https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants