var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

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; }

import View from './view';
import Viewport from '../viewports/viewport';

import mat4_lookAt from 'gl-mat4/lookAt';
import mat4_perspective from 'gl-mat4/perspective';

var DEGREES_TO_RADIANS = Math.PI / 180;

var PerspectiveView = function (_View) {
  _inherits(PerspectiveView, _View);

  function PerspectiveView() {
    _classCallCheck(this, PerspectiveView);

    return _possibleConstructorReturn(this, (PerspectiveView.__proto__ || Object.getPrototypeOf(PerspectiveView)).apply(this, arguments));
  }

  _createClass(PerspectiveView, [{
    key: '_getViewport',
    value: function _getViewport(props) {
      var x = props.x,
          y = props.y,
          width = props.width,
          height = props.height,
          viewState = props.viewState;
      var eye = viewState.eye,
          _viewState$lookAt = viewState.lookAt,
          lookAt = _viewState$lookAt === undefined ? [0, 0, 0] : _viewState$lookAt,
          _viewState$up = viewState.up,
          up = _viewState$up === undefined ? [0, 1, 0] : _viewState$up,
          _viewState$fovy = viewState.fovy,
          fovy = _viewState$fovy === undefined ? 75 : _viewState$fovy,
          _viewState$near = viewState.near,
          near = _viewState$near === undefined ? 1 : _viewState$near,
          _viewState$far = viewState.far,
          far = _viewState$far === undefined ? 100 : _viewState$far;
      var _viewState$aspect = viewState.aspect,
          aspect = _viewState$aspect === undefined ? null : _viewState$aspect;


      var fovyRadians = fovy * DEGREES_TO_RADIANS;
      aspect = Number.isFinite(aspect) ? aspect : width / height;
      return new Viewport({
        x: x,
        y: y,
        width: width,
        height: height,
        viewMatrix: mat4_lookAt([], eye, lookAt, up),
        projectionMatrix: mat4_perspective([], fovyRadians, aspect, near, far)
      });
    }
  }]);

  return PerspectiveView;
}(View);

export default PerspectiveView;


PerspectiveView.displayName = 'PerspectiveView';
//# sourceMappingURL=perspective-view.js.map