diff options
author | Dalai Felinto <dfelinto@gmail.com> | 2009-09-08 07:25:00 +0400 |
---|---|---|
committer | Dalai Felinto <dfelinto@gmail.com> | 2009-09-08 07:25:00 +0400 |
commit | f7deb2046e5905e46cebac97916679caf0484c17 (patch) | |
tree | b24f993313450ba5c64dab42c3b264dfdea3ea8f | |
parent | 6808e15c8d20819deddd6b175668d11a6c6f454d (diff) | |
parent | 7064f6c5d88e17406df1c7c8d1fec20364571084 (diff) |
manual merge trunk -r 23037
strangely vector.c was skipped in last merge from trunk.
-----------------------------------
Mathutils fix: Vector.reflect
* correct function for reflection and moving it to arithb.c
-rw-r--r-- | source/blender/python/generic/vector.c | 30 |
1 files changed, 5 insertions, 25 deletions
diff --git a/source/blender/python/generic/vector.c b/source/blender/python/generic/vector.c index 46a0df4ae4d..605f45be128 100644 --- a/source/blender/python/generic/vector.c +++ b/source/blender/python/generic/vector.c @@ -354,18 +354,12 @@ static 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) +*/ static PyObject *Vector_Reflect( VectorObject * self, VectorObject * value ) { - 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 mirror[3], vec[3]; + float reflect[3] = {0.0f, 0.0f, 0.0f}; if (!VectorObject_Check(value)) { PyErr_SetString( PyExc_TypeError, "vec.reflect(value): expected a vector argument" ); @@ -380,26 +374,12 @@ static PyObject *Vector_Reflect( VectorObject * self, VectorObject * value ) if (value->size > 2) mirror[2] = value->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, NULL); } |