【问题标题】:allow touch control up and down in aframe允许在框架中上下触摸控制
【发布时间】:2019-10-14 02:42:55
【问题描述】:

aframe 场景中的触控只能左右操作,手机不能上下操作 但是使用桌面它可以完美地工作 当我添加触摸控制时,外观控制被删除

如何同时添加两个

【问题讨论】:

    标签: mobile controls touch aframe


    【解决方案1】:

    我想在移动设备上做同样的事情。加载 aFrame 库后添加此代码:

    AFRAME.components["look-controls"].Component.prototype.onTouchMove = function (t) {
                            var PI_2 = Math.PI/2,
                            e,
                            o = this.el.sceneEl.canvas,
                            i = this.yawObject,
                            j = this.pitchObject;
                            this.touchStarted && this.data.touchEnabled && (e = 2 * Math.PI * (t.touches[0].pageX - this.touchStart.x) / o.clientWidth, f = 2 * Math.PI * (t.touches[0].pageY - this.touchStart.y) / o.clientHeight, j.rotation.x += .3 * f, i.rotation.y += .5 * e, j.rotation.x = Math.max(-PI_2, Math.min(PI_2, j.rotation.x)), this.touchStart = {
                                    x: t.touches[0].pageX,
                                    y: t.touches[0].pageY
                                })
                            }
    

    或者,或者,您可以在 aframe.min.js(或您使用的任何文件)中找到“外观控件”的代码并在那里修改 onTouchMove 函数。

    【讨论】:

      【解决方案2】:

      我从“Igor R”那里得到了答案,并稍微整理了一下。

      AFRAME.components["look-controls"].Component.prototype.onTouchMove = function (t) {
          if (this.touchStarted && this.data.touchEnabled) {
              this.pitchObject.rotation.x += .6 * Math.PI * (t.touches[0].pageY - this.touchStart.y) / this.el.sceneEl.canvas.clientHeight;
              this.yawObject.rotation.y += /*  */ Math.PI * (t.touches[0].pageX - this.touchStart.x) / this.el.sceneEl.canvas.clientWidth;
              this.pitchObject.rotation.x = Math.max(Math.PI / -2, Math.min(Math.PI / 2, this.pitchObject.rotation.x));
              this.touchStart = {
                  x: t.touches[0].pageX,
                  y: t.touches[0].pageY
              }
          }
      }
      

      【讨论】:

        【解决方案3】:

        请说明您使用的是 iOS 设备还是 Android。后续步骤:

        1. 在 iOS 12.2 上,这是一个已知问题,因为 Apple 已在 Safari 中禁用了设备方向和设备运动。试图手动启用它,但仍然无法正常工作。已安装 Chrome 和 cardboard-vr 文件,但没有取得丰硕成果。

        2. 在 Android 上,如果您没有 google cardboard,请安装它。更新 Aframe 的版本,确保您使用的是 A-Frame 0.9.2。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-03-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多