You are browsing as a guest. Sign up (or log in) to start making projects!

3h 12m 35s logged

Devlog 5: Speed up thanks to Spatial Partitioning

So now I’ve done it, the next thing on my To-Do list is completed, as seen in my last Devlog, it was to Optimize and Improve calculations, and I did that, mostly by implementing Spatial Partitioning.
How it works is that, if there is only a certain range around an particle, in this case the MaxRange, you can pretty much ignore everything outside of this range when calculating attraction, instead of having to check the distance to each particle, and getting the same result. To do that you split the area where the particles can be into squares(Cells) with length of MaxRange, and then assinging each particle a key, which you get like this:
key = someHashFunction(CellPos.x, CellPos.y) % ParticleAmount
And then with some sorting and such, you can calculate the attractions, only the Cell the particles in, and the 8 cells around it.

This was somewhat simplified, but I hope one could understand it.

And in the video below, you can see me simulating 4000 particles, at roughly 10 fps, which might not sound like a lot, but compared to before, where simulating 2000 particles resulted in about 5 fps, it certainly is.

To-Do:

  • Add interaction based on color and distance.
  • Optimize and Improve calculations.
  • Add an GUI / Interface
0
10

Comments 0

No comments yet. Be the first!