Finally I got a humble result. The idea is simple, to program a group of methods fro solving long range interactions as electric, magnetic, and gravitational forces between the body in Chipmunk.
I did it but there are still somethings to polish a bit more.
- At the moment the loop for calculating the net force over each body implies a loop over all other N-1 bodies. The idea is to use the action reaction principle to go only over N*N/2 elements.
- The radio of interaction covers all the space. It would be nice to define an effective range. Maybe one can use cpShape for this...or just a simple filter with cpArray methods.
- I have problems with interprenetration and i can not get intuition on how to fill the size of the spatial hashes...help!!
Ok, I hope you find this interesting.
To achieve this I added two fields to the cpBody structure, two methods on cpSpace and modified cpSpaceStep to calculate the force before updating the velocity. Do you have a better idea? please tell me.
P.S.: I am adding a kind of thermal noise to the bodies, that is why they move kind of randomly. Also there is noise in the angular speed...equipartition of the energy, uh. But this feature is not well implemented yet, Iam working on it.