@@ -2815,6 +2815,30 @@ public static bool ComponentsEquals(this Vector4 vec)
28152815 return vec . X == vec . Y && vec . X == vec . Z && vec . X == vec . W ;
28162816 }
28172817
2818+ /// <summary>
2819+ /// Gets the column of a <see cref="Matrix4x4"/>.
2820+ /// </summary>
2821+ /// <param name="matrix">The <see cref="Matrix4x4"/>.</param>
2822+ /// <param name="index">The column index.</param>
2823+ /// <returns>The column.</returns>
2824+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
2825+ public static unsafe Vector4 GetColumn ( this Matrix4x4 matrix , int index )
2826+ {
2827+ if ( index < 0 || index > 3 )
2828+ throw new ArgumentOutOfRangeException ( nameof ( index ) , "Column index must be between 0 and 3." ) ;
2829+
2830+ // Unsafe pointer to the first element of the matrix
2831+ float * m = ( float * ) & matrix ;
2832+
2833+ Vector4 column ;
2834+ column . X = m [ index + 0 * 4 ] ;
2835+ column . Y = m [ index + 1 * 4 ] ;
2836+ column . Z = m [ index + 2 * 4 ] ;
2837+ column . W = m [ index + 3 * 4 ] ;
2838+
2839+ return column ;
2840+ }
2841+
28182842 /// <summary>
28192843 /// Gets the row of a <see cref="Matrix4x4"/>.
28202844 /// </summary>
@@ -2825,17 +2849,18 @@ public static bool ComponentsEquals(this Vector4 vec)
28252849 public static unsafe Vector4 GetRow ( this Matrix4x4 matrix , int index )
28262850 {
28272851 if ( index < 0 || index > 3 )
2852+ {
28282853 throw new ArgumentOutOfRangeException ( nameof ( index ) , "Row index must be between 0 and 3." ) ;
2854+ }
28292855
28302856 // Unsafe pointer to the first element of the matrix
28312857 float * m = ( float * ) & matrix ;
28322858
28332859 Vector4 row ;
2834- row . X = m [ index + 0 * 4 ] ; // First column
2835- row . Y = m [ index + 1 * 4 ] ; // Second column
2836- row . Z = m [ index + 2 * 4 ] ; // Third column
2837- row . W = m [ index + 3 * 4 ] ; // Fourth column
2838-
2860+ row . X = m [ index * 4 + 0 ] ;
2861+ row . Y = m [ index * 4 + 1 ] ;
2862+ row . Z = m [ index * 4 + 2 ] ;
2863+ row . W = m [ index * 4 + 3 ] ;
28392864 return row ;
28402865 }
28412866
0 commit comments