diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-01 01:01:28 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2017-05-01 01:02:34 +0200 |
commit | 57712e58d97a048d3d6d0b613fab4a99ab26e583 (patch) | |
tree | 9d9691b0be8fd65582ed19576998d640ffe76be7 /pose-widget | |
parent | 8aa78cf708d646a05090223b55294f3390cb8e29 (diff) |
pose-widget: catch 90 deg oblique rotation sooner
Diffstat (limited to 'pose-widget')
-rw-r--r-- | pose-widget/pose-widget.cpp | 48 | ||||
-rw-r--r-- | pose-widget/pose-widget.hpp | 2 |
2 files changed, 16 insertions, 34 deletions
diff --git a/pose-widget/pose-widget.cpp b/pose-widget/pose-widget.cpp index 4be3f09f..b511f4c5 100644 --- a/pose-widget/pose-widget.cpp +++ b/pose-widget/pose-widget.cpp @@ -141,20 +141,6 @@ public: bool barycentric_coords(const vec2& px, vec2& uv, int& i) const; }; -inline vec3 pose_transform::normal(const vec3& p1, const vec3& p2, const vec3& p3) -{ - using std::sqrt; - - vec3 u = p2 - p1; - vec3 v = p3 - p1; - - vec3 tmp = u.cross(v); - - num i = 1/sqrt(tmp.dot(tmp)); - - return tmp * i; -} - Triangle::Triangle(const vec2& p1, const vec2& p2, const vec2& p3) { origin = p1; @@ -167,20 +153,8 @@ Triangle::Triangle(const vec2& p1, const vec2& p2, const vec2& p3) dot11 = v1.dot(v1); const num denom = dot00 * dot11 - dot01 * dot01; - const num area = std::fabs(v0.x() * v1.y() - v0.y() * v1.x()) * .5; - - static constexpr num min_area = 2; - if (area < min_area*min_area) - { - // for perpendicular plane, ensure u and v don't come out right - origin = vec2(-1e6, -1e6); - invDenom = -1; - dot00 = dot01 = dot11 = 1; - v0 = v1 = vec2(1, 1); - } - else - invDenom = 1 / denom; + invDenom = 1 / denom; } bool Triangle::barycentric_coords(const vec2& px, vec2& uv, int& i) const @@ -208,6 +182,8 @@ bool Triangle::barycentric_coords(const vec2& px, vec2& uv, int& i) const void pose_transform::project_quad_texture() { + image.fill(Qt::transparent); + num dir; vec2 pt[4]; const int sx = width - 1, sy = height - 1; @@ -230,8 +206,6 @@ void pose_transform::project_quad_texture() for (int i = 0; i < 4; i++) pt[i] = project(dst_corners[i]) + vec2(sx/2, sy/2); - vec3 normal1(0, 0, 1); - vec3 normal2; { vec3 foo[3]; for (int i = 0; i < 3; i++) @@ -239,9 +213,20 @@ void pose_transform::project_quad_texture() foo[i] = project2(dst_corners[i]); projected[i] = project(dst_corners[i]) + vec2(sx/2, sy/2); } - normal2 = normal(foo[0], foo[1], foo[2]); + + vec3 p1 = foo[1] - foo[0]; + vec3 p2 = foo[2] - foo[0]; + dir = p1.x() * p2.y() - p1.y() * p2.x(); // Z part of the cross product } - dir = normal1.dot(normal2); + } + + // rotation of (0, 90, 0) makes it numerically unstable + if (std::fabs(dir) < 1e-3) + { + lock_guard l(mtx2); + std::swap(image, image2); + fresh = true; + return; } const QImage& tex = dir < 0 ? back : front; @@ -340,7 +325,6 @@ void pose_transform::project_quad_texture() { lock_guard l2(mtx2); - image2.fill(Qt::transparent); std::swap(image, image2); fresh = true; } diff --git a/pose-widget/pose-widget.hpp b/pose-widget/pose-widget.hpp index 7db1d200..b528d394 100644 --- a/pose-widget/pose-widget.hpp +++ b/pose-widget/pose-widget.hpp @@ -59,8 +59,6 @@ class pose_transform final : private QThread template<typename F> inline void with_image_lock(F&& fun); - static vec3 normal(const vec3& p1, const vec3& p2, const vec3& p3); - rmat rotation, rotation_; vec3 translation, translation_; |