Skip to content

Commit 0825c1f

Browse files
committed
Add support for additional Euler rotation orders.
1 parent 89a4d0e commit 0825c1f

File tree

2 files changed

+100
-13
lines changed

2 files changed

+100
-13
lines changed

src/core/Matrix4.js

Lines changed: 98 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -532,30 +532,116 @@ THREE.Matrix4.prototype = {
532532

533533
},
534534

535-
setRotationFromEuler: function( v ) {
535+
setRotationFromEuler: function( v, order ) {
536536

537537
var x = v.x, y = v.y, z = v.z,
538538
a = Math.cos( x ), b = Math.sin( x ),
539539
c = Math.cos( y ), d = Math.sin( y ),
540-
e = Math.cos( z ), f = Math.sin( z ),
541-
ad = a * d, bd = b * d;
540+
e = Math.cos( z ), f = Math.sin( z );
542541

543-
this.n11 = c * e;
544-
this.n12 = - c * f;
545-
this.n13 = d;
542+
switch ( order ) {
543+
case 'YXZ':
544+
var ce = c * e, cf = c * f, de = d * e, df = d * f;
546545

547-
this.n21 = bd * e + a * f;
548-
this.n22 = - bd * f + a * e;
549-
this.n23 = - b * c;
546+
this.n11 = ce + df * b;
547+
this.n12 = de * b - cf;
548+
this.n13 = a * d;
550549

551-
this.n31 = - ad * e + b * f;
552-
this.n32 = ad * f + b * e;
553-
this.n33 = a * c;
550+
this.n21 = a * f;
551+
this.n22 = a * e;
552+
this.n23 = - b;
553+
554+
this.n31 = cf * b - de;
555+
this.n32 = df + ce * b;
556+
this.n33 = a * c;
557+
break;
558+
559+
case 'ZXY':
560+
var ce = c * e, cf = c * f, de = d * e, df = d * f;
561+
562+
this.n11 = ce - df * b;
563+
this.n12 = - a * f;
564+
this.n13 = de + cf * b;
565+
566+
this.n21 = cf + de * b;
567+
this.n22 = a * e;
568+
this.n23 = df - ce * b;
569+
570+
this.n31 = - a * d;
571+
this.n32 = b;
572+
this.n33 = a * c;
573+
break;
574+
575+
case 'ZYX':
576+
var ae = a * e, af = a * f, be = b * e, bf = b * f;
577+
578+
this.n11 = c * e;
579+
this.n12 = be * d - af;
580+
this.n13 = ae * d + bf;
581+
582+
this.n21 = c * f;
583+
this.n22 = bf * d + ae;
584+
this.n23 = af * d - be;
585+
586+
this.n31 = - d;
587+
this.n32 = b * c;
588+
this.n33 = a * c;
589+
break;
590+
591+
case 'YZX':
592+
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
593+
594+
this.n11 = c * e;
595+
this.n12 = bd - ac * f;
596+
this.n13 = bc * f + ad;
597+
598+
this.n21 = f;
599+
this.n22 = a * e;
600+
this.n23 = - b * e;
601+
602+
this.n31 = - d * e;
603+
this.n32 = ad * f + bc;
604+
this.n33 = ac - bd * f;
605+
break;
606+
607+
case 'XZY':
608+
var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
609+
610+
this.n11 = c * e;
611+
this.n12 = - f;
612+
this.n13 = d * e;
613+
614+
this.n21 = ac * f + bd;
615+
this.n22 = a * e;
616+
this.n23 = ad * f - bc;
617+
618+
this.n31 = bc * f - ad;
619+
this.n32 = b * e;
620+
this.n33 = bd * f + ac;
621+
break;
622+
623+
default: // 'XYZ'
624+
var ae = a * e, af = a * f, be = b * e, bf = b * f;
625+
626+
this.n11 = c * e;
627+
this.n12 = - c * f;
628+
this.n13 = d;
629+
630+
this.n21 = af + be * d;
631+
this.n22 = ae - bf * d;
632+
this.n23 = - b * c;
633+
634+
this.n31 = bf - ae * d;
635+
this.n32 = be + af * d;
636+
this.n33 = a * c;
637+
break;
638+
}
554639

555640
return this;
556641

557642
},
558643

644+
559645
setRotationFromQuaternion: function( q ) {
560646

561647
var x = q.x, y = q.y, z = q.z, w = q.w,

src/core/Object3D.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ THREE.Object3D = function() {
1313

1414
this.position = new THREE.Vector3();
1515
this.rotation = new THREE.Vector3();
16+
this.eulerOrder = 'XYZ';
1617
this.scale = new THREE.Vector3( 1, 1, 1 );
1718

1819
this.dynamic = false; // when true it retains arrays so they can be updated with __dirty*
@@ -175,7 +176,7 @@ THREE.Object3D.prototype = {
175176

176177
} else {
177178

178-
this.matrix.setRotationFromEuler( this.rotation );
179+
this.matrix.setRotationFromEuler( this.rotation, this.eulerOrder );
179180

180181
}
181182

0 commit comments

Comments
 (0)