|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2020 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef MANIPULATORSHELPERS_H_ 00004 #define MANIPULATORSHELPERS_H_ 00005 00006 #include <ImathMatrix.h> 00007 #include <ImathVec.h> 00008 00009 #include "FnViewer/plugin/FnViewport.h" 00010 #include "FnViewer/utils/FnImathHelpers.h" 00011 00012 namespace Foundry 00013 { 00014 namespace Katana 00015 { 00016 namespace ViewerUtils 00017 { 00029 inline double calculateFixedSizeScale( 00030 const ViewerAPI::ViewportWrapperPtr& viewport, 00031 const IMATH_NAMESPACE::V3d& point, 00032 const double factor = 100.0) 00033 { 00034 const int width = viewport->getWidth(); 00035 const int height = viewport->getHeight(); 00036 00037 const IMATH_NAMESPACE::M44d viewMatrix( 00038 toImathMatrix44d(viewport->getViewMatrix44d())); 00039 const IMATH_NAMESPACE::M44d projMatrix( 00040 toImathMatrix44d(viewport->getProjectionMatrix())); 00041 00042 const IMATH_NAMESPACE::M44d toScreenXform(viewMatrix * projMatrix); 00043 const IMATH_NAMESPACE::M44d screenToManip(toScreenXform.inverse()); 00044 00045 const IMATH_NAMESPACE::V3d a(point * toScreenXform); 00046 IMATH_NAMESPACE::V3d b(a.x, a.y, a.z); 00047 00048 if (width < height) 00049 { 00050 b.x += factor / width; 00051 } 00052 else 00053 { 00054 b.y += factor / height; 00055 } 00056 00057 return (a * screenToManip - b * screenToManip).length(); 00058 } 00059 } // namespace ViewerUtils 00060 } // namespace Katana 00061 } // namespace Foundry 00062 00063 #endif // MANIPULATORSHELPERS_H_
1.7.3