Gabe Willson
Gabe Willson

Reputation: 15

Adjusting sensitivity in A-Frame scene

When I click and drag my mouse across a scene, it takes two full screen widths to make a 360 degree turn.

Is it possible to adjust the sensitivity of an A-Frame scene?

In case anyone was curious, this is the html I am using:

<!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>

Upvotes: 1

Views: 424

Answers (1)

Grasper
Grasper

Reputation: 1313

<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 you can adjust the speed, and add the camera component right above the sky

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

Demo

You will only need the Y defined

Upvotes: 1

Related Questions