@@ -29,7 +29,7 @@ use approx::ApproxEq;
29
29
use array:: { Array1 , Array2 , FixedArray } ;
30
30
use num:: { BaseFloat , BaseNum } ;
31
31
use point:: { Point , Point3 } ;
32
- use quaternion:: { Quaternion , ToQuaternion } ;
32
+ use quaternion:: Quaternion ;
33
33
use vector:: { Vector , EuclideanVector } ;
34
34
use vector:: { Vector2 , Vector3 , Vector4 } ;
35
35
@@ -1337,44 +1337,44 @@ impl<S: BaseFloat> From<Matrix3<S>> for Matrix4<S> {
1337
1337
}
1338
1338
}
1339
1339
1340
- impl < S : BaseFloat > ToQuaternion < S > for Matrix3 < S > {
1340
+ impl < S : BaseFloat > From < Matrix3 < S > > for Quaternion < S > {
1341
1341
/// Convert the matrix to a quaternion
1342
- fn to_quaternion ( & self ) -> Quaternion < S > {
1342
+ fn from ( mat : Matrix3 < S > ) -> Quaternion < S > {
1343
1343
// http://www.cs.ucr.edu/~vbz/resources/quatut.pdf
1344
- let trace = self . trace ( ) ;
1344
+ let trace = mat . trace ( ) ;
1345
1345
let half: S = cast ( 0.5f64 ) . unwrap ( ) ;
1346
1346
1347
1347
if trace >= zero :: < S > ( ) {
1348
1348
let s = ( one :: < S > ( ) + trace) . sqrt ( ) ;
1349
1349
let w = half * s;
1350
1350
let s = half / s;
1351
- let x = ( self [ 1 ] [ 2 ] - self [ 2 ] [ 1 ] ) * s;
1352
- let y = ( self [ 2 ] [ 0 ] - self [ 0 ] [ 2 ] ) * s;
1353
- let z = ( self [ 0 ] [ 1 ] - self [ 1 ] [ 0 ] ) * s;
1351
+ let x = ( mat [ 1 ] [ 2 ] - mat [ 2 ] [ 1 ] ) * s;
1352
+ let y = ( mat [ 2 ] [ 0 ] - mat [ 0 ] [ 2 ] ) * s;
1353
+ let z = ( mat [ 0 ] [ 1 ] - mat [ 1 ] [ 0 ] ) * s;
1354
1354
Quaternion :: new ( w, x, y, z)
1355
- } else if ( self [ 0 ] [ 0 ] > self [ 1 ] [ 1 ] ) && ( self [ 0 ] [ 0 ] > self [ 2 ] [ 2 ] ) {
1356
- let s = ( half + ( self [ 0 ] [ 0 ] - self [ 1 ] [ 1 ] - self [ 2 ] [ 2 ] ) ) . sqrt ( ) ;
1355
+ } else if ( mat [ 0 ] [ 0 ] > mat [ 1 ] [ 1 ] ) && ( mat [ 0 ] [ 0 ] > mat [ 2 ] [ 2 ] ) {
1356
+ let s = ( half + ( mat [ 0 ] [ 0 ] - mat [ 1 ] [ 1 ] - mat [ 2 ] [ 2 ] ) ) . sqrt ( ) ;
1357
1357
let w = half * s;
1358
1358
let s = half / s;
1359
- let x = ( self [ 0 ] [ 1 ] - self [ 1 ] [ 0 ] ) * s;
1360
- let y = ( self [ 2 ] [ 0 ] - self [ 0 ] [ 2 ] ) * s;
1361
- let z = ( self [ 1 ] [ 2 ] - self [ 2 ] [ 1 ] ) * s;
1359
+ let x = ( mat [ 0 ] [ 1 ] - mat [ 1 ] [ 0 ] ) * s;
1360
+ let y = ( mat [ 2 ] [ 0 ] - mat [ 0 ] [ 2 ] ) * s;
1361
+ let z = ( mat [ 1 ] [ 2 ] - mat [ 2 ] [ 1 ] ) * s;
1362
1362
Quaternion :: new ( w, x, y, z)
1363
- } else if self [ 1 ] [ 1 ] > self [ 2 ] [ 2 ] {
1364
- let s = ( half + ( self [ 1 ] [ 1 ] - self [ 0 ] [ 0 ] - self [ 2 ] [ 2 ] ) ) . sqrt ( ) ;
1363
+ } else if mat [ 1 ] [ 1 ] > mat [ 2 ] [ 2 ] {
1364
+ let s = ( half + ( mat [ 1 ] [ 1 ] - mat [ 0 ] [ 0 ] - mat [ 2 ] [ 2 ] ) ) . sqrt ( ) ;
1365
1365
let w = half * s;
1366
1366
let s = half / s;
1367
- let x = ( self [ 0 ] [ 1 ] - self [ 1 ] [ 0 ] ) * s;
1368
- let y = ( self [ 1 ] [ 2 ] - self [ 2 ] [ 1 ] ) * s;
1369
- let z = ( self [ 2 ] [ 0 ] - self [ 0 ] [ 2 ] ) * s;
1367
+ let x = ( mat [ 0 ] [ 1 ] - mat [ 1 ] [ 0 ] ) * s;
1368
+ let y = ( mat [ 1 ] [ 2 ] - mat [ 2 ] [ 1 ] ) * s;
1369
+ let z = ( mat [ 2 ] [ 0 ] - mat [ 0 ] [ 2 ] ) * s;
1370
1370
Quaternion :: new ( w, x, y, z)
1371
1371
} else {
1372
- let s = ( half + ( self [ 2 ] [ 2 ] - self [ 0 ] [ 0 ] - self [ 1 ] [ 1 ] ) ) . sqrt ( ) ;
1372
+ let s = ( half + ( mat [ 2 ] [ 2 ] - mat [ 0 ] [ 0 ] - mat [ 1 ] [ 1 ] ) ) . sqrt ( ) ;
1373
1373
let w = half * s;
1374
1374
let s = half / s;
1375
- let x = ( self [ 2 ] [ 0 ] - self [ 0 ] [ 2 ] ) * s;
1376
- let y = ( self [ 1 ] [ 2 ] - self [ 2 ] [ 1 ] ) * s;
1377
- let z = ( self [ 0 ] [ 1 ] - self [ 1 ] [ 0 ] ) * s;
1375
+ let x = ( mat [ 2 ] [ 0 ] - mat [ 0 ] [ 2 ] ) * s;
1376
+ let y = ( mat [ 1 ] [ 2 ] - mat [ 2 ] [ 1 ] ) * s;
1377
+ let z = ( mat [ 0 ] [ 1 ] - mat [ 1 ] [ 0 ] ) * s;
1378
1378
Quaternion :: new ( w, x, y, z)
1379
1379
}
1380
1380
}
0 commit comments