import View from './view';
import Viewport from '../viewports/viewport';
import { Vector3, Matrix4, experimental } from 'math.gl';
const SphericalCoordinates = experimental.SphericalCoordinates;


function getDirectionFromBearingAndPitch({ bearing, pitch }) {
  const spherical = new SphericalCoordinates({ bearing, pitch });
  return spherical.toVector3().normalize();
}

export default class ThirdPersonView extends View {
  _getViewport(props) {
    var _props$viewState = props.viewState;
    const bearing = _props$viewState.bearing,
          pitch = _props$viewState.pitch,
          position = _props$viewState.position,
          up = _props$viewState.up,
          zoom = _props$viewState.zoom;


    const direction = getDirectionFromBearingAndPitch({
      bearing,
      pitch
    });

    const distance = zoom * 50;

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

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

    return new Viewport(Object.assign({}, props, {
      zoom: null, // triggers meter level zoom
      viewMatrix
    }));
  }
}

ThirdPersonView.displayName = 'ThirdPersonView';
//# sourceMappingURL=third-person-view.js.map