diff options
author | Lukas Tönne <lukas.toenne@gmail.com> | 2016-12-01 12:29:46 +0300 |
---|---|---|
committer | Lukas Tönne <lukas.toenne@gmail.com> | 2016-12-01 12:29:46 +0300 |
commit | ff2a74906a7b70625a4e941c6a805f7734491204 (patch) | |
tree | 562f5ccdd9f4e377d20fe22eadca48201924b4b3 /source/blender/blenlib/intern/math_matrix.c | |
parent | 73c1c92c0e86ce1b5a8abeaa16be2bf2c259412b (diff) | |
parent | 58877d6d082d82185ca611b704364168e5984bd7 (diff) |
Merge branch 'master' into blender2.8
Diffstat (limited to 'source/blender/blenlib/intern/math_matrix.c')
-rw-r--r-- | source/blender/blenlib/intern/math_matrix.c | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c index d95371b4ebc..50b92f5a383 100644 --- a/source/blender/blenlib/intern/math_matrix.c +++ b/source/blender/blenlib/intern/math_matrix.c @@ -1681,53 +1681,47 @@ void translate_m4(float mat[4][4], float Tx, float Ty, float Tz) } /* TODO: enum for axis? */ +/** + * Rotate a matrix in-place. + * + * \note To create a new rotation matrix see: + * #axis_angle_to_mat4_single, #axis_angle_to_mat3_single, #angle_to_mat2 + * (axis & angle args are compatible). + */ void rotate_m4(float mat[4][4], const char axis, const float angle) { - int col; - float temp[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - float cosine, sine; + const float angle_cos = cosf(angle); + const float angle_sin = sinf(angle); assert(axis >= 'X' && axis <= 'Z'); - cosine = cosf(angle); - sine = sinf(angle); switch (axis) { case 'X': - for (col = 0; col < 4; col++) - temp[col] = cosine * mat[1][col] + sine * mat[2][col]; - for (col = 0; col < 4; col++) { - mat[2][col] = -sine * mat[1][col] + cosine * mat[2][col]; - mat[1][col] = temp[col]; + for (int col = 0; col < 4; col++) { + float temp = angle_cos * mat[1][col] + angle_sin * mat[2][col]; + mat[2][col] = -angle_sin * mat[1][col] + angle_cos * mat[2][col]; + mat[1][col] = temp; } break; case 'Y': - for (col = 0; col < 4; col++) - temp[col] = cosine * mat[0][col] - sine * mat[2][col]; - for (col = 0; col < 4; col++) { - mat[2][col] = sine * mat[0][col] + cosine * mat[2][col]; - mat[0][col] = temp[col]; + for (int col = 0; col < 4; col++) { + float temp = angle_cos * mat[0][col] - angle_sin * mat[2][col]; + mat[2][col] = angle_sin * mat[0][col] + angle_cos * mat[2][col]; + mat[0][col] = temp; } break; case 'Z': - for (col = 0; col < 4; col++) - temp[col] = cosine * mat[0][col] + sine * mat[1][col]; - for (col = 0; col < 4; col++) { - mat[1][col] = -sine * mat[0][col] + cosine * mat[1][col]; - mat[0][col] = temp[col]; + for (int col = 0; col < 4; col++) { + float temp = angle_cos * mat[0][col] + angle_sin * mat[1][col]; + mat[1][col] = -angle_sin * mat[0][col] + angle_cos * mat[1][col]; + mat[0][col] = temp; } break; } } -void rotate_m2(float mat[2][2], const float angle) -{ - mat[0][0] = mat[1][1] = cosf(angle); - mat[0][1] = sinf(angle); - mat[1][0] = -mat[0][1]; -} - /** * Scale or rotate around a pivot point, * a convenience function to avoid having to do inline. |