@@ -93,7 +93,7 @@ function axisAngle(axis, angle) {
93
93
return quaternion ;
94
94
}
95
95
96
- function from ( x , y , z , w ) {
96
+ function getQuat ( x , y , z , w ) {
97
97
if ( typeof x === 'number' ) {
98
98
return [ x , y , z , w ] ;
99
99
}
@@ -103,10 +103,14 @@ function from(x, y, z, w) {
103
103
if ( isAngle ( y ) ) {
104
104
return axisAngle ( x , y ) ;
105
105
}
106
- if ( x ) {
107
- return look ( x , y || UP ) ;
106
+ if ( x && y ) {
107
+ return look ( x , y ) ;
108
108
}
109
- return [ 0 , 0 , 0 , 1 ] ;
109
+ return undefined ;
110
+ }
111
+
112
+ function from ( x , y , z , w ) {
113
+ return getQuat ( x , y , z , w ) || [ 0 , 0 , 0 , 1 ] ;
110
114
}
111
115
112
116
class AQuaternion {
@@ -133,6 +137,10 @@ class AQuaternion {
133
137
}
134
138
135
139
multiply ( other , y , z , w ) {
140
+ const o = getQuat ( other , y , z , w ) ;
141
+ if ( o ) {
142
+ return this . multiplyQuaternion ( new this . constructor ( o ) ) ;
143
+ }
136
144
if ( typeof other . w === 'number' ) {
137
145
return this . multiplyQuaternion ( other ) ;
138
146
}
@@ -159,8 +167,8 @@ class AQuaternion {
159
167
return new this . constructor ( x , y , z , w ) ;
160
168
}
161
169
162
- mul ( other ) {
163
- return this . multiply ( other ) ;
170
+ mul ( other , y , z , w ) {
171
+ return this . multiply ( other , y , z , w ) ;
164
172
}
165
173
166
174
get inverse ( ) {
@@ -268,7 +276,6 @@ class AQuaternion {
268
276
}
269
277
}
270
278
271
-
272
279
export class Quaternion extends AQuaternion {
273
280
/**
274
281
* @param {number | Quaternion | IQuaternion | Vector | Victor | [number, number, number, number] } [x]
@@ -433,22 +440,15 @@ const LEFT90 = new IQuaternion(LEFT, degree(90));
433
440
* @param {number } orientation
434
441
* @returns {IQuaternion }
435
442
*/
436
- export function fromOrientation ( orientationEvent , orientation ) {
437
- const { alpha, beta, gamma } = orientationEvent ;
438
- const x = iquaternion ( RIGHT , degree ( beta ) ) ;
439
- const y = iquaternion ( UP , degree ( alpha ) ) ;
440
- const z = iquaternion ( FORWARD , degree ( gamma ) ) ;
441
-
442
- let rot = y ;
443
- rot = rot . multiply ( x ) ;
444
- rot = rot . multiply ( z ) ;
445
- rot = rot . multiply ( LEFT90 ) ;
446
-
447
- if ( orientation ) {
448
- const { dir } = rot ;
449
- const local = new IQuaternion ( dir , degree ( orientation ) ) ;
450
- rot = local . multiplyQuaternion ( rot ) ;
451
- }
443
+ export function fromOrientation ( { alpha, beta, gamma } , orientation ) {
444
+ let rot = iquaternion ( UP , degree ( alpha ) )
445
+ . mul ( RIGHT , degree ( beta ) )
446
+ . mul ( FORWARD , degree ( gamma ) )
447
+ . mul ( LEFT90 ) ;
448
+
449
+ rot = iquaternion ( rot . dir , degree ( orientation ) )
450
+ . mul ( rot ) ;
451
+
452
452
return rot ;
453
453
}
454
454
0 commit comments