Selaa lähdekoodia

Created separate function for calculating panorama coordinates of mouse event.

tags/2.2.0
Matthew Petroff 8 vuotta sitten
vanhempi
commit
523ffefd43
1 muutettua tiedostoa jossa 34 lisäystä ja 11 poistoa
  1. +34
    -11
      src/js/pannellum.js

+ 34
- 11
src/js/pannellum.js Näytä tiedosto

@@ -545,17 +545,8 @@ function onDocumentMouseDown(event) {

// Log pitch / yaw of mouse click when debugging / placing hot spots
if (config.hotSpotDebug) {
var canvas = renderer.getCanvas();
var x = pos.x / canvas.width * 2 - 1;
var y = (1 - pos.y / canvas.height * 2) * canvas.height / canvas.width;
var focal = 1 / Math.tan(config.hfov * Math.PI / 360);
var s = Math.sin(config.pitch * Math.PI / 180);
var c = Math.cos(config.pitch * Math.PI / 180);
var a = focal * c - y * s;
var root = Math.sqrt(x*x + a*a);
var pitch = Math.atan((y * c + focal * s) / root) * 180 / Math.PI;
var yaw = Math.atan2(x / root, a / root) * 180 / Math.PI + config.yaw;
console.log('Pitch: ' + pitch + ', Yaw: ' + yaw + ', Center Pitch: ' +
var coords = mouseEventToCoords(event);
console.log('Pitch: ' + coords[0] + ', Yaw: ' + coords[1] + ', Center Pitch: ' +
config.pitch + ', Center Yaw: ' + config.yaw + ', HFOV: ' + config.hfov);
}
@@ -578,6 +569,27 @@ function onDocumentMouseDown(event) {
}

/**
* Calculate panorama pitch and yaw from location of mouse event.
* @private
* @param {MouseEvent} event - Document mouse down event.
* @returns {number[]} [pitch, yaw]
*/
function mouseEventToCoords(event) {
var pos = mousePosition(event);
var canvas = renderer.getCanvas();
var x = pos.x / canvas.width * 2 - 1;
var y = (1 - pos.y / canvas.height * 2) * canvas.height / canvas.width;
var focal = 1 / Math.tan(config.hfov * Math.PI / 360);
var s = Math.sin(config.pitch * Math.PI / 180);
var c = Math.cos(config.pitch * Math.PI / 180);
var a = focal * c - y * s;
var root = Math.sqrt(x*x + a*a);
var pitch = Math.atan((y * c + focal * s) / root) * 180 / Math.PI;
var yaw = Math.atan2(x / root, a / root) * 180 / Math.PI + config.yaw;
return [pitch, yaw];
}

/**
* Event handler for mouse moves. Pans center of view.
* @private
* @param {MouseEvent} event - Document mouse move event.
@@ -1824,6 +1836,17 @@ this.setUpdate = function(bool) {
return this;
}

/**
* Calculate panorama pitch and yaw from location of mouse event.
* @memberof Viewer
* @instance
* @param {MouseEvent} event - Document mouse down event.
* @returns {number[]} [pitch, yaw]
*/
this.mouseEventToCoords = function(event) {
return mouseEventToCoords(event);
}

}

return {


Ladataan…
Peruuta
Tallenna