/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include"AxisPhysicsModel.h"
namespace mozilla { namespace layers {
/** * The simulation is advanced forward in time with a fixed time step to ensure * that it remains deterministic given variable framerates. To determine the * position at any variable time, two samples are interpolated. * * kFixedtimestep is set to 120hz in order to ensure that every frame in a * common 60hz refresh rate display will have at least one physics simulation * sample. More accuracy can be obtained by reducing kFixedTimestep to smaller * intervals, such as 240hz or 1000hz, at the cost of more CPU cycles. If * kFixedTimestep is increased to much longer intervals, interpolation will * become less effective at reducing temporal jitter and the simulation will * lose accuracy.
*/ constdouble AxisPhysicsModel::kFixedTimestep = 1.0 / 120.0; // 120hz
/** * Constructs an AxisPhysicsModel with initial values for state. * * @param aInitialPosition sets the initial position of the simulation, * in AppUnits. * @param aInitialVelocity sets the initial velocity of the simulation, * in AppUnits / second.
*/
AxisPhysicsModel::AxisPhysicsModel(double aInitialPosition, double aInitialVelocity)
: mProgress(1.0),
mPrevState(aInitialPosition, aInitialVelocity),
mNextState(aInitialPosition, aInitialVelocity) {}