簡體   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