topical media & game development

talk show tell print

mobile-query-three-vendor-threex-examples-threex.domevent-vendor-threex-THREEx.DeviceOrientationState.js / js



  
@namespace

  
  var THREEx        = THREEx                 || {};
  
  THREEx.DeviceOrientationState        = function()
  {
          // to store the current state
          this._state        = { x: 0, y: 0, z: 0 };
  
          this._callback        = function(event){ this._onDeviceOrientation(event); }.bind(this);
          
          // bind events
          // - spec http://dev.w3.org/geo/api/spec-source-orientation.html
  	window.addEventListener('deviceorientation', this._callback);
  }
  
  
To stop listening of the keyboard events

  
  THREEx.DeviceOrientationState.prototype.destroy        = function()
  {
          // unbind events
          window.removeEventListener('deviceorientation', this._callback);
  }
  
  
to process the keyboard dom event

  
  THREEx.DeviceOrientationState.prototype._onDeviceOrientation        = function(event)
  {
          this._state.x        = (!event.alpha ? 0 : event.alpha) * Math.PI / 180;
          this._state.y        = (!event.beta  ? 0 : event.beta ) * Math.PI / 180;
          this._state.z        = (!event.gamma ? 0 : event.gamma) * Math.PI / 180;
  }
  
  THREEx.DeviceOrientationState.prototype.angleX        = function()
  {
          return this._state.x;
  }
  
  THREEx.DeviceOrientationState.prototype.angleY        = function()
  {
          return this._state.y;
  }
  
  THREEx.DeviceOrientationState.prototype.angleZ        = function()
  {
          return this._state.z;
  }
  
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.