### Re: Physics Patch-a-Day Thread – Join the fun!!!

Forums > Jitter > Physics Patch-a-Day Thread – Join the fun!!!
Sep 24 2012 | 11:13 pm

as fun and easy as jit.phys.ghost is, it’s not the only way to apply forces to multiple rigid-bodies. there is also the jit.phys.multiple force matrix.
one of the benefits to using jit.phys.multiple is that since it takes matrices, we can use all the great matrix tools jitter has to offer to generate those matrices.

for today’s patch, i wanted to demonstrate how we can use jit.phys.multiple with jit.path and jit.gen, to simulate bodies in a vortex or tornado.
disclaimer: in no way is this simulation intended to be scientifically accurate.

so what kind of forces are involved in this?
well, first a tornado has a long spiral shape, and objects are pulled along the shape of the spiral. and second objects are sucked upward into the spiral shape.

to create a spiral, the patch uses jit.expr and jit.path. i simply copied the jit.expr from the jit.gl.path help-file, and slightly modified the expr. i then used the "outputeval" message to jit.path to send a matrix containing the path points to a jit.gen.

the jit.gen simply takes the path matrix, and the phys.multiple position matrix, and tries to find the closest point on the path to each body. a jit.gen attribute @steps will determine how many path-points are iterated to find the closest. the more steps, the more cpu is consumed. once the closest point is found, a tangent is calculated by subtracting the previous path point from the current. this tangent will pull bodies along the path, so in order to pull bodies toward the path, we mix the tangent with the distance from the body position to the path point (adjusted by the jit.gen @fade attribute).

that’s it! the force matrix is then sent to phys.multiple to apply the forces to each of the bodies. we also send the force matrix to gl.multiple color matrix, mainly for debugging. there is also a jit.phys.ghost that can be enabled to add more forces to the equation.

the real fun happens when you interpolate between presets, so a pattrstorage is provided to get you started with that.

[attachment=204485,4441]