From c993ee678a3438a26c263a78ade71f8013f03160 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 13 Nov 2011 16:28:52 +0000 Subject: new math utility function isect_plane_plane_v3 --- source/blender/blenlib/BLI_math_geom.h | 23 +++++++++++++++++++--- source/blender/blenlib/intern/math_geom.c | 23 +++++++++++++++++++++- source/blender/blenlib/intern/math_vector_inline.c | 6 +++--- source/blender/makesrna/intern/rna_modifier.c | 4 ++-- .../blender/python/mathutils/mathutils_geometry.c | 1 + 5 files changed, 48 insertions(+), 9 deletions(-) (limited to 'source/blender') diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 99687ae8bb4..5c92d15c440 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -60,7 +60,7 @@ float dist_to_line_v2(const float p[2], const float l1[2], const float l2[2]); float dist_to_line_segment_v2(const float p[2], const float l1[2], const float l2[2]); void closest_to_line_segment_v2(float closest[2], const float p[2], const float l1[2], const float l2[2]); -float dist_to_plane_v3(const float p[2], const float plane_co[3], const float plane_no[2]); +float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3]); float dist_to_line_segment_v3(const float p[3], const float l1[3], const float l2[3]); float closest_to_line_v3(float r[3], const float p[3], const float l1[3], const float l2[3]); float closest_to_line_v2(float r[2], const float p[2], const float l1[2], const float l2[2]); @@ -92,9 +92,11 @@ int isect_seg_seg_v2_point(const float v1[2], const float v2[2], const float v3[ * */ int isect_line_line_v3(const float v1[3], const float v2[3], - const float v3[3], const float v4[3], float i1[3], float i2[3]); + const float v3[3], const float v4[3], + float i1[3], float i2[3]); int isect_line_line_strict_v3(const float v1[3], const float v2[3], - const float v3[3], const float v4[3], float vi[3], float *lambda); + const float v3[3], const float v4[3], + float vi[3], float *lambda); /*if clip is nonzero, will only return true if lambda is >= 0.0 (i.e. intersection point is along positive d)*/ @@ -113,6 +115,21 @@ int isect_ray_plane_v3(float p1[3], float d[3], float v0[3], 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); +/** + * Intersect two planes, return a point on the intersection and a vector + * that runs on the direction of the intersection. + * Return error code is the same as 'isect_line_line_v3'. + * @param r_isect_co The resulting intersection point. + * @param r_isect_no The resulting vector of the intersection. + * @param plane_a_co The point on the first plane. + * @param plane_a_no The normal of the first plane. + * @param plane_b_co The point on the second plane. + * @param plane_b_no The normal of the second plane. + */ +int isect_plane_plane_v3(float r_isect_co[3], float r_isect_no[3], + const float plane_a_co[3], const float plane_a_no[3], + const float plane_b_co[3], const float plane_b_no[3]); + /* 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]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index a135cb43882..6fc3891d1bd 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -238,7 +238,7 @@ void closest_to_line_segment_v3(float closest[3], const float v1[3], const float } /* signed distance from the point to the plane in 3D */ -float dist_to_plane_v3(const float p[2], const float plane_co[3], const float plane_no[2]) +float dist_to_plane_v3(const float p[3], const float plane_co[3], const float plane_no[3]) { float plane_no_unit[3]; float plane_co_other[3]; @@ -833,6 +833,27 @@ int isect_line_plane_v3(float out[3], const float l1[3], const float l2[3], cons } } +int isect_plane_plane_v3(float r_isect_co[3], float r_isect_no[3], + const float plane_a_co[3], const float plane_a_no[3], + const float plane_b_co[3], const float plane_b_no[3]) +{ + float p1_co_other[3], p2_co_other[3]; + float isect_co_dummy[3]; + + cross_v3_v3v3(r_isect_no, plane_a_no, plane_b_no); + cross_v3_v3v3(p1_co_other, plane_a_no, r_isect_no); + cross_v3_v3v3(p2_co_other, plane_b_no, r_isect_no); + + add_v3_v3(p1_co_other, plane_a_co); + add_v3_v3(p2_co_other, plane_b_co); + + /* we could use either ix_1, ix_2 - doesnt matter in this case */ + return isect_line_line_v3(plane_a_co, p1_co_other, + plane_b_co, p2_co_other, + r_isect_co, isect_co_dummy); +} + + /* 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) diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c index 1c7d131c750..4570bd5e99e 100644 --- a/source/blender/blenlib/intern/math_vector_inline.c +++ b/source/blender/blenlib/intern/math_vector_inline.c @@ -181,19 +181,19 @@ MINLINE void add_v4_fl(float r[4], float f) r[3] += f; } -MINLINE void add_v2_v2(float *r, const float *a) +MINLINE void add_v2_v2(float r[2], const float a[2]) { r[0] += a[0]; r[1] += a[1]; } -MINLINE void add_v2_v2v2(float *r, const float *a, const float *b) +MINLINE void add_v2_v2v2(float r[2], const float a[2], const float b[2]) { r[0]= a[0] + b[0]; r[1]= a[1] + b[1]; } -MINLINE void add_v3_v3(float *r, const float *a) +MINLINE void add_v3_v3(float r[3], const float a[3]) { r[0] += a[0]; r[1] += a[1]; diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c index b50f755b6c7..0752a781ca7 100644 --- a/source/blender/makesrna/intern/rna_modifier.c +++ b/source/blender/makesrna/intern/rna_modifier.c @@ -695,8 +695,8 @@ static void rna_OceanModifier_ocean_chop_set(PointerRNA *ptr, float value) omd->chop_amount = value; - if ((old_value == 0.0 && value > 0.0) || - (old_value > 0.0 && value == 0.0)) + if ((old_value == 0.0f && value > 0.0f) || + (old_value > 0.0f && value == 0.0f)) { omd->refresh |= MOD_OCEAN_REFRESH_RESET; omd->refresh |= MOD_OCEAN_REFRESH_CLEAR_CACHE; diff --git a/source/blender/python/mathutils/mathutils_geometry.c b/source/blender/python/mathutils/mathutils_geometry.c index c2487db707c..dfa1c98b94b 100644 --- a/source/blender/python/mathutils/mathutils_geometry.c +++ b/source/blender/python/mathutils/mathutils_geometry.c @@ -1213,6 +1213,7 @@ static PyMethodDef M_Geometry_methods[]= { {"intersect_line_line", (PyCFunction) M_Geometry_intersect_line_line, METH_VARARGS, M_Geometry_intersect_line_line_doc}, {"intersect_line_line_2d", (PyCFunction) M_Geometry_intersect_line_line_2d, METH_VARARGS, M_Geometry_intersect_line_line_2d_doc}, {"intersect_line_plane", (PyCFunction) M_Geometry_intersect_line_plane, METH_VARARGS, M_Geometry_intersect_line_plane_doc}, + /* TODO: isect_plane_plane_v3 --> intersect_plane_plane */ {"intersect_line_sphere", (PyCFunction) M_Geometry_intersect_line_sphere, METH_VARARGS, M_Geometry_intersect_line_sphere_doc}, {"intersect_line_sphere_2d", (PyCFunction) M_Geometry_intersect_line_sphere_2d, METH_VARARGS, M_Geometry_intersect_line_sphere_2d_doc}, {"distance_point_to_plane", (PyCFunction) M_Geometry_distance_point_to_plane, METH_VARARGS, M_Geometry_distance_point_to_plane_doc}, -- cgit v1.2.3