@@ -3,14 +3,19 @@ import {Component} from '@wonderlandengine/api';
3
3
/**
4
4
* Function to convert a Euler in YXZ order to a quaternion
5
5
*/
6
- function quatFromEulerYXZ ( out , x , y , z ) {
7
- const c1 = Math . cos ( x / 2 ) ;
8
- const c2 = Math . cos ( y / 2 ) ;
9
- const c3 = Math . cos ( z / 2 ) ;
6
+ function quatFromEulerYXZDeg ( out : number [ ] , x : number , y : number , z : number ) {
7
+ const halfToRad = ( 0.5 * Math . PI ) / 180.0 ;
8
+ x *= halfToRad ;
9
+ y *= halfToRad ;
10
+ z *= halfToRad ;
10
11
11
- const s1 = Math . sin ( x / 2 ) ;
12
- const s2 = Math . sin ( y / 2 ) ;
13
- const s3 = Math . sin ( z / 2 ) ;
12
+ const c1 = Math . cos ( x ) ;
13
+ const c2 = Math . cos ( y ) ;
14
+ const c3 = Math . cos ( z ) ;
15
+
16
+ const s1 = Math . sin ( x ) ;
17
+ const s2 = Math . sin ( y ) ;
18
+ const s3 = Math . sin ( z ) ;
14
19
15
20
out [ 0 ] = s1 * c2 * c3 + c1 * s2 * s3 ;
16
21
out [ 1 ] = c1 * s2 * c3 - s1 * c2 * s3 ;
@@ -68,19 +73,13 @@ export class DeviceOrientationLook extends Component {
68
73
}
69
74
70
75
onDeviceOrientation = ( e : DeviceOrientationEvent ) => {
71
- let alpha = e . alpha || 0 ;
72
- let beta = e . beta || 0 ;
73
- let gamma = e . gamma || 0 ;
74
- const toRad = Math . PI / 180 ;
75
- quatFromEulerYXZ (
76
- this . deviceOrientation ,
77
- beta * toRad ,
78
- alpha * toRad ,
79
- - gamma * toRad
80
- ) ;
76
+ let alpha = e . alpha ?? 0 ;
77
+ let beta = e . beta ?? 0 ;
78
+ let gamma = e . gamma ?? 0 ;
79
+ quatFromEulerYXZDeg ( this . deviceOrientation , beta , alpha , - gamma ) ;
81
80
} ;
82
81
83
- onOrientationChange = ( e : Event ) => {
82
+ onOrientationChange = ( ) => {
84
83
this . screenOrientation =
85
84
window . screen ?. orientation . angle ?? window . orientation ?? 0 ;
86
85
} ;
0 commit comments