Damper in C#

I’m looking to simulate (pretty much exactly) what a Damper-Animation node does for my boygrouping setup. However, in this case I would like to do it in template (c#) code running on the client rather than in a patch. Does anyone know or have some c# code that would simulate this.

I was going to try to lerp between the old value and the new value but it would be nice to emulate the behavior exactly if possible. I checked VMath as well (which is great!) but no go.

Many thanks!

Take a look: https://discourse.vvvv.org/t/1683.

Thanks!.. no text …

hello, i have a c# version of the damper on my disc. it will be in VVVV.Utils.Animation in future. if you got some time…

Tonfilm, can you send me the c# code for that? Writing my own Runge-Kutta one right now but if I could use yours it would save me quite a bit of time!

Thanks for any help!

have it at home, will be there later… can you write me an email and tell me for what you need it.

Ended up just writing this myself (wasn’t too difficult). Here is it in case anyone needs it.

/// <summary>
	/// 4th order Runge-Kutta integrator
	/// </summary>                           
	public static class RK4Integrator
		public struct State
	         public double x;          // position
	         public double v;          // velocity
	    struct Derivative
	         public double dx;          // derivative of position: velocity
	         public double dv;          // derivative of velocity: acceleration
		static double Acceleration(State state, double k, double b)
	         return -k * state.x - b * state.v;
	    static Derivative Evaluate(State initial, double dt, Derivative d, double dampK, double dampB)
	         State state;
	         state.x = initial.x + d.dx*dt;
	         state.v = initial.v + d.dv*dt;
	         Derivative output = new Derivative();
	         output.dx = state.v;
	         output.dv = Acceleration(state, dampK, dampB);
	         return output;
	    public static State Integrate(State inState, double dt, double dampK, double dampB)
	         Derivative a = Evaluate(inState, 0.0, new Derivative(), dampK, dampB);
	         Derivative b = Evaluate(inState, dt*0.5, a, dampK, dampB);
	         Derivative c = Evaluate(inState, dt*0.5, b, dampK, dampB);
	         Derivative d = Evaluate(inState, dt, c, dampK, dampB);
	         double dxdt = 1.0/6.0 * (a.dx + 2.0*(b.dx + c.dx) + d.dx);
	         double dvdt = 1.0/6.0 * (a.dv + 2.0*(b.dv + c.dv) + d.dv);
	         State outState = new State();
	         outState.x = inState.x + dxdt * dt;
	         outState.v = inState.v + dvdt * dt;
	         return outState;

yes, thats the RK damping, but the vvvv Damper/Oscillator has a time input to control the damping speeds, so that the state arrives at a certain destination in that time. if you need that, the code gets a bit more complicated… or do you know of a RK implementation which does this?

Nope, not offhand. This code seems to get very similar results for me to the default Damping behavior (which was what I was looking for). If you can post/send the code that you are referring to I’m sure it would help me and the rest of the vvvv community!

yea, will commit it to the public repo on github next week… right now i am on another project till sunday.