Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
14 changes: 8 additions & 6 deletions src/geo/projection/globe_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {lerp} from '../../util/util';
import type {OverscaledTileID, UnwrappedTileID, CanonicalTileID} from '../../source/tile_id';

import type Point from '@mapbox/point-geometry';
import {mercatorZfromAltitude} from '../mercator_coordinate';
import type {MercatorCoordinate} from '../mercator_coordinate';
import type {LngLatBounds} from '../lng_lat_bounds';
import type {Frustum} from '../../util/primitives/frustum';
Expand Down Expand Up @@ -209,14 +210,14 @@ export class GlobeTransform implements ITransform {
get constrain(): TransformConstrainFunction {
return this._helper.constrain;
}
public get nearZ(): number {
return this._helper.nearZ;
public get nearZ(): number {
return this._helper.nearZ;
}
public get farZ(): number {
return this._helper.farZ;
public get farZ(): number {
return this._helper.farZ;
}
public get autoCalculateNearFarZ(): boolean {
return this._helper.autoCalculateNearFarZ;
public get autoCalculateNearFarZ(): boolean {
return this._helper.autoCalculateNearFarZ;
}
//
// Implementation of globe transform
Expand Down Expand Up @@ -344,6 +345,7 @@ export class GlobeTransform implements ITransform {
this._mercatorTransform.apply(this, true, this.isGlobeRendering);
this._helper._nearZ = this._mercatorTransform.nearZ;
this._helper._farZ = this._mercatorTransform.farZ;
this._helper._pixelPerMeter = mercatorZfromAltitude(1, this.center.lat) * this.worldSize;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Globe transform should mostly be a wrapper around mercator and vertical presense.
So I would expect this call to be something like:
this._helper._pixelPerMeter = this.currentTransform.pixelPerMeter
Or something similar, can you please check if this is possible?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to think that placing this logic inside the calcMatrices of the helper will solve this issue as the code is the same for both vertical perspective and mercator transforms.
I'm guessing this it's also the right place since the helper is "responsible" for this variable and should update it as needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the calculation to the TransformHelper as you suggested.

There is a slight functional difference with my change: MercatorTransform used to recalculate this._helper._pixelPerMeter when this.helper._width is possibly nullable (or 0), but now it is only re-calculated when both _width and _height are defined.

}

calculateFogMatrix(unwrappedTileID: UnwrappedTileID): mat4 {
Expand Down
16 changes: 9 additions & 7 deletions src/geo/projection/vertical_perspective_transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {LngLat, type LngLatLike, earthRadius} from '../lng_lat';
import {angleToRotateBetweenVectors2D, clamp, createIdentityMat4f32, createIdentityMat4f64, createMat4f64, createVec3f64, createVec4f64, differenceOfAnglesDegrees, distanceOfAnglesRadians, MAX_VALID_LATITUDE, pointPlaneSignedDistance, warnOnce} from '../../util/util';
import {OverscaledTileID, UnwrappedTileID, type CanonicalTileID} from '../../source/tile_id';
import Point from '@mapbox/point-geometry';
import {MercatorCoordinate} from '../mercator_coordinate';
import {mercatorZfromAltitude, MercatorCoordinate} from '../mercator_coordinate';
import {LngLatBounds} from '../lng_lat_bounds';
import {tileCoordinatesToMercatorCoordinates} from './mercator_utils';
import {angularCoordinatesToSurfaceVector, clampToSphere, getGlobeRadiusPixels, getZoomAdjustment, horizonPlaneToCenterAndRadius, mercatorCoordinatesToAngularCoordinatesRadians, projectTileCoordinatesToSphere, sphereSurfacePointToCoordinates} from './globe_utils';
Expand Down Expand Up @@ -225,14 +225,14 @@ export class VerticalPerspectiveTransform implements ITransform {
get constrain(): TransformConstrainFunction {
return this._helper.constrain;
}
public get nearZ(): number {
return this._helper.nearZ;
public get nearZ(): number {
return this._helper.nearZ;
}
public get farZ(): number {
return this._helper.farZ;
public get farZ(): number {
return this._helper.farZ;
}
public get autoCalculateNearFarZ(): boolean {
return this._helper.autoCalculateNearFarZ;
public get autoCalculateNearFarZ(): boolean {
return this._helper.autoCalculateNearFarZ;
}
setTransitionState(_value: number): void {
// Do nothing
Expand Down Expand Up @@ -507,6 +507,8 @@ export class VerticalPerspectiveTransform implements ITransform {
const matrix = mat4.clone(this._globeViewProjMatrixNoCorrectionInverted);
mat4.scale(matrix, matrix, [1, 1, -1]);
this._cachedFrustum = Frustum.fromInvProjectionMatrix(matrix, 1, 0, this._cachedClippingPlane, true);

this._helper._pixelPerMeter = mercatorZfromAltitude(1, this.center.lat) * this.worldSize;
}

calculateFogMatrix(_unwrappedTileID: UnwrappedTileID): mat4 {
Expand Down
Loading