Source code

Revision control

Other Tools

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/. */
6
7
#ifndef mozilla_layers_AxisPhysicsMSDModel_h
8
#define mozilla_layers_AxisPhysicsMSDModel_h
9
10
#include "AxisPhysicsModel.h"
11
12
namespace mozilla {
13
namespace layers {
14
15
/**
16
* AxisPhysicsMSDModel encapsulates a 1-dimensional MSD (Mass-Spring-Damper)
17
* model. A unit mass is assumed.
18
*/
19
class AxisPhysicsMSDModel : public AxisPhysicsModel {
20
public:
21
AxisPhysicsMSDModel(double aInitialPosition, double aInitialDestination,
22
double aInitialVelocity, double aSpringConstant,
23
double aDampingRatio);
24
25
virtual ~AxisPhysicsMSDModel();
26
27
/**
28
* Gets the raw destination of this axis at this moment.
29
*/
30
double GetDestination() const;
31
32
/**
33
* Sets the raw destination of this axis at this moment.
34
*/
35
void SetDestination(double aDestination);
36
37
/**
38
* Returns true when the position is close to the destination and the
39
* velocity is low.
40
*/
41
bool IsFinished(double aSmallestVisibleIncrement);
42
43
protected:
44
double Acceleration(const State& aState) override;
45
46
private:
47
/**
48
* mDestination represents the target position and the resting position of
49
* the simulated spring.
50
*/
51
double mDestination;
52
53
/**
54
* Greater values of mSpringConstant result in a stiffer / stronger spring.
55
*/
56
double mSpringConstant;
57
58
/**
59
* mSpringConstantSqrtTimesTwo is calculated from mSpringConstant to reduce
60
* calculations performed in the inner loop.
61
*/
62
double mSpringConstantSqrtXTwo;
63
64
/**
66
*
67
* When mDampingRatio < 1.0, this is an under damped system.
68
* - Overshoots destination and oscillates with the amplitude gradually
69
* decreasing to zero.
70
*
71
* When mDampingRatio == 1.0, this is a critically damped system.
72
* - Reaches destination as quickly as possible without oscillating.
73
*
74
* When mDampingRatio > 1.0, this is an over damped system.
75
* - Reaches destination (exponentially decays) without oscillating.
76
*/
77
double mDampingRatio;
78
};
79
80
} // namespace layers
81
} // namespace mozilla
82
83
#endif