mpetroff / pannellum

Pannellum is a lightweight, free, and open source panorama viewer for the web.
https://pannellum.org/
MIT License
4.23k stars 721 forks source link

Mouse click to cube coordinates #1213

Open StephenWitherden opened 5 months ago

StephenWitherden commented 5 months ago

Hi, there, thank you for this awesome library.

I am working to include a depth map for measurement purposes. Effectively, what I want to implement is your suggestion in #1128 but using a cube map rather than the equirectangular image. I am also aware that getting from mouse coordinates to equirectangular coordinates is trivial as you say in #765.

Should I just go the equirectangular route, or is there a nice neat algorithm I could use to map a mouse click to coordinates on a multidimensional cube map? I am preferring cubes because of performance on large panoramas.

mpetroff commented 5 months ago

This Stack Exchange answer describes how to go from latitude / longitude to cube face coordinates (in C#, but it's straightforward to convert to JavaScript): https://gamedev.stackexchange.com/a/137303

The pitch / yaw returned by mouseEventToCoords is equivalent to latitude / longitude. It might take some trial and error to get the face mapping and coordinate signs correct, but that should get you started.