Skip to content

OpenToonz - An open-source full-featured 2D animation creation software

C

#assistants: SceneViewer::get3dViewMatrix()

Ivan Mahonin8a3cf997f794
diff --git a/toonz/sources/include/tools/inputmanager.h b/toonz/sources/include/tools/inputmanager.h
index 5b6d67797..3f6f51a14 100644
--- a/toonz/sources/include/tools/inputmanager.h
+++ b/toonz/sources/include/tools/inputmanager.h
@@ -83,7 +83,7 @@ public:
m_lock = lock;
if (m_savePoint) {
m_savePoint->hold();
- if (m_lock) savePoint->lock();
+ if (m_lock) savePoint->lock();
}
} else
if (m_lock != lock) {
@@ -97,10 +97,12 @@ public:
inline void reset()
{ set(NULL, false); }
+ inline void setLock(bool lock)
+ { set(m_savePoint, lock); }
inline void lock()
- { set(m_savePoint, true); }
+ { setLock(true); }
inline void unlock()
- { set(m_savePoint, false); }
+ { setLock(false); }
inline TInputSavePoint* savePoint() const
{ return m_savePoint; }
diff --git a/toonz/sources/include/tools/tool.h b/toonz/sources/include/tools/tool.h
index b6aff1bf5..070188922 100644
--- a/toonz/sources/include/tools/tool.h
+++ b/toonz/sources/include/tools/tool.h
@@ -625,6 +625,11 @@ public:
} //!< Gets the viewer's current view affine (ie the transform from
//!< starting to current <I> world view <\I>)
+ virtual TAffine4 get3dViewMatrix() const {
+ return TAffine4(getViewMatrix());
+ } //!< Gets the viewer's current view affine 3d (ie the transform from
+ //!< starting to current <I> world view <\I>)
+
//! return the column index of the drawing intersecting point \b p
//! (window coordinate, pixels, bottom-left origin)
virtual int posToColumnIndex(const TPointD &p, double distance,
diff --git a/toonz/sources/tnztools/modifiers/modifierassistants.cpp b/toonz/sources/tnztools/modifiers/modifierassistants.cpp
index 0385fa3ce..fb0af74b6 100644
--- a/toonz/sources/tnztools/modifiers/modifierassistants.cpp
+++ b/toonz/sources/tnztools/modifiers/modifierassistants.cpp
@@ -11,6 +11,7 @@
#include <toonz/txsheethandle.h>
#include <toonz/txsheet.h>
#include <toonz/tframehandle.h>
+#include <toonz/tobjecthandle.h>
// TnzCore includes
#include <tmetaimage.h>
@@ -111,8 +112,13 @@ TModifierAssistants::modifyTrack(
if (TInputHandler *handler = manager->getHandler())
if (TTool *tool = handler->getTool())
if (TToolViewer *viewer = tool->getViewer()) {
- TAffine trackToScreen = manager->toolToWorld()
- * viewer->get3dViewMatrix().get2d().inv();
+ TAffine trackToScreen = tool->getMatrix();
+ if (tool->getToolType() & TTool::LevelTool)
+ if (TObjectHandle *objHandle = TTool::getApplication()->getCurrentObject())
+ if (!objHandle->isSpline())
+ trackToScreen *= TScale(viewer->getDpiScale().x, viewer->getDpiScale().y);
+ trackToScreen *= viewer->get3dViewMatrix().get2d().inv();
+
TGuidelineP guideline = TGuideline::findBest(modifier->guidelines, track, trackToScreen, longEnough);
if (guideline != modifier->guidelines.front())
for(int i = 1; i < (int)modifier->guidelines.size(); ++i)
@@ -122,7 +128,7 @@ TModifierAssistants::modifyTrack(
break;
}
}
- if (longEnough) modifier->savePoint.unlock(); else modifier->savePoint.lock();
+ modifier->savePoint.setLock(!longEnough);
} else {
modifier->savePoint.reset();
}
diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp
index fdf2e0868..f65e6e7b9 100644
--- a/toonz/sources/toonz/sceneviewer.cpp
+++ b/toonz/sources/toonz/sceneviewer.cpp
@@ -2257,6 +2257,37 @@ TRect SceneViewer::getActualClipRect(const TAffine &aff) {
//-----------------------------------------------------------------------------
+TAffine4 SceneViewer::get3dViewMatrix() const {
+ if (is3DView()) {
+ TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
+ TStageObjectId cameraId = xsh->getStageObjectTree()->getCurrentCameraId();
+ double z = xsh->getStageObject(cameraId)->getZ(
+ TApp::instance()->getCurrentFrame()->getFrame());
+
+ TAffine4 affine;
+ affine *= TAffine4::translation(m_pan3D.x, m_pan3D.y, z);
+ affine *= TAffine4::scale(m_zoomScale3D, m_zoomScale3D, m_zoomScale3D);
+ affine *= TAffine4::rotationX(M_PI_180*m_theta3D);
+ affine *= TAffine4::rotationY(M_PI_180*m_phi3D);
+ return affine;
+ }
+
+ int viewMode = TApp::instance()->getCurrentFrame()->isEditingLevel()
+ ? LEVEL_VIEWMODE
+ : SCENE_VIEWMODE;
+
+ if (m_referenceMode == CAMERA_REFERENCE) {
+ int frame = TApp::instance()->getCurrentFrame()->getFrame();
+ TXsheet *xsh = TApp::instance()->getCurrentXsheet()->getXsheet();
+ TAffine aff = xsh->getCameraAff(frame);
+ return TAffine4(m_viewAff[viewMode] * aff.inv());
+ }
+
+ return TAffine4(m_viewAff[viewMode]);
+}
+
+//-----------------------------------------------------------------------------
+
TAffine SceneViewer::getViewMatrix() const {
int viewMode = TApp::instance()->getCurrentFrame()->isEditingLevel()
? LEVEL_VIEWMODE
diff --git a/toonz/sources/toonz/sceneviewer.h b/toonz/sources/toonz/sceneviewer.h
index bf1fbe699..e93cfd3e1 100644
--- a/toonz/sources/toonz/sceneviewer.h
+++ b/toonz/sources/toonz/sceneviewer.h
@@ -232,6 +232,8 @@ public:
//! The view matrix is a matrix contained in \b m_viewAff
TAffine getSceneMatrix() const;
+ TAffine4 get3dViewMatrix() const override;
+
void setViewMatrix(const TAffine &aff, int viewMode);
int getFPS() { return m_FPS; }