{"size": 968, "ext": "js", "max_stars_repo_path": "src/camera-track.js", "max_stars_repo_name": "GeneralGrifon/TEST", "max_stars_repo_stars_event_min_datetime": "2021-03-17T22:24:52.000Z", "max_stars_repo_stars_event_max_datetime": "2021-03-17T22:24:52.000Z", "max_issues_repo_path": "src/camera-track.js", "max_issues_repo_name": "GeneralGrifon/TEST", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/camera-track.js", "max_forks_repo_name": "GeneralGrifon/TEST", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.2, "max_line_length": 91, "alphanum_fraction": 0.5743801653}
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.112.1/build/three.module.js';

import {spline} from './spline.js';


export const camera_track = (function() {

  class _CameraTrack {
    constructor(params) {
      this._params = params;
      this._currentTime = 0.0;
      
      const lerp = (t, p1, p2) => {
        const p = new THREE.Vector3().lerpVectors(p1.pos, p2.pos, t);
        const q = p1.rot.clone().slerp(p2.rot, t);

        return {pos: p, rot: q};
      };
      this._spline = new spline.LinearSpline(lerp);

      for (let p of params.points) {
        this._spline.AddPoint(p.time, p.data);
      }
    }

    Update(timeInSeconds) {
      this._currentTime += timeInSeconds;

      const r = this._spline.Get(this._currentTime);

      this._params.camera.position.copy(r.pos);
      this._params.camera.quaternion.copy(r.rot);
    }
  };

  return {
    CameraTrack: _CameraTrack,
  };
})();
