OpenToonz - An open-source full-featured 2D animation creation software
C
#assistants: improve vanishing point
Ivan Mahonin7c7225c00c49
diff --git a/toonz/sources/tnztools/assistant.cpp b/toonz/sources/tnztools/assistant.cppindex 84d27255c..2756531c9 100644--- a/toonz/sources/tnztools/assistant.cpp+++ b/toonz/sources/tnztools/assistant.cpp@@ -424,13 +424,13 @@ TAssistant::drawDot(const TPointD &p, double alpha) const {tglEnableBlending();glColor4dv(colorWhite);- tglEnablePointSmooth(4.0);+ tglEnablePointSmooth(6.0);glBegin(GL_POINTS);glVertex2d(p.x, p.y);glEnd();glColor4dv(colorBlack);- tglEnablePointSmooth(2.0);+ tglEnablePointSmooth(3.0);glBegin(GL_POINTS);glVertex2d(p.x, p.y);glEnd();diff --git a/toonz/sources/tnztools/assistants/assistantvanishingpoint.cpp b/toonz/sources/tnztools/assistants/assistantvanishingpoint.cppindex 9eb771819..fb50040cb 100644--- a/toonz/sources/tnztools/assistants/assistantvanishingpoint.cpp+++ b/toonz/sources/tnztools/assistants/assistantvanishingpoint.cpp@@ -29,9 +29,6 @@ protected:TAssistantPoint &m_grid0;TAssistantPoint &m_grid1;- int m_gridRays; //!< for simple grid only, not perspective- double m_gridRadiusPart;-public:TAssistantVanishingPoint(TMetaObject &object):TAssistant(object),@@ -39,14 +36,12 @@ public:m_idGrid("grid"),m_idPerspective("perspective"),m_center( addPoint("center", TAssistantPoint::CircleCross) ),- m_a0 ( addPoint("A0", TAssistantPoint::Circle, TPointD(-50.0, 0.0)) ),- m_a1 ( addPoint("A1", TAssistantPoint::Circle, TPointD(-75.0, 0.0)) ),- m_b0 ( addPoint("B0", TAssistantPoint::Circle, TPointD( 50.0, 0.0)) ),- m_b1 ( addPoint("B1", TAssistantPoint::Circle, TPointD( 75.0, 0.0)) ),- m_grid0 ( addPoint("grid0", TAssistantPoint::CircleDoubleDots, TPointD(-12.5,-25.0)) ),- m_grid1 ( addPoint("grid1", TAssistantPoint::CircleDots, TPointD( 12.5,-25.0)) ),- m_gridRays(),- m_gridRadiusPart()+ m_a0 ( addPoint("a0", TAssistantPoint::Circle, TPointD(-50.0, 0.0)) ),+ m_a1 ( addPoint("a1", TAssistantPoint::Circle, TPointD(-75.0, 0.0)) ),+ m_b0 ( addPoint("b0", TAssistantPoint::Circle, TPointD( 50.0, 0.0)) ),+ m_b1 ( addPoint("b1", TAssistantPoint::Circle, TPointD( 75.0, 0.0)) ),+ m_grid0 ( addPoint("grid0", TAssistantPoint::CircleDoubleDots, TPointD( 0.0,-50.0)) ),+ m_grid1 ( addPoint("grid1", TAssistantPoint::CircleDots, TPointD( 25.0,-50.0)) ){addProperty( new TBoolProperty(m_idPassThrough.str(), getPassThrough()) );addProperty( new TBoolProperty(m_idGrid.str(), getGrid()) );@@ -127,31 +122,11 @@ private:m_grid1.position = m_grid0.position + dx*x + dy*y;}- void recalcGrid() {- const double minStep = 5.0;-- TPointD d0 = m_grid0.position - m_center.position;- TPointD d1 = m_grid1.position - m_center.position;- double l = norm(d0);- if (l <= TConsts::epsilon) return;- if (norm2(d1) <= TConsts::epsilon*TConsts::epsilon) return;- double a0 = atan(d0);- double a1 = atan(d1);- double da = fabs(a1 - a0);- if (da > M_PI) da = M_PI - da;- if (da < TConsts::epsilon) da = TConsts::epsilon;- double count = M_2PI/da;- m_gridRadiusPart = minStep/da/l;- m_gridRays = count < 1e6 && m_gridRadiusPart < 1.0- ? (int)round(count) : 0;- }-public:void onFixPoints() override {fixSidePoint(m_a0, m_a1);fixSidePoint(m_b0, m_b1);fixCenter();- recalcGrid();}void onMovePoint(TAssistantPoint &point, const TPointD &position) override {@@ -187,8 +162,6 @@ public:if (&point != &m_grid1) {fixGrid1(previousCenter, m_grid0.position);}-- recalcGrid();}void getGuidelines(@@ -214,7 +187,28 @@ public:}void drawSimpleGrid() const {- if (m_gridRays <= 0) return;+ const double minStep = 5.0;+ double alpha = getDrawingGridAlpha();+ const TPointD &p = m_center.position;++ // calculate rays count and step+ TPointD d0 = m_grid0.position - p;+ TPointD d1 = m_grid1.position - p;+ TPointD dp = d0;+ double l = norm(d0);+ if (l <= TConsts::epsilon) return;+ if (norm2(d1) <= TConsts::epsilon*TConsts::epsilon) return;+ double a0 = atan(d0);+ double a1 = atan(d1);+ double da = fabs(a1 - a0);+ if (da > M_PI) da = M_PI - da;+ if (da < TConsts::epsilon) da = TConsts::epsilon;+ double count = M_2PI/da;+ if (count > 1e6) return;+ double radiusPart = minStep/(da*l);+ if (radiusPart > 1.0) return;+ int raysCount = (int)round(count);+ double step = M_2PI/(double)raysCount;// common data about viewportconst TRectD oneBox(-1.0, -1.0, 1.0, 1.0);@@ -225,14 +219,7 @@ public:TAffine matrixInv = matrix.inv();double pixelSize = sqrt(tglGetPixelSize2());- // initial calculations- double alpha = getDrawingGridAlpha();- const TPointD &p = m_center.position;- TPointD dp = m_grid0.position - p;- double step = M_2PI/(double)m_gridRays;-// calculate range- int raysCount = m_gridRays;if (!(matrixInv*oneBox).contains(p)) {TPointD corners[4] = {TPointD(oneBox.x0, oneBox.y0),@@ -265,9 +252,9 @@ public:double s = sin(step);double c = cos(step);for(int i = 0; i < raysCount; ++i) {- TPointD p0 = matrix*(p + dp*m_gridRadiusPart);+ TPointD p0 = matrix*(p + dp*radiusPart);TPointD p1 = matrix*(p + dp);- if (TGuidelineLineBase::truncateInfiniteRay(oneBox, p0, p1))+ if (TGuidelineLineBase::truncateRay(oneBox, p0, p1))drawSegment(matrixInv*p0, matrixInv*p1, pixelSize, alpha);dp = TPointD(c*dp.x - s*dp.y, s*dp.x + c*dp.y);}@@ -345,7 +332,7 @@ public:TPointD p = smallGrid0 + smallStep*x - center;TPointD p0 = matrix*(center + p);TPointD p1 = matrix*(center + p*2.0);- if (TGuidelineLineBase::truncateInfiniteRay(oneBox, p0, p1))+ if (TGuidelineLineBase::truncateRay(oneBox, p0, p1))drawSegment(matrixInv*p0, matrixInv*p1, pixelSize, alpha);}diff --git a/toonz/sources/tnztools/assistants/guidelineline.cpp b/toonz/sources/tnztools/assistants/guidelineline.cppindex 5d4777146..e3f3b50fe 100644--- a/toonz/sources/tnztools/assistants/guidelineline.cpp+++ b/toonz/sources/tnztools/assistants/guidelineline.cpp@@ -58,7 +58,7 @@ TGuidelineLineBase::truncateInfiniteLine(const TRectD &bounds, TPointD &p0, TPoiif (bounds.isEmpty()) return false;TPointD d = p0 - p1;TDimensionD size = bounds.getSize();- if (fabs(d.x)*(bounds.y1 - bounds.y0) > fabs(d.y)*(bounds.x1 - bounds.x0)) {+ if (fabs(d.x)*size.ly > fabs(d.y)*size.lx) {// horizontalif (!fitX (p0.x, p0.y, p1.x, p1.y, bounds.x0, bounds.x1)) return false;if (!truncateX(p0.y, p0.x, p1.y, p1.x, bounds.y0, bounds.y1)) return false;@@ -71,19 +71,28 @@ TGuidelineLineBase::truncateInfiniteLine(const TRectD &bounds, TPointD &p0, TPoi}bool-TGuidelineLineBase::truncateInfiniteRay(const TRectD &bounds, TPointD &p0, TPointD &p1) {+TGuidelineLineBase::truncateRay(const TRectD &bounds, TPointD &p0, TPointD &p1) {if (bounds.isEmpty()) return false;TRectD b(bounds);- if (p0.x <= p1.x && b.x0 <= p0.x) b.x0 = p0.x;- if (p0.x > p1.x && b.x1 > p0.x) b.x1 = p0.x;- if (p0.y <= p1.y && b.y0 <= p0.y) b.y0 = p0.y;- if (p0.y > p1.y && b.y1 > p0.y) b.y1 = p0.y;++ if (p0.x <= p1.x) { if (b.x0 < p0.x) b.x0 = p0.x; }+ else { if (b.x1 > p0.x) b.x1 = p0.x; }+ if (p0.y <= p1.y) { if (b.y0 < p0.y) b.y0 = p0.y; }+ else { if (b.y1 > p0.y) b.y1 = p0.y; }++ if (b.isEmpty()) return false;+ return truncateInfiniteLine(b, p0, p1);+}++bool+TGuidelineLineBase::truncateLine(const TRectD &bounds, TPointD &p0, TPointD &p1) {+ TRectD b = bounds * boundingBox(p0, p1);if (b.isEmpty()) return false;return truncateInfiniteLine(b, p0, p1);}void-TGuidelineLineBase::drawInfiniteLine(const TPointD &p0, const TPointD &p1, bool ray, bool active, bool enabled) const {+TGuidelineLineBase::drawLine(const TPointD &p0, const TPointD &p1, bool restrict0, bool restrict1, bool active, bool enabled) const {TAffine4 modelview, projection;glGetDoublev(GL_MODELVIEW_MATRIX, modelview.a);glGetDoublev(GL_PROJECTION_MATRIX, projection.a);@@ -91,9 +100,11 @@ TGuidelineLineBase::drawInfiniteLine(const TPointD &p0, const TPointD &p1, boolTAffine matrix = (projection*modelview).get2d();TPointD pp0 = matrix*p0;TPointD pp1 = matrix*p1;- if ( ray- ? !truncateInfiniteRay (TRectD(-1.0, -1.0, 1.0, 1.0), pp0, pp1)- : !truncateInfiniteLine(TRectD(-1.0, -1.0, 1.0, 1.0), pp0, pp1) ) return;+ const TRectD oneBox(-1.0, -1.0, 1.0, 1.0);+ if ( restrict0 && restrict1 ? !truncateLine(oneBox, pp0, pp1)+ : restrict0 ? !truncateRay (oneBox, pp0, pp1)+ : restrict1 ? !truncateRay (oneBox, pp1, pp0) // pp1 first+ : !truncateInfiniteLine(oneBox, pp0, pp1) ) return;double pixelSize = sqrt(tglGetPixelSize2());TAffine matrixInv = matrix.inv();@@ -119,7 +130,7 @@ TGuidelineLine::transformPoint(const TTrackPoint &point) const {voidTGuidelineLine::draw(bool active, bool enabled) const- { drawSegment(p0, p1, sqrt(tglGetPixelSize2()), active, enabled); }+ { drawLine(p0, p1, true, true, active, enabled); }//*****************************************************************************************@@ -139,7 +150,7 @@ TGuidelineInfiniteLine::transformPoint(const TTrackPoint &point) const {voidTGuidelineInfiniteLine::draw(bool active, bool enabled) const- { drawInfiniteLine(p0, p1, false, active, enabled); }+ { drawLine(p0, p1, false, false, active, enabled); }//*****************************************************************************************@@ -159,5 +170,5 @@ TGuidelineRay::transformPoint(const TTrackPoint &point) const {voidTGuidelineRay::draw(bool active, bool enabled) const- { drawInfiniteLine(p0, p1, true, active, enabled); }+ { drawLine(p0, p1, true, false, active, enabled); }diff --git a/toonz/sources/tnztools/assistants/guidelineline.h b/toonz/sources/tnztools/assistants/guidelineline.hindex 27262ca82..e2954e4fc 100644--- a/toonz/sources/tnztools/assistants/guidelineline.h+++ b/toonz/sources/tnztools/assistants/guidelineline.h@@ -32,10 +32,11 @@ public:const TPointD p1;TGuidelineLineBase(bool enabled, double magnetism, const TPointD &p0, const TPointD &p1);- void drawInfiniteLine(const TPointD &p0, const TPointD &p1, bool ray, bool active, bool enabled) const;+ void drawLine(const TPointD &p0, const TPointD &p1, bool restrict0, bool restrict1, bool active, bool enabled) const;static TPointD calcDirection(const TPointD &p0, const TPointD &p1);static bool truncateInfiniteLine(const TRectD &bounds, TPointD &p0, TPointD &p1);- static bool truncateInfiniteRay(const TRectD &bounds, TPointD &p0, TPointD &p1);+ static bool truncateRay(const TRectD &bounds, TPointD &p0, TPointD &p1);+ static bool truncateLine(const TRectD &bounds, TPointD &p0, TPointD &p1);};