diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-19 03:07:27 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-19 03:07:27 +0400 |
commit | 32ce3a6ca72b4d7f0c7cd447a2077ac1dc60d167 (patch) | |
tree | 8c4e7057358322f7d6bdb83def8d7e099ef5e2aa | |
parent | b7a2402da68accb283314bc7929d037e1a115da9 (diff) |
utility vector functions for flipping one vector about another:
nicer then interp_v3_v3v3(v, v1, v2, -1.0f);
-rw-r--r-- | source/blender/blenlib/BLI_math_vector.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_vector.c | 26 |
2 files changed, 30 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h index f4572afec84..e9217728eae 100644 --- a/source/blender/blenlib/BLI_math_vector.h +++ b/source/blender/blenlib/BLI_math_vector.h @@ -171,6 +171,10 @@ void mid_v3_v3v3(float r[3], const float a[3], const float b[3]); void mid_v2_v2v2(float r[2], const float a[2], const float b[2]); void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v3[3]); +void flip_v4_v4v4(float v[4], const float v1[4], const float v2[4]); +void flip_v3_v3v3(float v[3], const float v1[3], const float v2[3]); +void flip_v2_v2v2(float v[2], const float v1[2], const float v2[2]); + /********************************* Comparison ********************************/ MINLINE int is_zero_v3(const float a[3]); diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c index 812e2b3e63d..743d1fc497b 100644 --- a/source/blender/blenlib/intern/math_vector.c +++ b/source/blender/blenlib/intern/math_vector.c @@ -122,6 +122,32 @@ void mid_v3_v3v3v3(float v[3], const float v1[3], const float v2[3], const float v[2] = (v1[2] + v2[2] + v3[2]) / 3.0f; } +/** + * Equivalent to: + * interp_v3_v3v3(v, v1, v2, -1.0f); + */ + +void flip_v4_v4v4(float v[4], const float v1[4], const float v2[4]) +{ + v[0] = v1[0] + (v1[0] - v2[0]); + v[1] = v1[1] + (v1[1] - v2[1]); + v[2] = v1[2] + (v1[2] - v2[2]); + v[3] = v1[3] + (v1[3] - v2[3]); +} + +void flip_v3_v3v3(float v[3], const float v1[3], const float v2[3]) +{ + v[0] = v1[0] + (v1[0] - v2[0]); + v[1] = v1[1] + (v1[1] - v2[1]); + v[2] = v1[2] + (v1[2] - v2[2]); +} + +void flip_v2_v2v2(float v[2], const float v1[2], const float v2[2]) +{ + v[0] = v1[0] + (v1[0] - v2[0]); + v[1] = v1[1] + (v1[1] - v2[1]); +} + /********************************** Angles ***********************************/ /* Return the angle in radians between vecs 1-2 and 2-3 in radians |