Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect a head/camera motion with aframe

I'm in search for a motion detection in with a-frame. What I want to achieve is a detection if someone is moving his head when being in VR-Mode. Is there any property for an entity I can check? Or does the camera component itself has any position/rotaion/whatever attributes I can use for a detection?

like image 848
casarock Avatar asked Jul 13 '26 01:07

casarock


2 Answers

https://aframe.io/docs/0.3.0/core/entity.html#listening-for-component-changes

AFRAME.registerComponent('do-something-on-head-movement', {
  init: function () {
    var scene = this.el;
    var camera = scene.cameraEl;

    camera.addEventListener('componentchanged', function (evt) {
      if (evt.detail.name === 'rotation' || evt.detail.name === 'position') {
        // Do something.
      }
    });
  }
});

<a-scene do-something-on-head-movement>
like image 151
ngokevin Avatar answered Jul 14 '26 14:07

ngokevin


I used this function to detect when the headset was put down (face down) to "pause" the app

function process(event) {
  var gamma = event.gamma;
  if((gamma < -10)||(gamma>5)){
    playApp();
  }else{
    pauseApp();
  }
}

http://w3c.github.io/deviceorientation/spec-source-orientation.html

like image 39
Laurie Clark Avatar answered Jul 14 '26 13:07

Laurie Clark