PhysicsSystem
public class PhysicsSystem : PhysicsSolving
A simple physics engine used with PhysicsMotion
and PathPhysicsMotion
to calculate values for motions. It primarily uses a constant velocity
, plus a friction
component, to update movements of values over time. As of version 2.2.0 it also supports simple collision handling between two optional fixed start and end points, and a restitution
value to control the value’s elasticity when colliding.
-
The velocity value to use in physics calculations.
Declaration
Swift
public var velocity: Double { get set }
-
The friction value between 0.0 and 1.0, to be applied in physics calculations. Provided values outside of that range are clamped to the closest minimum or maximum value. A friction value of 0.0 is actually set internally to slightly above that in order to avoid divide by zero errors.
Declaration
Swift
public var friction: Double { get set }
-
The restitution value from 0.0 to 1.0 which represents the elasticity of the object and used in collision calculations, with 0.0 representing a perfectly inelastic collision (in which the object does not rebound at all during a collision), and 1.0 representing a perfectly elastic collision (in which the object rebounds with no loss of velocity). Provided values outside of that range are clamped to the closest minimum or maximum value. The default value is 0.75.
Declaration
Swift
public var restitution: Double { get set }
-
This Boolean represents whether collision detections are active in the physics simulation. If
true
, collisions will be checked using thestart
andend
properties of eachPropertyData
object passed in to thesolve(forPositions:timestamp:)
method. The default value isfalse
.Declaration
Swift
public var useCollisionDetection: Bool
-
The last timestamp sent via the
solve
method.Declaration
Swift
public internal(set) var lastTimestamp: TimeInterval { get }
-
Boolean value representing whether the physics system is currently paused.
Declaration
Swift
public internal(set) var paused: Bool { get }
-
A convenience initializer.
Declaration
Swift
public convenience init(configuration: PhysicsConfiguration)
Parameters
configuration
A configuration model containing data to set up the system to provide physics calculations.
-
Initializer.
Declaration
Swift
public init(velocity: Double, friction: Double, restitution: Double? = nil, useCollisionDetection: Bool? = nil)
Parameters
velocity
The velocity used to calculate new values in physics system. Any values are accepted due to the differing ranges of velocity magnitude required for various motion applications. Experiment to see what suits your needs best.
friction
The friction used to calculate new values in the physics system. Acceptable values are 0.0 (almost no friction) to 1.0 (no movement); values outside of this range will be clamped to the nearest edge.
restitution
The restitution value from 0.0 to 1.0 which represents the elasticity of the object and used in collision calculations, with 0.0 representing a perfectly inelastic collision (in which the object does not rebound at all during a collision), and 1.0 representing a perfectly elastic collision (in which the object rebounds with no loss of velocity).
useCollisionDetection
Determines whether collision detections are checked and acted on with the object being moved. The default value is
false
.
-
Declaration
Swift
public func solve(forPositions positions: [PropertyData], timestamp: TimeInterval) -> [Double]
-
Declaration
Swift
public func reset()
-
Declaration
Swift
public func pause()
-
Declaration
Swift
public func resume()
-
Declaration
Swift
public func reverseDirection()