11/*
2- HandmadeMath.h v1.6 .0
2+ HandmadeMath.h v1.7 .0
33
44 This is a single header file with a bunch of useful functions for game and
55 graphics math operations.
172172 (*) Added array subscript operators for vector and matrix types in
173173 C++. This is provided as a convenience, but be aware that it may
174174 incur an extra function call in unoptimized builds.
175+ 1.7.0
176+ (*) Renamed the 'Rows' member of hmm_mat4 to 'Columns'. Since our
177+ matrices are column-major, this should have been named 'Columns'
178+ from the start. 'Rows' is still present, but has been deprecated.
175179
176180
177181 LICENSE
@@ -447,6 +451,10 @@ typedef union hmm_mat4
447451 float Elements [4 ][4 ];
448452
449453#ifdef HANDMADE_MATH__USE_SSE
454+ __m128 Columns [4 ];
455+
456+ // DEPRECATED. Our matrices are column-major, so this was named
457+ // incorrectly. Use Columns instead.
450458 __m128 Rows [4 ];
451459#endif
452460
@@ -1129,10 +1137,10 @@ HMM_INLINE hmm_vec4 HMM_NormalizeVec4(hmm_vec4 A)
11291137HMM_INLINE __m128 HMM_LinearCombineSSE (__m128 Left , hmm_mat4 Right )
11301138{
11311139 __m128 Result ;
1132- Result = _mm_mul_ps (_mm_shuffle_ps (Left , Left , 0x00 ), Right .Rows [0 ]);
1133- Result = _mm_add_ps (Result , _mm_mul_ps (_mm_shuffle_ps (Left , Left , 0x55 ), Right .Rows [1 ]));
1134- Result = _mm_add_ps (Result , _mm_mul_ps (_mm_shuffle_ps (Left , Left , 0xaa ), Right .Rows [2 ]));
1135- Result = _mm_add_ps (Result , _mm_mul_ps (_mm_shuffle_ps (Left , Left , 0xff ), Right .Rows [3 ]));
1140+ Result = _mm_mul_ps (_mm_shuffle_ps (Left , Left , 0x00 ), Right .Columns [0 ]);
1141+ Result = _mm_add_ps (Result , _mm_mul_ps (_mm_shuffle_ps (Left , Left , 0x55 ), Right .Columns [1 ]));
1142+ Result = _mm_add_ps (Result , _mm_mul_ps (_mm_shuffle_ps (Left , Left , 0xaa ), Right .Columns [2 ]));
1143+ Result = _mm_add_ps (Result , _mm_mul_ps (_mm_shuffle_ps (Left , Left , 0xff ), Right .Columns [3 ]));
11361144
11371145 return (Result );
11381146}
@@ -1167,7 +1175,7 @@ HMM_INLINE hmm_mat4 HMM_Transpose(hmm_mat4 Matrix)
11671175{
11681176 hmm_mat4 Result = Matrix ;
11691177
1170- _MM_TRANSPOSE4_PS (Result .Rows [0 ], Result .Rows [1 ], Result .Rows [2 ], Result .Rows [3 ]);
1178+ _MM_TRANSPOSE4_PS (Result .Columns [0 ], Result .Columns [1 ], Result .Columns [2 ], Result .Columns [3 ]);
11711179
11721180 return (Result );
11731181}
@@ -1180,10 +1188,10 @@ HMM_INLINE hmm_mat4 HMM_AddMat4(hmm_mat4 Left, hmm_mat4 Right)
11801188{
11811189 hmm_mat4 Result ;
11821190
1183- Result .Rows [0 ] = _mm_add_ps (Left .Rows [0 ], Right .Rows [0 ]);
1184- Result .Rows [1 ] = _mm_add_ps (Left .Rows [1 ], Right .Rows [1 ]);
1185- Result .Rows [2 ] = _mm_add_ps (Left .Rows [2 ], Right .Rows [2 ]);
1186- Result .Rows [3 ] = _mm_add_ps (Left .Rows [3 ], Right .Rows [3 ]);
1191+ Result .Columns [0 ] = _mm_add_ps (Left .Columns [0 ], Right .Columns [0 ]);
1192+ Result .Columns [1 ] = _mm_add_ps (Left .Columns [1 ], Right .Columns [1 ]);
1193+ Result .Columns [2 ] = _mm_add_ps (Left .Columns [2 ], Right .Columns [2 ]);
1194+ Result .Columns [3 ] = _mm_add_ps (Left .Columns [3 ], Right .Columns [3 ]);
11871195
11881196 return (Result );
11891197}
@@ -1196,10 +1204,10 @@ HMM_INLINE hmm_mat4 HMM_SubtractMat4(hmm_mat4 Left, hmm_mat4 Right)
11961204{
11971205 hmm_mat4 Result ;
11981206
1199- Result .Rows [0 ] = _mm_sub_ps (Left .Rows [0 ], Right .Rows [0 ]);
1200- Result .Rows [1 ] = _mm_sub_ps (Left .Rows [1 ], Right .Rows [1 ]);
1201- Result .Rows [2 ] = _mm_sub_ps (Left .Rows [2 ], Right .Rows [2 ]);
1202- Result .Rows [3 ] = _mm_sub_ps (Left .Rows [3 ], Right .Rows [3 ]);
1207+ Result .Columns [0 ] = _mm_sub_ps (Left .Columns [0 ], Right .Columns [0 ]);
1208+ Result .Columns [1 ] = _mm_sub_ps (Left .Columns [1 ], Right .Columns [1 ]);
1209+ Result .Columns [2 ] = _mm_sub_ps (Left .Columns [2 ], Right .Columns [2 ]);
1210+ Result .Columns [3 ] = _mm_sub_ps (Left .Columns [3 ], Right .Columns [3 ]);
12031211
12041212 return (Result );
12051213}
@@ -1215,10 +1223,10 @@ HMM_INLINE hmm_mat4 HMM_MultiplyMat4f(hmm_mat4 Matrix, float Scalar)
12151223 hmm_mat4 Result ;
12161224
12171225 __m128 SSEScalar = _mm_set1_ps (Scalar );
1218- Result .Rows [0 ] = _mm_mul_ps (Matrix .Rows [0 ], SSEScalar );
1219- Result .Rows [1 ] = _mm_mul_ps (Matrix .Rows [1 ], SSEScalar );
1220- Result .Rows [2 ] = _mm_mul_ps (Matrix .Rows [2 ], SSEScalar );
1221- Result .Rows [3 ] = _mm_mul_ps (Matrix .Rows [3 ], SSEScalar );
1226+ Result .Columns [0 ] = _mm_mul_ps (Matrix .Columns [0 ], SSEScalar );
1227+ Result .Columns [1 ] = _mm_mul_ps (Matrix .Columns [1 ], SSEScalar );
1228+ Result .Columns [2 ] = _mm_mul_ps (Matrix .Columns [2 ], SSEScalar );
1229+ Result .Columns [3 ] = _mm_mul_ps (Matrix .Columns [3 ], SSEScalar );
12221230
12231231 return (Result );
12241232}
@@ -1234,10 +1242,10 @@ HMM_INLINE hmm_mat4 HMM_DivideMat4f(hmm_mat4 Matrix, float Scalar)
12341242 hmm_mat4 Result ;
12351243
12361244 __m128 SSEScalar = _mm_set1_ps (Scalar );
1237- Result .Rows [0 ] = _mm_div_ps (Matrix .Rows [0 ], SSEScalar );
1238- Result .Rows [1 ] = _mm_div_ps (Matrix .Rows [1 ], SSEScalar );
1239- Result .Rows [2 ] = _mm_div_ps (Matrix .Rows [2 ], SSEScalar );
1240- Result .Rows [3 ] = _mm_div_ps (Matrix .Rows [3 ], SSEScalar );
1245+ Result .Columns [0 ] = _mm_div_ps (Matrix .Columns [0 ], SSEScalar );
1246+ Result .Columns [1 ] = _mm_div_ps (Matrix .Columns [1 ], SSEScalar );
1247+ Result .Columns [2 ] = _mm_div_ps (Matrix .Columns [2 ], SSEScalar );
1248+ Result .Columns [3 ] = _mm_div_ps (Matrix .Columns [3 ], SSEScalar );
12411249
12421250 return (Result );
12431251}
@@ -2252,10 +2260,10 @@ hmm_mat4 HMM_MultiplyMat4(hmm_mat4 Left, hmm_mat4 Right)
22522260
22532261#ifdef HANDMADE_MATH__USE_SSE
22542262
2255- Result .Rows [0 ] = HMM_LinearCombineSSE (Right .Rows [0 ], Left );
2256- Result .Rows [1 ] = HMM_LinearCombineSSE (Right .Rows [1 ], Left );
2257- Result .Rows [2 ] = HMM_LinearCombineSSE (Right .Rows [2 ], Left );
2258- Result .Rows [3 ] = HMM_LinearCombineSSE (Right .Rows [3 ], Left );
2263+ Result .Columns [0 ] = HMM_LinearCombineSSE (Right .Columns [0 ], Left );
2264+ Result .Columns [1 ] = HMM_LinearCombineSSE (Right .Columns [1 ], Left );
2265+ Result .Columns [2 ] = HMM_LinearCombineSSE (Right .Columns [2 ], Left );
2266+ Result .Columns [3 ] = HMM_LinearCombineSSE (Right .Columns [3 ], Left );
22592267
22602268#else
22612269 int Columns ;
0 commit comments