clip the polygon when applying the transform shape
This commit is contained in:
@@ -102,7 +102,7 @@ target_include_directories(native-lib PRIVATE
|
||||
../libs/yoga
|
||||
../libs/stb
|
||||
../libs/jpeg
|
||||
../libs/curl-android-ios/prebuilt-with-ssl/android/include
|
||||
../libs/curl-android-ios/android/android/include
|
||||
../libs/poly2tri/poly2tri
|
||||
../libs/base64
|
||||
)
|
||||
@@ -112,7 +112,7 @@ target_link_libraries(
|
||||
native-lib
|
||||
android
|
||||
app-glue
|
||||
${CMAKE_SOURCE_DIR}/../libs/curl-android-ios/prebuilt-with-ssl/android/armeabi-v7a/libcurl.a
|
||||
${CMAKE_SOURCE_DIR}/../libs/curl-android-ios/android/android/armeabi-v7a/libcurl.a
|
||||
EGL
|
||||
GLESv3
|
||||
log
|
||||
|
||||
@@ -10,7 +10,7 @@ buildscript {
|
||||
}
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.2.0'
|
||||
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||
classpath "gradle.plugin.com.gladed.gradle.androidgitversion:gradle-android-git-version:0.4.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1122,32 +1122,80 @@ void CanvasModeTransform::leave()
|
||||
for (int i = 0; i < 6; i++)
|
||||
{
|
||||
auto plane_camera = glm::lookAt(glm::vec3(0), canvas->m_plane_origin[i], canvas->m_plane_tangent[i]);
|
||||
auto mvp = proj * plane_camera * m_xform * m_xform_local;
|
||||
auto mv = plane_camera * m_xform * m_xform_local;
|
||||
auto mvp = proj * mv;
|
||||
ShaderManager::u_mat4(kShaderUniform::MVP, mvp);
|
||||
|
||||
layer.m_rtt[i].bindFramebuffer();
|
||||
|
||||
glm::vec2 bb_min(canvas->m_size);
|
||||
glm::vec2 bb_max(0, 0);
|
||||
std::vector<glm::vec2> poly2d;
|
||||
static std::vector<glm::vec2> face_corners{ {1,1}, {-1,1}, {-1,-1}, {1,-1} };
|
||||
for (int j = 0; j < 6; j++)
|
||||
{
|
||||
std::vector<glm::vec3> poly_cam;
|
||||
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);
|
||||
|
||||
for (int pi = 0; pi < poly_cam.size(); pi++)
|
||||
{
|
||||
auto p_clip = mvp * p.pos;
|
||||
auto p_norm = p_clip / p_clip.z;
|
||||
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_raster = (xy(p_norm) * 0.5f + 0.5f) * canvas->m_size;
|
||||
bb_min = glm::max({ 0, 0 }, glm::min(bb_min, p_raster));
|
||||
bb_max = glm::min(canvas->m_size, glm::max(bb_max, p_raster));
|
||||
|
||||
poly2d.push_back(p_norm);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto clipped = poly_intersect(poly2d, face_corners);
|
||||
|
||||
glm::vec2 bb_min(canvas->m_size);
|
||||
glm::vec2 bb_max(0, 0);
|
||||
for (auto p_norm : clipped)
|
||||
{
|
||||
auto p_raster = (p_norm * 0.5f + 0.5f) * canvas->m_size;
|
||||
bb_min = glm::max({ 0, 0 }, glm::min(bb_min, p_raster));
|
||||
bb_max = glm::min(canvas->m_size, glm::max(bb_max, p_raster));
|
||||
}
|
||||
glm::vec2 pad(2);
|
||||
bb_min = glm::max({ 0, 0 }, glm::floor(bb_min) - pad);
|
||||
bb_max = glm::min(canvas->m_size, glm::ceil(bb_max) + pad);
|
||||
auto bb_sz = bb_max - bb_min;
|
||||
|
||||
if (bb_sz.x <= 0.f || bb_sz.y <= 0.f)
|
||||
if (clipped.empty() || bb_sz.x <= 0.f || bb_sz.y <= 0.f)
|
||||
{
|
||||
layer.m_rtt[i].unbindFramebuffer();
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user