Skip to content

Commit

Permalink
fix: handle fill fov correctly
Browse files Browse the repository at this point in the history
Take aspect and horizontal fov into account.
  • Loading branch information
oscarlorentzon committed Feb 4, 2025
1 parent 93c0a0d commit 3850dff
Showing 1 changed file with 35 additions and 15 deletions.
50 changes: 35 additions & 15 deletions src/render/RenderCamera.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ export class RenderCamera {

private _state: State;

private _currentBearings: number[][];
private _previousBearings: number[][];
private _currentBearings: {x: number[][], y: number[][]};
private _previousBearings: {x: number[][], y: number[][]};

private _currentFov: number;
private _previousFov: number;
Expand Down Expand Up @@ -92,8 +92,8 @@ export class RenderCamera {

this._state = null;

this._currentBearings = [];
this._previousBearings = [];
this._currentBearings = {x: [], y: []};
this._previousBearings = {x: [], y: []};

this._currentFov = this._initialFov;
this._previousFov = this._initialFov;
Expand Down Expand Up @@ -393,17 +393,30 @@ export class RenderCamera {
this.perspective.aspect);
}

private _computeBearings(transform: Transform): number[][] {
const vertices = [[0, 0]];
const directions = [[1, 0]];
const pointsPerLine = 25;
private _computeBearings(transform: Transform): {x: number[][], y: number[][]} {
const yVertices = [[0, 0]];
const yDirections = [[1, 0]];
const yPointsPerLine = 25;

return Geo.computeBearings(
const y = Geo.computeBearings(
transform,
vertices,
directions,
pointsPerLine,
yVertices,
yDirections,
yPointsPerLine,
this._viewportCoords);

const xVertices = [[0, 0]];
const xDirections = [[0, 1]];
const xPointsPerLine = 25;

const x = Geo.computeBearings(
transform,
xVertices,
xDirections,
xPointsPerLine,
this._viewportCoords);

return {x: x, y: y};
}

private _computeRotation(camera: Camera): EulerRotation {
Expand All @@ -417,18 +430,25 @@ export class RenderCamera {
}

private _computeVerticalBearingFov(
bearings: number[][],
bearings: {x: number[][], y: number[][]},
renderMode: RenderMode,
zoom: number,
aspect: number): number {

const {_spatial} = this;

const projections = bearings
const yProjections = bearings.y
.map(b => _spatial.projectToPlane(b, [1, 0, 0]))
.map(p => [p[1], -p[2]]);

const fovs = projections.map(p => 2 * _spatial.radToDeg(Math.abs(Math.atan2(p[0], p[1]))));
const xProjections = bearings.x
.map(b => _spatial.projectToPlane(b, [0, 1, 0]))
.map(p => [p[0], -p[2]]);

const yFovs = yProjections.map(p => 2 * _spatial.radToDeg(Math.abs(Math.atan2(p[0], p[1]))));
const xFovs = xProjections.map(p => 2 * _spatial.radToDeg(Math.abs(Math.atan2(p[0] / aspect, p[1]))));
const fovs = [...yFovs, ...xFovs];

const vFovMin = fovs.length > 0 ? 0.995 * Math.min(...fovs) : 125;
const fovMin = this._fovToZoomedFov(vFovMin, zoom);
const fovMax = this._fovToZoomedFov(125, zoom);
Expand Down

0 comments on commit 3850dff

Please sign in to comment.