Path: blob/main/projects/HexGL/bkcore.coffee/controllers/OrientationController.coffee
4627 views
###1OrientationController (Orientation + buttons) for touch devices23@class bkcore.OrientationController4@author Thibaut 'BKcore' Despoulain <http://bkcore.com>5###6class OrientationController78@isCompatible: ->9return ('DeviceOrientationEvent' of window)1011###12Creates a new OrientationController1314@param dom DOMElement The element that will listen to touch events15@param registerTouch bool Enable touch detection16@param touchCallback function Callback for touches17###18constructor: (@dom, @registerTouch=true, @touchCallback=null) ->19@active = true20@alpha = 0.021@beta = 0.022@gamma = 0.023@dalpha = null24@dbeta = null25@dgamma = null26@touches = null2728window.addEventListener('deviceorientation', ((e)=> @orientationChange(e)), false)29if @registerTouch30@dom.addEventListener('touchstart', ((e)=> @touchStart(e)), false)31@dom.addEventListener('touchend', ((e)=> @touchEnd(e)), false)3233###34@private35###36orientationChange: (event) ->37return if not @active38if(@dalpha == null)39console.log "calbrate", event.beta40@dalpha = event.alpha41@dbeta = event.beta42@dgamma = event.gamma43@alpha = event.alpha - @dalpha44@beta = event.beta - @dbeta45@gamma = event.gamma - @dgamma46false4748###49@private50###51touchStart: (event) ->52return if not @active53for touch in event.changedTouches54@touchCallback?(on, touch, event)55@touches = event.touches56false5758###59@private60###61touchEnd: (event) ->62return if not @active63for touch in event.changedTouches64@touchCallback?(on, touch, event)65@touches = event.touches66false6768exports = exports ? @69exports.bkcore ||= {}70exports.bkcore.controllers ||= {}71exports.bkcore.controllers.OrientationController = OrientationController7273