mattdesl / verlet-system

2D and 3D verlet integration
http://mattdesl.github.io/verlet-system/demo/line.html
MIT License
75 stars 5 forks source link

Callback per collision #2

Open mrozbarry opened 8 years ago

mrozbarry commented 8 years ago

Any chance of seeing something like:

world = VerletSystem({
    gravity: [0, 500],
    min: [0, 0],
    max: [width, height]
    onCollision: function(pointA, pointB, force) {}
});

I've been poking around different physics engines for something incredibly lean with a simple api, and your engine is what I'm looking for, I think.

It sounds like if I add a radius to any of my points, they can collide with each other? If so, the collision callback would be really awesome. If not, any recommendations on a collision detection/resolver module? SAT looked good, but it only does detection, and might be a memory hog.

Thanks for the help!

mattdesl commented 8 years ago

Hmm this is probably a little too simple for your needs (also the mass calculation needs to be fixed before it can be very practical - see #1).

What you are looking for is a bit more involved, having objects colliding with each other. Something like this might be useful if your spheres are equal size: https://github.com/mikolalysenko/n-body-pairs

Also this is a pretty good intro: http://gamedevelopment.tutsplus.com/tutorials/when-worlds-collide-simulating-circle-circle-collisions--gamedev-769

More advanced articles on collision detection here by Mikola Lysenko.

Also feel free to hop on the creative-dev channel, lots of people there will be able to help. https://creative-dev.herokuapp.com/

mrozbarry commented 8 years ago

Well, I'm only doing physics simulations of circles. They are rendered to the client as slightly blobby, but the collisions only need to be on perfect circles, so I think your implementation is what I'm after. The problem with n-body-pairs is all my circles will be of different sizes, unless I want to build "tires" like in the verlet-js demo, in which case I could have fixed-size mini cirlces that build a larger circle, and render the circles as a path of those smaller circles.

I'm pretty familiar with physics in general, I was just hoping I wouldn't have to re-invent the wheel, or use a library that handles the drawing for me. I'm using React and want to control the rendering manually, which is why I've avoided a lot of the other physics libraries.

I also like that verlet-point uses small js objects, so I don't have to re-iterate over it all and simplify it so there isn't a huge data load when passing physics data to the client web application.

I don't mind just doing a pull request, but I wasn't sure if it was in the scope of the project.

mattdesl commented 8 years ago

Cool. I'd be happy to merge a PR as long as it follows the same style/goals of the module. :smile:

I haven't given this module much love lately, since I've been working on other things. I can also add you as a collaborator if you'd like to help maintain it.