add utility functions for dealing with planes
- plane_point_side_v3(), a bit like line_point_side_v2() - isect_point_planes_v3(), moved from paint_hide.c functions to convert between point/normal pairs. - plane_from_point_normal_v3() - plane_to_point_normal_v3()
This commit is contained in:
@@ -61,6 +61,14 @@ float area_quad_v3(const float a[3], const float b[3], const float c[3], const f
|
||||
float area_poly_v3(int nr, float verts[][3], const float normal[3]);
|
||||
float area_poly_v2(int nr, float verts[][2]);
|
||||
|
||||
/********************************* Planes **********************************/
|
||||
|
||||
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3]);
|
||||
void plane_to_point_normal_v3(const float plane[4], float r_plane_co[3], float r_plane_no[3]);
|
||||
MINLINE float plane_point_side_v3(const float plane[4], const float co[3]);
|
||||
|
||||
/********************************* Volume **********************************/
|
||||
|
||||
float volume_tetrahedron_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
|
||||
|
||||
int is_quad_convex_v3(const float v1[3], const float v2[3], const float v3[3], const float v4[3]);
|
||||
@@ -120,6 +128,7 @@ bool isect_ray_plane_v3(const float p1[3], const float d[3],
|
||||
const float v0[3], const float v1[3], const float v2[3],
|
||||
float *r_lambda, const int clip);
|
||||
|
||||
bool isect_point_planes_v3(float (*planes)[4], int totplane, const float p[3]);
|
||||
bool 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 bool no_flip);
|
||||
|
||||
|
||||
@@ -183,6 +183,28 @@ float area_poly_v2(int nr, float verts[][2])
|
||||
return fabsf(0.5f * area);
|
||||
}
|
||||
|
||||
/********************************* Planes **********************************/
|
||||
|
||||
/**
|
||||
* Calculate a plane from a point and a direction,
|
||||
* \note \a point_no isn't required to be normalized.
|
||||
*/
|
||||
void plane_from_point_normal_v3(float r_plane[4], const float plane_co[3], const float plane_no[3])
|
||||
{
|
||||
copy_v3_v3(r_plane, plane_no);
|
||||
r_plane[3] = -dot_v3v3(r_plane, plane_co);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a point and a normal from a plane.
|
||||
*/
|
||||
void plane_to_point_normal_v3(const float plane[4], float r_plane_co[3], float r_plane_no[3])
|
||||
{
|
||||
const float length = normalize_v3_v3(r_plane_no, plane);
|
||||
madd_v3_v3v3fl(r_plane_co, r_plane_no, r_plane_no, (-plane[3] / length) - 1.0f);
|
||||
}
|
||||
|
||||
|
||||
/********************************* Volume **********************************/
|
||||
|
||||
/**
|
||||
@@ -1042,6 +1064,22 @@ bool isect_ray_tri_threshold_v3(const float p1[3], const float d[3],
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a point is behind all planes.
|
||||
*/
|
||||
bool isect_point_planes_v3(float (*planes)[4], int totplane, const float p[3])
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < totplane; i++) {
|
||||
if (plane_point_side_v3(planes[i], p) > 0.0f) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Intersect line/plane, optionally treat line as directional (like a ray) with the no_flip argument.
|
||||
*
|
||||
@@ -1757,7 +1795,7 @@ bool clip_segment_v3_plane(float p1[3], float p2[3], const float plane[4])
|
||||
if (div == 0.0f) /* parallel */
|
||||
return 1;
|
||||
|
||||
t = -(dot_v3v3(p1, plane) + plane[3]) / div;
|
||||
t = -plane_point_side_v3(plane, p1) / div;
|
||||
|
||||
if (div > 0.0f) {
|
||||
/* behind plane, completely clipped */
|
||||
@@ -1811,7 +1849,7 @@ bool clip_segment_v3_plane_n(float r_p1[3], float r_p2[3], float plane_array[][4
|
||||
const float div = dot_v3v3(dp, plane);
|
||||
|
||||
if (div != 0.0f) {
|
||||
const float t = -(dot_v3v3(p1, plane) + plane[3]) / div;
|
||||
const float t = -plane_point_side_v3(plane, p1) / div;
|
||||
if (div > 0.0f) {
|
||||
/* clip a */
|
||||
if (t >= 1.0f) {
|
||||
@@ -3616,4 +3654,3 @@ int is_quad_convex_v2(const float v1[2], const float v2[2], const float v3[2], c
|
||||
/* linetests, the 2 diagonals have to instersect to be convex */
|
||||
return (isect_line_line_v2(v1, v3, v2, v4) > 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -185,4 +185,9 @@ MINLINE int poly_to_tri_count(const int poly_count, const int corner_count)
|
||||
}
|
||||
}
|
||||
|
||||
MINLINE float plane_point_side_v3(const float plane[4], const float co[3])
|
||||
{
|
||||
return dot_v3v3(co, plane) + plane[3];
|
||||
}
|
||||
|
||||
#endif /* __MATH_GEOM_INLINE_C__ */
|
||||
|
||||
@@ -71,18 +71,6 @@
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static int planes_contain_v3(float (*planes)[4], int totplane, const float p[3])
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < totplane; i++) {
|
||||
if (dot_v3v3(planes[i], p) + planes[i][3] > 0)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* return true if the element should be hidden/shown */
|
||||
static int is_effected(PartialVisArea area,
|
||||
float planes[4][4],
|
||||
@@ -95,7 +83,7 @@ static int is_effected(PartialVisArea area,
|
||||
return mask > 0.5f;
|
||||
}
|
||||
else {
|
||||
int inside = planes_contain_v3(planes, 4, co);
|
||||
bool inside = isect_point_planes_v3(planes, 4, co);
|
||||
return ((inside && area == PARTIALVIS_INSIDE) ||
|
||||
(!inside && area == PARTIALVIS_OUTSIDE));
|
||||
}
|
||||
|
||||
@@ -220,10 +220,10 @@ void ED_view3d_clipping_enable(void)
|
||||
|
||||
static bool view3d_clipping_test(const float co[3], float clip[6][4])
|
||||
{
|
||||
if (0.0f < clip[0][3] + dot_v3v3(co, clip[0]))
|
||||
if (0.0f < clip[1][3] + dot_v3v3(co, clip[1]))
|
||||
if (0.0f < clip[2][3] + dot_v3v3(co, clip[2]))
|
||||
if (0.0f < clip[3][3] + dot_v3v3(co, clip[3]))
|
||||
if (plane_point_side_v3(clip[0], co) > 0.0f)
|
||||
if (plane_point_side_v3(clip[1], co) > 0.0f)
|
||||
if (plane_point_side_v3(clip[2], co) > 0.0f)
|
||||
if (plane_point_side_v3(clip[3], co) > 0.0f)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user