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

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

const DEGREES_TO_RADIANS = Math.PI / 180;

export default class PerspectiveView extends View {
  _getViewport(props) {
    const x = props.x,
          y = props.y,
          width = props.width,
          height = props.height,
          viewState = props.viewState;
    const eye = viewState.eye;
    var _viewState$lookAt = viewState.lookAt;
    const lookAt = _viewState$lookAt === undefined ? [0, 0, 0] : _viewState$lookAt;
    var _viewState$up = viewState.up;
    const up = _viewState$up === undefined ? [0, 1, 0] : _viewState$up;
    var _viewState$fovy = viewState.fovy;
    const fovy = _viewState$fovy === undefined ? 75 : _viewState$fovy;
    var _viewState$near = viewState.near;
    const near = _viewState$near === undefined ? 1 : _viewState$near;
    var _viewState$far = viewState.far;
    const far = _viewState$far === undefined ? 100 : _viewState$far;
    var _viewState$aspect = viewState.aspect;
    let aspect = _viewState$aspect === undefined ? null : _viewState$aspect;


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

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