【问题标题】:Adjusting sensitivity in A-Frame scene在 A-Frame 场景中调整灵敏度
【发布时间】:2020-10-08 04:25:04
【问题描述】:

当我在场景中单击并拖动鼠标时,需要两个全屏宽度才能进行 360 度旋转。

是否可以调整 A-Frame 场景的灵敏度?

如果有人好奇,这是我正在使用的 html:

<!DOCTYPE html>


<html>
<head>
    <title>test</title>
    <script src="https://aframe.io/releases/0.5.0/aframe.min.js"></script>
</head>


<body>
    <a-scene vr-mode-ui="enabled: false">
        <a-assets>
            <img id="image" crossorigin="anonymous" src="https://cdn.aframe.io/360-image-gallery-boilerplate/img/sechelt.jpg">
        </a-assets>

        <a-sky id="image-360" radius="10" src="#image"></a-sky>
    </a-scene>
</body>
</html>

【问题讨论】:

  • 灵敏度设置为头部旋转。关于背景,您无需在 VR 中单击并拖动
  • A-Frame 允许用鼠标单击和拖动旋转,我知道它是为 VR 设计的,但如果用户没有能够检测运动的设备,例如 pc,我会仍然喜欢他们能够快速移动

标签: html aframe


【解决方案1】:
<script type="text/javascript">
    AFRAME.registerComponent('drag-rotate-component',{
      schema : { speed : {default:1}},
      init : function(){
        this.ifMouseDown = false;
        this.x_cord = 0;
        this.y_cord = 0;
        document.addEventListener('mousedown',this.OnDocumentMouseDown.bind(this));
        document.addEventListener('mouseup',this.OnDocumentMouseUp.bind(this));
        document.addEventListener('mousemove',this.OnDocumentMouseMove.bind(this));
      },
      OnDocumentMouseDown : function(event){
        this.ifMouseDown = true;
        this.x_cord = event.clientX;
        this.y_cord = event.clientY;
      },
      OnDocumentMouseUp : function(){
        this.ifMouseDown = false;
      },
      OnDocumentMouseMove : function(event)
      {
        if(this.ifMouseDown)
        {
          var temp_x = event.clientX-this.x_cord;
          var temp_y = event.clientY-this.y_cord;
          if(Math.abs(temp_y)<Math.abs(temp_x))
          {
            this.el.object3D.rotateY(temp_x*this.data.speed/100);
          }
          else
          {
            this.el.object3D.rotateX(temp_y*this.data.speed/100);
          }
          this.x_cord = event.clientX;
          this.y_cord = event.clientY;
        }
      }
    });
  </script>

Source你可以调整速度,并在天空正上方添加camera组件

<a-entity camera drag-rotate-component></a-entity>

Demo

您只需要定义Y

【讨论】:

    【解决方案2】:

    我制作了一个fork of aframe,其中包括用于外观控制的 X 和 Y 鼠标灵敏度

    【讨论】:

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