"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _viewport = _interopRequireDefault(require("../viewports/viewport"));

var _webMercator = require("@math.gl/web-mercator");

var _core = require("@math.gl/core");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var FirstPersonViewport = function (_Viewport) {
  (0, _inherits2.default)(FirstPersonViewport, _Viewport);

  var _super = _createSuper(FirstPersonViewport);

  function FirstPersonViewport(props) {
    var _this;

    (0, _classCallCheck2.default)(this, FirstPersonViewport);
    var longitude = props.longitude,
        latitude = props.latitude,
        modelMatrix = props.modelMatrix,
        _props$bearing = props.bearing,
        bearing = _props$bearing === void 0 ? 0 : _props$bearing,
        _props$pitch = props.pitch,
        pitch = _props$pitch === void 0 ? 0 : _props$pitch,
        _props$up = props.up,
        up = _props$up === void 0 ? [0, 0, 1] : _props$up;
    var spherical = new _core._SphericalCoordinates({
      bearing: bearing,
      pitch: pitch === -90 ? 0.0001 : 90 + pitch
    });
    var dir = spherical.toVector3().normalize();
    var center = modelMatrix ? new _core.Matrix4(modelMatrix).transformAsVector(dir) : dir;
    var zoom = Number.isFinite(latitude) ? (0, _webMercator.getMeterZoom)({
      latitude: latitude
    }) : 0;
    var scale = Math.pow(2, zoom);
    var viewMatrix = new _core.Matrix4().lookAt({
      eye: [0, 0, 0],
      center: center,
      up: up
    }).scale(scale);
    _this = _super.call(this, _objectSpread(_objectSpread({}, props), {}, {
      zoom: zoom,
      viewMatrix: viewMatrix
    }));
    _this.longitude = void 0;
    _this.latitude = void 0;
    _this.latitude = latitude;
    _this.longitude = longitude;
    return _this;
  }

  return FirstPersonViewport;
}(_viewport.default);

exports.default = FirstPersonViewport;
//# sourceMappingURL=first-person-viewport.js.map