繁体   English   中英

重设方向在手机中不起作用

[英]Reset orientation does not work in phone

我想重置头部方向。 我做到了,但是可以在PC上使用,但不能在手机上使用。 有一个名为“重置”的按钮。 如果单击,它应该重置头部方向。 它可以在PC上运行,但不能在手机上运行。 这是我的代码:

<!DOCTYPE html>
<html>
<head>
<title>Hello, WebVR! - A-Frame</title>
<meta name="description" content="Hello, WebVR! - A-Frame">
<script src="https://aframe.io/releases/0.8.0/aframe.min.js"></script>
<script src="https://rawgit.com/rdub80/aframe-gui/master/dist/aframe-gui.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<a-scene>
  <a-box position="-1 0.5 -3" rotation="0 45 0" color="#4CC3D9" shadow></a-box>
  <a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E" shadow></a-sphere>
  <a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D" shadow></a-cylinder>
  <a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4" shadow></a-plane>
  <a-gui-button resetorientation
          id="reset"
          class="clickable"              
          position="-0.038 -1.611 -3.011"
          rotation="-25 0 0"
          width="2.5" height="0.75"
          key-code="80"
          value="Reset"
          font-family="Helvetica"
          background-color="#A04000"           
      >
      </a-gui-button>
  <a-sky color="#ECECEC"></a-sky>
  <a-camera position="0 2 0">
    <a-cursor raycaster="objects: .clickable" ></a-cursor>
  </a-camera>
</a-scene>
 </body>
 </html>

这是我的脚本:

AFRAME.registerComponent('resetorientation', {
init: function () {
this.el.addEventListener('click', function () {
  document.querySelector('#reset').emit(reset());
  });
 }
});
function reset(){
var x = document.querySelector('[camera]').getAttribute('rotation').x;
var y = document.querySelector('[camera]').getAttribute('rotation').y;
console.log(x);
  console.log(y);
document.querySelector('[camera]').setAttribute('rotation', {x: 0 * x});
document.querySelector('[camera]').setAttribute('rotation', {y: 0 * y});
var a = document.querySelector('[camera]').getAttribute('rotation').x;
var b = document.querySelector('[camera]').getAttribute('rotation').y;
console.log(a);
  console.log(b);
}

您将需要进入look-controls并手动为其从陀螺仪获得的xyz旋转添加偏移量。


仅使用偏航(y)值才有意义的解决方法是将相机包装在实体中,然后单击“ reset ,旋转包装器偏航。

在这里住小提琴。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM