|
Katana Plug-in APIs 0.1
|
00001 // Copyright (c) 2017 The Foundry Visionmongers Ltd. All Rights Reserved. 00002 00003 #ifndef GLTRANSLATESCREENPLANEHANDLE_H_ 00004 #define GLTRANSLATESCREENPLANEHANDLE_H_ 00005 00006 #include "FnGLTransformManipulator.h" 00007 00008 #include <string> 00009 00010 #include <FnViewer/plugin/FnManipulatorHandle.h> 00011 #include <FnViewer/plugin/FnMathTypes.h> 00012 #include <FnViewer/utils/FnDrawable.h> 00013 00014 using Foundry::Katana::ViewerAPI::Vec2i; 00015 using Foundry::Katana::ViewerAPI::Vec3d; 00016 using Foundry::Katana::ViewerAPI::Matrix44d; 00017 00029 struct SnappingTextures 00030 { 00031 GLuint defaultTexture = 0; 00032 GLuint hoverTexture = 0; 00033 GLuint draggingTexture = 0; 00034 00035 void cleanup() 00036 { 00037 if (defaultTexture > 0) 00038 { 00039 glDeleteTextures(1, &defaultTexture); 00040 } 00041 00042 if (hoverTexture > 0) 00043 { 00044 glDeleteTextures(1, &hoverTexture); 00045 } 00046 00047 if (draggingTexture > 0) 00048 { 00049 glDeleteTextures(1, &draggingTexture); 00050 } 00051 } 00052 }; 00053 00054 class GLTranslateScreenPlaneHandle 00055 : public Foundry::Katana::ViewerUtils::GLTransformManipulatorHandle 00056 { 00057 using OpId = Foundry::Katana::ViewerAPI::OptionIdGenerator; 00058 00059 public: 00061 GLTranslateScreenPlaneHandle(); 00062 00064 virtual ~GLTranslateScreenPlaneHandle(); 00065 00067 static Foundry::Katana::ViewerAPI::ManipulatorHandle* create() 00068 { 00069 return new GLTranslateScreenPlaneHandle(); 00070 } 00071 00073 static void flush(){} 00074 00078 void draw(); 00079 00085 void pickerDraw(int64_t pickerId); 00086 00088 void setup(); 00089 00090 virtual Foundry::Katana::ViewerUtils::Orientation getOrientation(); 00091 00092 protected: 00096 virtual std::string getComponentName() { return "translate"; } 00097 00103 bool getDraggingPlane(Vec3d& origin, Vec3d& normal); 00104 00110 void drag(const Vec3d& initialPointOnPlane, 00111 const Vec3d& previousPointOnPlane, 00112 const Vec3d& currentPointOnPlane, 00113 const Vec2i& initialMousePosition, 00114 const Vec2i& previousMousePosition, 00115 const Vec2i& currentMousePosition, 00116 bool isFinal); 00117 00121 void startDrag(const Vec3d& initialPointOnPlane, 00122 const Vec2i& initialMousePosition); 00123 00127 void endDrag(); 00128 00133 void applyXformToLocation(const std::string& locationPath, 00134 const IMATH_NAMESPACE::M44d& xform, 00135 bool isFinal); 00136 00141 virtual void calculateAndSetLocalXform(const std::string& locationPath); 00142 00143 void setOption(OpId::value_type optionId, 00144 FnAttribute::Attribute attr) override; 00145 00146 private: 00147 void loadTextures(const float scale); 00148 00152 bool isSnapping(); 00153 00154 void drawSnappingHandle(); 00155 00156 void drawHandle(); 00157 00158 GLuint getTexture(); 00159 00160 private: 00162 Foundry::Katana::ViewerUtils::Drawable m_mesh; 00163 Foundry::Katana::ViewerUtils::Orientation m_orientation; 00164 Vec3d m_manipOrigin; 00165 SnappingTextures m_snappingTextures; 00166 }; 00167 00168 #endif // GLTRANSLATESCREENPLANEHANDLE_H_
1.7.3