[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36759] trunk/blender/source/blender: added math function isect_line_plane_v3(), use for window_to_3d rather then having it inline.
Campbell Barton
ideasman42 at gmail.com
Thu May 19 05:49:58 CEST 2011
Revision: 36759
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36759
Author: campbellbarton
Date: 2011-05-19 03:49:57 +0000 (Thu, 19 May 2011)
Log Message:
-----------
added math function isect_line_plane_v3(), use for window_to_3d rather then having it inline.
Modified Paths:
--------------
trunk/blender/source/blender/blenlib/BLI_math_geom.h
trunk/blender/source/blender/blenlib/intern/math_geom.c
trunk/blender/source/blender/editors/space_view3d/view3d_view.c
Modified: trunk/blender/source/blender/blenlib/BLI_math_geom.h
===================================================================
--- trunk/blender/source/blender/blenlib/BLI_math_geom.h 2011-05-19 01:40:37 UTC (rev 36758)
+++ trunk/blender/source/blender/blenlib/BLI_math_geom.h 2011-05-19 03:49:57 UTC (rev 36759)
@@ -96,6 +96,18 @@
int isect_ray_plane_v3(float p1[3], float d[3], float v0[3],
float v1[3], float v2[3], float *lambda, int clip);
+/**
+ * Definition of a callback routine that receives events.
+ * @param out The intersection point.
+ * @param l1 The first point of the line.
+ * @param l2 The second point of the line.
+ * @param plane_co A point on the plane to intersect with.
+ * @param plane_no The direction of the plane (does not need to be normalized).
+ * @param no_flip When true, the intersection point will always be from l1 to l2, even if this is not on the plane.
+ */
+int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3],
+ const float plane_co[3], const float plane_no[3], const short no_flip);
+
/* line/ray triangle */
int isect_line_tri_v3(const float p1[3], const float p2[3],
const float v0[3], const float v1[3], const float v2[3], float *lambda, float uv[2]);
Modified: trunk/blender/source/blender/blenlib/intern/math_geom.c
===================================================================
--- trunk/blender/source/blender/blenlib/intern/math_geom.c 2011-05-19 01:40:37 UTC (rev 36758)
+++ trunk/blender/source/blender/blenlib/intern/math_geom.c 2011-05-19 03:49:57 UTC (rev 36759)
@@ -37,8 +37,8 @@
#include "BLI_memarena.h"
#include "BLI_utildefines.h"
+static float lambda_cp_line(const float p[3], const float l1[3], const float l2[3]);
-
/********************************** Polygons *********************************/
void cent_tri_v3(float cent[3], const float v1[3], const float v2[3], const float v3[3])
@@ -640,7 +640,46 @@
return 1;
}
+int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3], const float plane_co[3], const float plane_no[3], const short no_flip)
+{
+ float l_vec[3]; /* line vector */
+ float p_no[3];
+ float dot;
+ sub_v3_v3v3(l_vec, l2, l1);
+
+ normalize_v3(l_vec);
+ normalize_v3_v3(p_no, plane_no);
+
+ /* for pradictable flipping */
+ dot= dot_v3v3(l_vec, p_no);
+ if(dot == 0.0f) {
+ return 0;
+ }
+ else {
+ float l1_plane[3]; /* line point aligne with the plane */
+ float dist;
+
+ if(dot < 0.0f) {
+ dot= -dot;
+ negate_v3(p_no);
+ }
+
+ add_v3_v3v3(l1_plane, l1, p_no);
+
+ dist = lambda_cp_line(plane_co, l1, l1_plane);
+ if(no_flip && dist < 0.0f) {
+ dist= -dist;
+ }
+
+ mul_v3_fl(l_vec, dist / dot);
+
+ add_v3_v3v3(out, l1, l_vec);
+
+ return 1;
+ }
+}
+
/* Adapted from the paper by Kasper Fauerby */
/* "Improved Collision detection and Response" */
static int getLowestRoot(const float a, const float b, const float c, const float maxR, float *root)
@@ -1075,16 +1114,14 @@
return lambda;
}
-#if 0
/* little sister we only need to know lambda */
-static float lambda_cp_line(float p[3], float l1[3], float l2[3])
+static float lambda_cp_line(const float p[3], const float l1[3], const float l2[3])
{
float h[3],u[3];
sub_v3_v3v3(u, l2, l1);
sub_v3_v3v3(h, p, l1);
return(dot_v3v3(u,h)/dot_v3v3(u,u));
}
-#endif
/* Similar to LineIntersectsTriangleUV, except it operates on a quad and in 2d, assumes point is in quad */
void isect_point_quad_uv_v2(const float v0[2], const float v1[2], const float v2[2], const float v3[2], const float pt[2], float *uv)
Modified: trunk/blender/source/blender/editors/space_view3d/view3d_view.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_view.c 2011-05-19 01:40:37 UTC (rev 36758)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_view.c 2011-05-19 03:49:57 UTC (rev 36759)
@@ -607,17 +607,14 @@
if(rv3d->is_persp) {
float mousevec[3];
- float view_z[3];
- float pt_mid[3];
-
+ copy_v3_v3(line_sta, rv3d->viewinv[3]);
window_to_3d_vector(ar, mousevec, mx, my);
+ add_v3_v3v3(line_end, line_sta, mousevec);
- copy_v3_v3(line_sta, rv3d->viewinv[3]);
- normalize_v3_v3(view_z, rv3d->viewinv[2]);
- add_v3_v3v3(line_end, line_sta, view_z);
- closest_to_line_v3(pt_mid, depth_pt, line_sta, line_end);
- mul_v3_fl(mousevec, shell_angle_to_dist(angle_normalized_v3v3(view_z, mousevec)) * len_v3v3(line_sta, pt_mid));
- add_v3_v3v3(out, line_sta, mousevec);
+ if(isect_line_plane_v3(out, line_sta, line_end, depth_pt, rv3d->viewinv[2], TRUE) == 0) {
+ /* highly unlikely to ever happen, mouse vec paralelle with view plane */
+ zero_v3(out);
+ }
}
else {
const float dx= (2.0f * (float)mx / (float)ar->winx) - 1.0f;
More information about the Bf-blender-cvs
mailing list