'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _viewport = require('./viewport');

var _viewport2 = _interopRequireDefault(_viewport);

var _log = require('../utils/log');

var _log2 = _interopRequireDefault(_log);

var _math = require('math.gl');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } // Copyright (c) 2015 - 2017 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

var SphericalCoordinates = _math.experimental.SphericalCoordinates;


function getDirectionFromBearingAndPitch(_ref) {
  var bearing = _ref.bearing,
      pitch = _ref.pitch;

  var spherical = new SphericalCoordinates({ bearing: bearing, pitch: pitch });
  return spherical.toVector3().normalize();
}

var ThirdPersonViewport = function (_Viewport) {
  _inherits(ThirdPersonViewport, _Viewport);

  function ThirdPersonViewport(opts) {
    _classCallCheck(this, ThirdPersonViewport);

    _log2.default.deprecated('ThirdPersonViewport', 'ThirdPersonView')();

    var bearing = opts.bearing,
        pitch = opts.pitch,
        position = opts.position,
        up = opts.up,
        zoom = opts.zoom;


    var direction = getDirectionFromBearingAndPitch({
      bearing: bearing,
      pitch: pitch
    });

    var distance = zoom * 50;

    // TODO somehow need to flip z to make it work
    // check if the position offset is done in the base viewport
    var eye = direction.scale(-distance).multiply(new _math.Vector3(1, 1, -1));

    var viewMatrix = new _math.Matrix4().multiplyRight(new _math.Matrix4().lookAt({ eye: eye, center: position, up: up }));

    return _possibleConstructorReturn(this, (ThirdPersonViewport.__proto__ || Object.getPrototypeOf(ThirdPersonViewport)).call(this, Object.assign({}, opts, {
      // use meter level
      zoom: null,
      viewMatrix: viewMatrix
    })));
  }

  return ThirdPersonViewport;
}(_viewport2.default);

exports.default = ThirdPersonViewport;
//# sourceMappingURL=third-person-viewport.js.map