diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2009-09-06 23:51:57 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2009-09-06 23:51:57 +0400 |
commit | 7064f6c5d88e17406df1c7c8d1fec20364571084 (patch) | |
tree | e3f99a691e5a7b24c5c375b47547f26b47146acc /source/blender/blenlib/intern/arithb.c | |
parent | a46beac3f87ee78d6231b2f0038db31c50aa2315 (diff) |
Mathutils fix: Vector.reflect
* correct function for reflection and moving it to arithb.c
* note: 2.5 has an already more elegant solution for it (still wrong, but the code is cleaner).
Therefore the merge may need to be manual in that case.
Specifically in 2.5 we are doing:
if(!BaseMath_ReadCallback(self) || !BaseMath_ReadCallback(value)) return NULL;
And there we don't need to create a VectorObject *mirrvec; only to get the values.
Code used to test it:
http://www.pasteall.org/7654/python
* YoFrankie script probably needs to be fixed too.
Diffstat (limited to 'source/blender/blenlib/intern/arithb.c')
-rw-r--r-- | source/blender/blenlib/intern/arithb.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/source/blender/blenlib/intern/arithb.c b/source/blender/blenlib/intern/arithb.c index c20794953b9..e7a31e37581 100644 --- a/source/blender/blenlib/intern/arithb.c +++ b/source/blender/blenlib/intern/arithb.c @@ -2981,6 +2981,29 @@ void VecBisect3(float *out, float *v1, float *v2, float *v3) Normalize(out); } +/* Returns a reflection vector from a vector and a normal vector +reflect = vec - ((2 * DotVecs(vec, mirror)) * mirror) +*/ +void VecReflect(float *out, float *v1, float *v2) +{ + float vec[3], normal[3]; + float reflect[3] = {0.0f, 0.0f, 0.0f}; + float dot2; + + VecCopyf(vec, v1); + VecCopyf(normal, v2); + + Normalize(normal); + + dot2 = 2 * Inpf(vec, normal); + + reflect[0] = vec[0] - (dot2 * normal[0]); + reflect[1] = vec[1] - (dot2 * normal[1]); + reflect[2] = vec[2] - (dot2 * normal[2]); + + VecCopyf(out, reflect); +} + /* Return the angle in degrees between vecs 1-2 and 2-3 in degrees If v1 is a shoulder, v2 is the elbow and v3 is the hand, this would return the angle at the elbow */ |