mpetroff / pannellum

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

Converting the viewer rotation coordinates to three.js camera vectors #1114

Closed fareed945 closed 1 year ago

fareed945 commented 1 year ago

Hey, thanks a ton for this amazing light weight library !! I'm kind of confused as to how to convert these pitch, yaw to the three.js camera target vectors . Anyone can help on this ? Basically, i'm synchronizing pannellum with another third party 3d rendering library, that uses three.js

mpetroff commented 1 year ago

The pitch and yaw are Euler angles, with a YXZ order. Pitch is X, yaw is Y, and roll is Z. You might need to add in a minus sign or two or add or subtract pi to get things to match up with three.js.

fareed945 commented 1 year ago

Thanks, i'll try this out and confirm

fareed945 commented 1 year ago

hey @mpetroff i'm struggling to get them in-line, few clarifications 1) The order of rotation is YXZ where-in y is yaw , x is pitch and Z is roll. Correct ? 2) Should roll be set to Zero?

mpetroff commented 1 year ago
  1. That's correct.
  2. The roll is normally zero, but it's non-zero when device orientation mode is in use.
mpetroff commented 1 year ago

In case it's helpful, here's a snippet showing how to go the opposite direction, to synchronize Pannellum to a three.js camera:

var quat = new THREE.Quaternion();
var euler = new THREE.Euler(0, 0, 0, 'YXZ');
camera.getWorldQuaternion(quat);    // THREE.PerspectiveCamera
euler.setFromQuaternion(quat, 'YXZ');
var pitch = -euler.x;
var yaw = Math.PI + euler.y;
var roll = euler.z - Math.PI;