Quad grid collisions and spacial partitioning

Hi there, last time I posted about this question, I was attempting to create a program that would help in calculating collisions, in circular bodies, the standard calculation without any grid management involves n to the n calculations and so can be costly when using a large dataset.

My first attempt was very flawed and only barely worked, so after a fresh look at the problem I have addressed all the problems, ideally I would like to turn this into a library later, if anyone has any ideas or would like to contribute please feel free, otherwise here is the code.

check performance by comparing the reg_collisions, with the quad_collisions.

Please note further speed improvements can be attained using FX2D, however this may depend on specific use.

If you notice any errors please let me know

1 Like

Thanks for sharing this. How do you imagine it becoming a reusable library? Would e.g. quad_collidable be an interface that users could implement in their objects?

Collision detection can be a bit tricky to generalize as an a la carte small library outside a full framework like JBox2D – or toxiclibs – or gicentre utils (hashgrid) – or Pixelflow. These are all big libraries, and the collision part may be in part because it matters a lot whether you are testing circle-rect or polygon-point or line-line collision, if you do it by axis aligned bounding boxes, and then whether the colliding object classes are important and if the collidee properties like angle/speed/size are needed for what happens next (to bounce, or hitpoints, or inventory etc.)…

1 Like

not sure I’ll have to make use of matrices, and then I suppose I would have to tailor the quad_collide to account for these cases.

an update on this project. Ive updated it and ironed out flaws, and have made a second version which now now makes use of dynamic size grids.

note this does not necessarily give the best speed, I was averaging 45-55 fps using the FX2D renderer using 4000 entities however it is useful when you have to compute static neighbouring entities rather than having to go through the entire grid.

original’s (static size) speed.

I understand other established libraries will probably make more robust/ efficient versions of this idea, but this was a fun idea, and allows me to quickly integrate it within any project.

new ( dynamic size);