[Bf-blender-cvs] [48d3a8b] master: Math Lib: inline project_plane_v3_v3v3

Campbell Barton noreply at git.blender.org
Tue May 3 06:01:39 CEST 2016


Commit: 48d3a8b54bf53a1562ceadc32af4cf0b8b1fc4b1
Author: Campbell Barton
Date:   Tue May 3 13:30:16 2016 +1000
Branches: master
https://developer.blender.org/rB48d3a8b54bf53a1562ceadc32af4cf0b8b1fc4b1

Math Lib: inline project_plane_v3_v3v3

===================================================================

M	source/blender/blenlib/intern/math_vector.c

===================================================================

diff --git a/source/blender/blenlib/intern/math_vector.c b/source/blender/blenlib/intern/math_vector.c
index 72a3da2..3e46432 100644
--- a/source/blender/blenlib/intern/math_vector.c
+++ b/source/blender/blenlib/intern/math_vector.c
@@ -591,19 +591,28 @@ void project_v3_v3v3(float c[3], const float v1[3], const float v2[3])
  * Projecting will make \a c a copy of \a v orthogonal to \a v_plane.
  *
  * \note If \a v is exactly perpendicular to \a v_plane, \a c will just be a copy of \a v.
+ *
+ * \note This function is a convenience to call:
+ * \code{.c}
+ * project_v3_v3v3(c, v, v_plane);
+ * sub_v3_v3v3(c, v, c);
+ * \endcode
  */
 void project_plane_v3_v3v3(float c[3], const float v[3], const float v_plane[3])
 {
-	float delta[3];
-	project_v3_v3v3(delta, v, v_plane);
-	sub_v3_v3v3(c, v, delta);
+	const float mul = dot_v3v3(v, v_plane) / dot_v3v3(v_plane, v_plane);
+
+	c[0] = v[0] - (mul * v_plane[0]);
+	c[1] = v[1] - (mul * v_plane[1]);
+	c[2] = v[2] - (mul * v_plane[2]);
 }
 
 void project_plane_v2_v2v2(float c[2], const float v[2], const float v_plane[2])
 {
-	float delta[2];
-	project_v2_v2v2(delta, v, v_plane);
-	sub_v2_v2v2(c, v, delta);
+	const float mul = dot_v2v2(v, v_plane) / dot_v2v2(v_plane, v_plane);
+
+	c[0] = v[0] - (mul * v_plane[0]);
+	c[1] = v[1] - (mul * v_plane[1]);
 }
 
 /* project a vector on a plane defined by normal and a plane point p */




More information about the Bf-blender-cvs mailing list