I've been struggling to grasp the concepts of quaternions for quite some time now, and I suspect they may be the root cause of my current challenge.
If you're familiar with three.js, you might know about the equirectangular panorama video example. My goal has been to extract the camera's rotation at any given moment in a format that makes sense to me (radians, degrees...), for each axis. In theory, shouldn't I be able to simply access the camera's rotation.x/y/z parameters to achieve this? However, I'm consistently receiving unexpected values.
Take a look at this example:
In the upper left corner, I display the camera's xyz rotation values, but instead of the anticipated values, I observe them fluctuating between positive and negative numbers.
This particular example does not utilize one of the available control scripts. Instead, it creates a vector to calculate a camera target to focus on. Here is what the camera code looks like:
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
camera.target = new THREE.Vector3( 0, 0, 0 );
}
function onDocumentMouseDown( event ) {
event.preventDefault();
isUserInteracting = true;
onPointerDownPointerX = event.clientX;
onPointerDownPointerY = event.clientY;
onPointerDownLon = lon;
onPointerDownLat = lat;
}
function onDocumentMouseMove( event ) {
if ( isUserInteracting === true ) {
lon = ( onPointerDownPointerX - event.clientX ) * 0.1 + onPointerDownLon;
lat = ( event.clientY - onPointerDownPointerY ) * 0.1 + onPointerDownLat;
}
}
function onDocumentMouseUp( event ) {
isUserInteracting = false;
}
function update() {
lat = Math.max( - 85, Math.min( 85, lat ) );
phi = THREE.Math.degToRad( 90 - lat );
theta = THREE.Math.degToRad( lon );
camera.target.x = 500 * Math.sin( phi ) * Math.cos( theta );
camera.target.y = 500 * Math.cos( phi );
camera.target.z = 500 * Math.sin( phi ) * Math.sin( theta );
camera.lookAt( camera.target );
}
Could someone shed light on why I'm receiving these erratic values, and offer guidance on how I can accurately extract rotation data for use on another object to replicate the movement?