Skip to content

Commit

Permalink
Provide a way to override the easing function in Scene#lookTo.
Browse files Browse the repository at this point in the history
Fixes #242.
  • Loading branch information
jordyno authored and tjgq committed Jul 8, 2019
1 parent 1f0a5b2 commit 0da2862
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/Scene.js
Expand Up @@ -255,6 +255,7 @@ Scene.prototype.switchTo = function(opts, done) {
*
* @param {Object} params Target view parameters.
* @param {Object} opts Transition options.
* @param {function} [opts.ease=easeInOutQuad] Tween easing function
* @param {number} [opts.controlsInterrupt=false] allow controls to interrupt
* an ongoing tween.
* @param {number} [opts.transitionDuration=1000] Tween duration, in
Expand All @@ -267,14 +268,22 @@ Scene.prototype.switchTo = function(opts, done) {
* interrupted.
*/
Scene.prototype.lookTo = function(params, opts, done) {
// TODO: provide a way to override the easing function.
opts = opts || {};
done = done || noop;

if (type(params) !== 'object') {
throw new Error("Target view parameters must be an object");
}

// Quadratic in/out easing.
var easeInOutQuad = function (k) {
if ((k *= 2) < 1) {
return 0.5 * k * k;
}
return -0.5 * (--k * (k - 2) - 1);
};

var ease = opts.ease != null ? opts.ease : easeInOutQuad;
var controlsInterrupt = opts.controlsInterrupt != null ? opts.controlsInterrupt : false;
var duration = opts.transitionDuration != null ? opts.transitionDuration : 1000;
var shortest = opts.shortest != null ? opts.shortest : true;
Expand All @@ -293,14 +302,6 @@ Scene.prototype.lookTo = function(params, opts, done) {
view.normalizeToClosest(finalParams, finalParams);
}

// Quadratic in/out easing.
var ease = function (k) {
if ((k *= 2) < 1) {
return 0.5 * k * k;
}
return -0.5 * (--k * (k - 2) - 1);
};

var movement = function() {

var finalUpdate = false;
Expand Down

0 comments on commit 0da2862

Please sign in to comment.