@@ -2815,6 +2815,30 @@ public static bool ComponentsEquals(this Vector4 vec)
2815
2815
return vec . X == vec . Y && vec . X == vec . Z && vec . X == vec . W ;
2816
2816
}
2817
2817
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
+
2818
2842
/// <summary>
2819
2843
/// Gets the row of a <see cref="Matrix4x4"/>.
2820
2844
/// </summary>
@@ -2825,17 +2849,18 @@ public static bool ComponentsEquals(this Vector4 vec)
2825
2849
public static unsafe Vector4 GetRow ( this Matrix4x4 matrix , int index )
2826
2850
{
2827
2851
if ( index < 0 || index > 3 )
2852
+ {
2828
2853
throw new ArgumentOutOfRangeException ( nameof ( index ) , "Row index must be between 0 and 3." ) ;
2854
+ }
2829
2855
2830
2856
// Unsafe pointer to the first element of the matrix
2831
2857
float * m = ( float * ) & matrix ;
2832
2858
2833
2859
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 ] ;
2839
2864
return row ;
2840
2865
}
2841
2866
0 commit comments