1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_layers_AxisPhysicsMSDModel_h
8 #define mozilla_layers_AxisPhysicsMSDModel_h
10 #include "AxisPhysicsModel.h"
16 * AxisPhysicsMSDModel encapsulates a 1-dimensional MSD (Mass-Spring-Damper)
17 * model. A unit mass is assumed.
19 class AxisPhysicsMSDModel
: public AxisPhysicsModel
{
21 AxisPhysicsMSDModel(double aInitialPosition
, double aInitialDestination
,
22 double aInitialVelocity
, double aSpringConstant
,
23 double aDampingRatio
);
25 virtual ~AxisPhysicsMSDModel();
28 * Gets the raw destination of this axis at this moment.
30 double GetDestination() const;
33 * Sets the raw destination of this axis at this moment.
35 void SetDestination(double aDestination
);
38 * Returns true when the position is close to the destination and the
41 bool IsFinished(double aSmallestVisibleIncrement
) const;
44 double Acceleration(const State
& aState
) override
;
48 * mDestination represents the target position and the resting position of
49 * the simulated spring.
54 * Greater values of mSpringConstant result in a stiffer / stronger spring.
56 double mSpringConstant
;
59 * mSpringConstantSqrtTimesTwo is calculated from mSpringConstant to reduce
60 * calculations performed in the inner loop.
62 double mSpringConstantSqrtXTwo
;
65 * Damping Ratio: http://en.wikipedia.org/wiki/Damping_ratio
67 * When mDampingRatio < 1.0, this is an under damped system.
68 * - Overshoots destination and oscillates with the amplitude gradually
71 * When mDampingRatio == 1.0, this is a critically damped system.
72 * - Reaches destination as quickly as possible without oscillating.
74 * When mDampingRatio > 1.0, this is an over damped system.
75 * - Reaches destination (exponentially decays) without oscillating.
81 } // namespace mozilla