Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle fill field of view correctly #631

Merged
merged 1 commit into from
Feb 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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