fix poly clip and fix poly_remove_duplicate

This commit is contained in:
2018-11-29 23:13:04 +01:00
parent f64f157e82
commit d0919862da
5 changed files with 14 additions and 40 deletions

View File

@@ -878,7 +878,7 @@ void CanvasModeTransform::enter()
}
auto center = zw(canvas->m_box) * 0.5f;
glm::vec2 bb_sz = glm::vec2(aspect, 1.f) * 100.f;
glm::vec2 bb_sz = glm::vec2(aspect, 1.f) * 100.f * App::I.zoom;
glm::vec2 bb_min = center - bb_sz * 0.5f;
glm::vec2 bb_max = center + bb_sz * 0.5f;
glm::vec2 midpoint = (bb_min + bb_max) * 0.5f;
@@ -1141,48 +1141,17 @@ void CanvasModeTransform::leave()
poly_cam.reserve(m_points_face[j].size());
for (auto p : m_points_face[j])
poly_cam.push_back(mv * p.pos);
poly_cam = poly_clip_near(poly_cam, 0.01f);
auto poly_clipped = poly_clip_near(poly_cam, 0.01f);
for (int pi = 0; pi < poly_cam.size(); pi++)
for (auto p : poly_clipped)
{
auto p = poly_cam[pi];
auto p_clip = proj * glm::vec4(p, 1);
auto p_norm = p_clip / p_clip.w;
/*
// compute the next point
auto p_next = m_points_face[j][(pi + 1) % m_points_face[j].size()];
auto p_next_clip = mvp * p_next.pos;
auto p_next_norm = p_next_clip / p_next_clip.z;
// now test if there's a collision with on of the face edge
static glm::vec2 face_corners[4]{ {-1,1}, {1,1}, {1,-1}, {-1,-1} };
glm::vec2 poly_seg[2] = { xy(p_norm), xy(p_next_norm) };
bool edge_intersection = false;
for (int edge_i = 0; edge_i < 4; edge_i++)
{
glm::vec2 edge[2]{ face_corners[edge_i], face_corners[(edge_i + 1) % 4] };
glm::vec2 unused_pt, unused_uv;
if (segments_intersect(edge[0], edge[1], poly_seg[0], poly_seg[1], unused_pt, unused_uv))
{
edge_intersection = true;
break;
}
}
if (p_clip.w < 0 || glm::any(glm::greaterThan(glm::abs(xy(p_norm)), { 1, 1 })))
{
// now the point is outside, but will its edge cross the face?
if (!edge_intersection)
continue;
}
*/
if (p_clip.w < 0)
continue;
auto p_norm = p_clip / p_clip.w;
poly2d.push_back(p_norm);
}
}
auto clipped = poly_intersect(poly2d, face_corners);