src/integrator/src/rk4-integrator.js
function _calculateDerivative(out, state, job, t, dt, d) {
  vec3.scaleAndAdd(state.position, state.position, d.velocity, dt);
  vec3.scaleAndAdd(state.momentum, state.momentum, d.force, dt);
  _geometry.scaleAndAddQuat(state.orientation, state.orientation, d.spin, dt);
  vec3.scaleAndAdd(state.angularMomentum, state.angularMomentum, d.torque, dt);

  state.updateDependentFields();

  out.velocity = state.velocity;
  out.spin = state.spin;
  vec3.set(out.force, 0, 0, 0);
  vec3.set(out.torque, 0, 0, 0);

  _forceApplierOutput.force = out.force;
  _forceApplierOutput.torque = out.torque;
  _forceApplierInput.state = state;
  _forceApplierInput.t = t + dt;
  _forceApplierInput.dt = dt;

  job.applyForces(_forceApplierOutput, _forceApplierInput);
}
function _calculateDerivative(out, state, job, t, dt, d) {
  vec3.scaleAndAdd(state.position, state.position, d.velocity, dt);
  vec3.scaleAndAdd(state.momentum, state.momentum, d.force, dt);
  _geometry.scaleAndAddQuat(state.orientation, state.orientation, d.spin, dt);
  vec3.scaleAndAdd(state.angularMomentum, state.angularMomentum, d.torque, dt);

  state.updateDependentFields();

  out.velocity = state.velocity;
  out.spin = state.spin;
  vec3.set(out.force, 0, 0, 0);
  vec3.set(out.torque, 0, 0, 0);

  _forceApplierOutput.force = out.force;
  _forceApplierOutput.torque = out.torque;
  _forceApplierInput.state = state;
  _forceApplierInput.t = t + dt;
  _forceApplierInput.dt = dt;

  job.applyForces(_forceApplierOutput, _forceApplierInput);
}
function _calculateDerivative ( out , state , job , t , dt , d ) { vec3 . scaleAndAdd ( state . position , state . position , d . velocity , dt ) ; vec3 . scaleAndAdd ( state . momentum , state . momentum , d . force , dt ) ; _geometry . scaleAndAddQuat ( state . orientation , state . orientation , d . spin , dt ) ; vec3 . scaleAndAdd ( state . angularMomentum , state . angularMomentum , d . torque , dt ) ; state . updateDependentFields ( ) ; out . velocity = state . velocity ; out . spin = state . spin ; vec3 . set ( out . force , 0 , 0 , 0 ) ; vec3 . set ( out . torque , 0 , 0 , 0 ) ; _forceApplierOutput . force = out . force ; _forceApplierOutput . torque = out . torque ; _forceApplierInput . state = state ; _forceApplierInput . t = t + dt ; _forceApplierInput . dt = dt ; job . applyForces ( _forceApplierOutput , _forceApplierInput ) ; }
Calculate the derivative from the given state with the given time step.

@param {PhysicsDerivative} out
@param {PhysicsState} state
@param {PhysicsJob} job
@param {number} t
@param {number} dt
@param {PhysicsDerivative} d
@private
Calculate the derivative from the given state with the given time step .