-
Notifications
You must be signed in to change notification settings - Fork 0
/
motion.js
37 lines (29 loc) · 978 Bytes
/
motion.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* Created by soads on 21.01.2017.
*/
function Motion(){
this.x = 0;
this.y = 0;
this.z = 0;
this.gyroAlpha = 0;
this.gyroBeta = 0;
this.gyroGamma = 0;
this.absAlpha = 0;
this.absBeta = 0;
this.absGamma = 0;
this.handleMotionEvent = function (event) {
this.x = event.accelerationIncludingGravity.x;
this.y = event.accelerationIncludingGravity.y;
this.z = event.accelerationIncludingGravity.z;
this.gyroAlpha = event.rotationRate.alpha;
this.gyroBeta = event.rotationRate.beta;
this.gyroGamma = event.rotationRate.gamma;
};
this.handleOrientationEvent = function(event){
this.absAlpha = event.alpha;
this.absBeta = event.beta;
this.absGamma = event.gamma;
};
window.addEventListener("devicemotion", this.handleMotionEvent.bind(this), true);
window.addEventListener("deviceorientation", this.handleOrientationEvent.bind(this), true);
}