feat(core): Add pitch, bearing, and cursor-position zoom to GlobeView#10207
Open
charlieforward9 wants to merge 1 commit intovisgl:masterfrom
Open
feat(core): Add pitch, bearing, and cursor-position zoom to GlobeView#10207charlieforward9 wants to merge 1 commit intovisgl:masterfrom
charlieforward9 wants to merge 1 commit intovisgl:masterfrom
Conversation
5 tasks
Draft
5 tasks
Add camera tilt (pitch) and rotation (bearing) support to GlobeView, matching Google Maps/Earth interaction model. Uses a lookAt-based view matrix that correctly composes pitch and bearing rotations while keeping the target (lat/lng) at screen center. Also makes scroll-wheel zoom target the mouse cursor position instead of always zooming to screen center (matching MapView behavior), and fixes unproject ray-sphere intersection for rays that miss the globe surface. Changes: - GlobeViewport: lookAt view matrix with pitch/bearing, cursor-anchored zoom - GlobeController: dragRotate/touchRotate, pitch/bearing constraints - GlobeView: pitch/bearing/minPitch/maxPitch view state props - Tests for pitch/bearing transitions and viewport calculations Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51f8f62 to
39baee9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds pitch (tilt) and bearing (rotation) support to
GlobeView, along with cursor-position zoom — closing the interaction gap between GlobeView and MapView / Google Earth.Before: GlobeView was locked to a top-down view. No camera tilt, no rotation, scroll-wheel zoom always targeted screen center.
After: Right-click drag tilts, two-finger rotate turns, scroll-wheel zoom follows the cursor. Existing code with
pitch=0, bearing=0(the default) produces bit-identical output.Globe.pitch.bear.zoom.mov
What changed
1. Pitch & Bearing (
GlobeViewport,GlobeView,GlobeController)The view matrix uses a
lookAt-based approach that composes four transformations:Because the Viewport base class subtracts
centerbefore applying this matrix, the target lat/lng always projects to screen center regardless of pitch/bearing — no special-casing needed.GlobeViewportpitch,bearingconstructor options; rewritten view matrix; far-plane adjustment (farZ / cos(pitch)) to prevent clipping at steep anglesGlobeViewpitch,bearing,minPitch(0),maxPitch(60) view state propsGlobeControllerdragRotate/touchRotate; pitch clamping, bearing normalization, transition interpolation for new props2. Cursor-Position Zoom (
GlobeState.zoom)GlobeState.zoom()now unprojects the cursor to get its lng/lat, computes the new zoom level, then callspanByPositionin a new anchor mode (nostartPixel) to keep that coordinate under the cursor. Falls back to center zoom when the cursor is off the globe surface.This matches the existing
MapViewscroll-zoom behavior and makes the globe feel dramatically more responsive at high zoom levels.Backward Compatibility
pitch=0, bearing=0produces identical projections to the current implementation (tested)GlobeViewAPI is additive only — no breaking changesTests
centerat screen centerbearing=90, North is left and East is up — cross-checked againstWebMercatorViewportto ensure convention matchesmaxPitch,shortestPathFrombearing wrapping through ±180pitch=0, bearing=0produces identicalpixelProjectionMatrixas omitting themDocs
globe-view.md: addedbearing,pitch,maxPitch,minPitchto view state; removed "No support for rotation" limitationglobe-controller.md: updateddragRotate/touchRotatedefaults totrueTest Plan
yarn test node— all viewport, view-state, and controller tests passtest/apps/globe— interactive demo withpitch: 30, right-click drag to rotate, scroll to zoom toward cursor