DynamicSolver
public struct DynamicSolver<F: DynamicFunctionType> : Advanceable
DynamicSolver
simulates changes to a value over time, based on
a function that calculates acceleration after each time step.
The RK4 method is used to integrate the acceleration function.
Constant time steps are not guarenteed elsewhere in the framework. Due to
the nature of dynamic functions, however, it is desirable to maintain
a constant update interval for a dynamic simulation. DynamicSolver
instances maintain their own internal time state. When `advance(elapsed:)
is called on an instance, it may run an arbitrary number of time steps
internally (and call the underlying function as needed) in order to catch
up
to the outside time. It then uses linear interpolation to match the
internal state to the required external time in order to return the most
precise calculations.
-
The function driving the simulation.
Declaration
Swift
public var function: F
-
Returns
true
if the solver has settled and does not currently need to be advanced on each frame.Declaration
Swift
fileprivate (set) public var settled: Bool = false
-
Creates a new
DynamicSolver
instance.Declaration
Swift
public init(function: F, value: F.Vector, velocity: F.Vector = F.Vector.zero)
Parameters
function
The function that will drive the simulation.
value
The initial value of the simulation.
velocity
The initial velocity of the simulation.
-
Advances the simulation.
Declaration
Swift
public mutating func advance(_ elapsed: Double)
Parameters
elapsed
The duration by which to advance the simulation in seconds.
-
The current value.
Declaration
Swift
public var value: F.Vector
-
The current velocity.
Declaration
Swift
public var velocity: F.Vector