@@ -661,6 +661,135 @@ function rotate<T extends Mat3Arg = MatType>(m: Mat3Arg, angleInRadians: number,
661
661
return newDst ;
662
662
}
663
663
664
+ /**
665
+ * Creates a 3-by-3 matrix which rotates around the x-axis by the given angle.
666
+ * @param angleInRadians - The angle by which to rotate (in radians).
667
+ * @param dst - matrix to hold result. If not passed a new one is created.
668
+ * @returns The rotation matrix.
669
+ */
670
+ function rotationX < T extends Mat3Arg = MatType > ( angleInRadians : number , dst ?: T ) {
671
+ const newDst = ( dst ?? new Ctor ( 12 ) ) as T ;
672
+
673
+ const c = Math . cos ( angleInRadians ) ;
674
+ const s = Math . sin ( angleInRadians ) ;
675
+
676
+ newDst [ 0 ] = 1 ; newDst [ 1 ] = 0 ; newDst [ 2 ] = 0 ;
677
+ newDst [ 4 ] = 0 ; newDst [ 5 ] = c ; newDst [ 6 ] = s ;
678
+ newDst [ 8 ] = 0 ; newDst [ 9 ] = - s ; newDst [ 10 ] = c ;
679
+
680
+ return newDst ;
681
+ }
682
+
683
+ /**
684
+ * Rotates the given 3-by-3 matrix around the x-axis by the given
685
+ * angle.
686
+ * @param m - The matrix.
687
+ * @param angleInRadians - The angle by which to rotate (in radians).
688
+ * @param dst - matrix to hold result. If not passed a new one is created.
689
+ * @returns The rotated matrix.
690
+ */
691
+ function rotateX < T extends Mat3Arg = MatType > ( m : Mat3Arg , angleInRadians : number , dst ?: T ) {
692
+ const newDst = ( dst ?? new Ctor ( 12 ) ) as T ;
693
+
694
+ const m10 = m [ 4 ] ;
695
+ const m11 = m [ 5 ] ;
696
+ const m12 = m [ 6 ] ;
697
+ const m20 = m [ 8 ] ;
698
+ const m21 = m [ 9 ] ;
699
+ const m22 = m [ 10 ] ;
700
+
701
+ const c = Math . cos ( angleInRadians ) ;
702
+ const s = Math . sin ( angleInRadians ) ;
703
+
704
+ newDst [ 4 ] = c * m10 + s * m20 ;
705
+ newDst [ 5 ] = c * m11 + s * m21 ;
706
+ newDst [ 6 ] = c * m12 + s * m22 ;
707
+ newDst [ 8 ] = c * m20 - s * m10 ;
708
+ newDst [ 9 ] = c * m21 - s * m11 ;
709
+ newDst [ 10 ] = c * m22 - s * m12 ;
710
+
711
+ if ( m !== newDst ) {
712
+ newDst [ 0 ] = m [ 0 ] ;
713
+ newDst [ 1 ] = m [ 1 ] ;
714
+ newDst [ 2 ] = m [ 2 ] ;
715
+ }
716
+
717
+ return newDst ;
718
+ }
719
+
720
+ /**
721
+ * Creates a 3-by-3 matrix which rotates around the y-axis by the given angle.
722
+ * @param angleInRadians - The angle by which to rotate (in radians).
723
+ * @param dst - matrix to hold result. If not passed a new one is created.
724
+ * @returns The rotation matrix.
725
+ */
726
+ function rotationY < T extends Mat3Arg = MatType > ( angleInRadians : number , dst ?: T ) {
727
+ const newDst = ( dst ?? new Ctor ( 12 ) ) as T ;
728
+
729
+ const c = Math . cos ( angleInRadians ) ;
730
+ const s = Math . sin ( angleInRadians ) ;
731
+
732
+ newDst [ 0 ] = c ; newDst [ 1 ] = 0 ; newDst [ 2 ] = - s ;
733
+ newDst [ 4 ] = 0 ; newDst [ 5 ] = 1 ; newDst [ 6 ] = 0 ;
734
+ newDst [ 8 ] = s ; newDst [ 9 ] = 0 ; newDst [ 10 ] = c ;
735
+
736
+ return newDst ;
737
+ }
738
+
739
+ /**
740
+ * Rotates the given 3-by-3 matrix around the y-axis by the given
741
+ * angle.
742
+ * @param m - The matrix.
743
+ * @param angleInRadians - The angle by which to rotate (in radians).
744
+ * @param dst - matrix to hold result. If not passed a new one is created.
745
+ * @returns The rotated matrix.
746
+ */
747
+ function rotateY < T extends Mat3Arg = MatType > ( m : Mat3Arg , angleInRadians : number , dst ?: T ) {
748
+ const newDst = ( dst ?? new Ctor ( 12 ) ) as T ;
749
+
750
+ const m00 = m [ 0 * 4 + 0 ] ;
751
+ const m01 = m [ 0 * 4 + 1 ] ;
752
+ const m02 = m [ 0 * 4 + 2 ] ;
753
+ const m20 = m [ 2 * 4 + 0 ] ;
754
+ const m21 = m [ 2 * 4 + 1 ] ;
755
+ const m22 = m [ 2 * 4 + 2 ] ;
756
+ const c = Math . cos ( angleInRadians ) ;
757
+ const s = Math . sin ( angleInRadians ) ;
758
+
759
+ newDst [ 0 ] = c * m00 - s * m20 ;
760
+ newDst [ 1 ] = c * m01 - s * m21 ;
761
+ newDst [ 2 ] = c * m02 - s * m22 ;
762
+ newDst [ 8 ] = c * m20 + s * m00 ;
763
+ newDst [ 9 ] = c * m21 + s * m01 ;
764
+ newDst [ 10 ] = c * m22 + s * m02 ;
765
+
766
+ if ( m !== newDst ) {
767
+ newDst [ 4 ] = m [ 4 ] ;
768
+ newDst [ 5 ] = m [ 5 ] ;
769
+ newDst [ 6 ] = m [ 6 ] ;
770
+ }
771
+
772
+ return newDst ;
773
+ }
774
+
775
+ /**
776
+ * Creates a 3-by-3 matrix which rotates around the z-axis by the given angle.
777
+ * @param angleInRadians - The angle by which to rotate (in radians).
778
+ * @param dst - matrix to hold result. If not passed a new one is created.
779
+ * @returns The rotation matrix.
780
+ */
781
+ const rotationZ = rotation ;
782
+
783
+ /**
784
+ * Rotates the given 3-by-3 matrix around the z-axis by the given
785
+ * angle.
786
+ * @param m - The matrix.
787
+ * @param angleInRadians - The angle by which to rotate (in radians).
788
+ * @param dst - matrix to hold result. If not passed a new one is created.
789
+ * @returns The rotated matrix.
790
+ */
791
+ const rotateZ = rotate ;
792
+
664
793
/**
665
794
* Creates a 3-by-3 matrix which scales in each dimension by an amount given by
666
795
* the corresponding entry in the given vector; assumes the vector has three
@@ -784,6 +913,12 @@ return {
784
913
translate,
785
914
rotation,
786
915
rotate,
916
+ rotationX,
917
+ rotateX,
918
+ rotationY,
919
+ rotateY,
920
+ rotationZ,
921
+ rotateZ,
787
922
scaling,
788
923
scale,
789
924
uniformScaling,
0 commit comments