Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/blenlib/BLI_arithb.h1
-rw-r--r--source/blender/blenlib/intern/arithb.c23
-rw-r--r--source/blender/python/api2_2x/vector.c31
3 files changed, 30 insertions, 25 deletions
diff --git a/source/blender/blenlib/BLI_arithb.h b/source/blender/blenlib/BLI_arithb.h
index 86b626dabdf..0c3ec40f16d 100644
--- a/source/blender/blenlib/BLI_arithb.h
+++ b/source/blender/blenlib/BLI_arithb.h
@@ -270,6 +270,7 @@ void AxisAngleToQuat(float *q, float *axis, float angle);
void RotationBetweenVectorsToQuat(float *q, float v1[3], float v2[3]);
void vectoquat(float *vec, short axis, short upflag, float *q);
+void VecReflect(float *out, float *v1, float *v2);
void VecBisect3(float *v, float *v1, float *v2, float *v3);
float VecAngle2(float *v1, float *v2);
float VecAngle3(float *v1, float *v2, float *v3);
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 */
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);
}