2
2
import {
3
3
operatorCalc , cachedValueOf , defineVectorLength , cachedFactory , cachedFunction
4
4
} from '../operator' ;
5
+ import { fromEulerYXZ } from '../util' ;
5
6
6
7
function fallbackWindow ( ) {
7
8
return {
@@ -10,7 +11,7 @@ function fallbackWindow() {
10
11
}
11
12
export function hijackPlayCanvas ( pc ) {
12
13
const {
13
- Vec2, Vec3, Quat, Mat4
14
+ Vec2, Vec3, Quat, Mat4, math
14
15
} = pc ;
15
16
16
17
cachedValueOf ( Vec2 ) ;
@@ -60,14 +61,34 @@ export function hijackPlayCanvas(pc) {
60
61
}
61
62
} ) ;
62
63
pc . quat = cachedFunction ( ( x , y , z , w ) => {
63
- if ( typeof dir === 'number' ) {
64
+ if ( typeof x === 'number' ) {
64
65
return new Quat ( x , y , z , w ) ;
65
66
}
66
67
if ( ! x ) {
67
68
return new Quat ( ) ;
68
69
}
70
+ if ( typeof y === 'number' ) {
71
+ return new Quat ( ) . setFromAxisAngle ( x , y ) ;
72
+ }
69
73
return new Quat ( ) . setFromMat4 ( new Mat4 ( ) . setLookAt ( Vec3 . ZERO , x , y || Vec3 . UP ) ) ;
70
74
} ) ;
75
+
76
+ const LEFT90 = pc . quat ( Vec3 . LEFT , 90 ) ;
77
+
78
+ Quat . prototype . setFromOrientation = function ( { alpha, beta, gamma } , orientation ) {
79
+ const x = beta * math . DEG_TO_RAD ;
80
+ const y = alpha * math . DEG_TO_RAD ;
81
+ const z = - gamma * math . DEG_TO_RAD ;
82
+ let rot = pc . quat ( fromEulerYXZ ( x , y , z ) ) ;
83
+ rot . mul ( LEFT90 ) ;
84
+
85
+ if ( orientation ) {
86
+ const { dir } = rot ;
87
+ const local = pc . quat ( dir , orientation ) ;
88
+ rot = local . mul ( rot ) ;
89
+ }
90
+ this . copy ( rot ) ;
91
+ } ;
71
92
}
72
93
73
94
// eslint-disable-next-line no-undef
0 commit comments