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/python | |
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/python')
-rw-r--r-- | source/blender/python/api2_2x/vector.c | 31 |
1 files changed, 6 insertions, 25 deletions
diff --git a/source/blender/python/api2_2x/vector.c b/source/blender/python/api2_2x/vector.c index a7e00e2878a..6a0107142c1 100644 --- a/source/blender/python/api2_2x/vector.c +++ b/source/blender/python/api2_2x/vector.c @@ -277,19 +277,14 @@ PyObject *Vector_ToTrackQuat( VectorObject * self, PyObject * args ) /*----------------------------Vector.reflect(mirror) ---------------------- return a reflected vector on the mirror normal - ((2 * DotVecs(vec, mirror)) * mirror) - vec - using arithb.c would be nice here */ + vec - ((2 * DotVecs(vec, mirror)) * mirror) +*/ PyObject *Vector_Reflect( VectorObject * self, PyObject * value ) { VectorObject *mirrvec; float mirror[3]; float vec[3]; - float reflect[4] = {0.0f, 0.0f, 0.0f, 0.0f}; - float dot2; - - /* for normalizing */ - int i; - float norm = 0.0f; + float reflect[3] = {0.0f, 0.0f, 0.0f}; if (!VectorObject_Check(value)) { PyErr_SetString( PyExc_TypeError, "vec.reflect(value): expected a vector argument" ); @@ -302,27 +297,13 @@ PyObject *Vector_Reflect( VectorObject * self, PyObject * value ) if (mirrvec->size > 2) mirror[2] = mirrvec->vec[2]; else mirror[2] = 0.0; - /* normalize, whos idea was it not to use arithb.c? :-/ */ - for(i = 0; i < 3; i++) { - norm += mirror[i] * mirror[i]; - } - norm = (float) sqrt(norm); - for(i = 0; i < 3; i++) { - mirror[i] /= norm; - } - /* done */ - vec[0] = self->vec[0]; vec[1] = self->vec[1]; if (self->size > 2) vec[2] = self->vec[2]; else vec[2] = 0.0; - - dot2 = 2 * vec[0]*mirror[0]+vec[1]*mirror[1]+vec[2]*mirror[2]; - - reflect[0] = (dot2 * mirror[0]) - vec[0]; - reflect[1] = (dot2 * mirror[1]) - vec[1]; - reflect[2] = (dot2 * mirror[2]) - vec[2]; - + + VecReflect(reflect, vec, mirror); + return newVectorObject(reflect, self->size, Py_NEW); } |