此为开发vr全景,所用到的:
window.addEventListener('deviceorientation', function(event) {
var alpha = event.alpha;
// var beta = event.beta;
var gamma = event.gamma;
var newH = event.alpha / 2 * (-1);
var newV = event.gamma * 1;
if (gamma <= 0) {
newV = 90 + gamma;
newH = -alpha;
} else {
newV = gamma - 90;
alpha = (alpha + 180) % 360;
newH = -alpha;
}
// 处理逻辑
pano1.call('lookat(' + newH + ',' + newV + ',20)');
pano2.call('lookat(' + newH + ',' + newV + ',20)');
}, false);