Physics RK4 001

Over here http://gafferongames.com/game-physics/integration-basics/

someone shows how to implement physics simulations using an RK4 integrator

and here’s my implementation of his c++ source as a Daz Script

1 - create a cylinder, 30cm tall 1 cm diameter

2 - select the cylinder

3 - run the script

the Z rotation angle of the selected cylinder will be driven by the simulated output ( x )

the line that reads “if( (cpt++) > 200 ) break;” is a safety device limiting the simulation to 200 frames

cpt also serves as the keyframe time

you may want to replace

zRot.setValue( cpt * tick, state[0] );

by

zRot.setValue( t * 4800, state[0] );

g_k is the Hooke’s law spring constant, g_b is the dampening factor

and here is HTML5 applet to display the curve and motion