File size: 1,632 Bytes
6cd9596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
 * @author WestLangley / http://github.com/WestLangley
 * @author thezwap / http://github.com/thezwap
 */

THREE.MathUtils = {

    setQuaternionFromProperEuler: function ( q, a, b, c, order ) {

        // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles

        // rotations are applied to the axes in the order specified by 'order'
        // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
        // angles are in radians

        var cos = Math.cos;
        var sin = Math.sin;

        var c2 = cos( b / 2 );
        var s2 = sin( b / 2 );

        var c13 = cos( ( a + c ) / 2 );
        var s13 = sin( ( a + c ) / 2 );

        var c1_3 = cos( ( a - c ) / 2 );
        var s1_3 = sin( ( a - c ) / 2 );

        var c3_1 = cos( ( c - a ) / 2 );
        var s3_1 = sin( ( c - a ) / 2 );

        if ( order === 'XYX' ) {

            q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );

        } else if ( order === 'YZY' ) {

            q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );

        } else if ( order === 'ZXZ' ) {

            q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );

        } else if ( order === 'XZX' ) {

            q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );

        } else if ( order === 'YXY' ) {

            q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );

        } else if ( order === 'ZYZ' ) {

            q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );

        } else {

            console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order.' );

        }

    }

};