TuttleOFX
1
|
00001 #ifndef _TUTTLE_PLUGIN_INTERACTOBJECT_HPP_ 00002 #define _TUTTLE_PLUGIN_INTERACTOBJECT_HPP_ 00003 00004 #include "interact.hpp" 00005 #include <ofxsInteract.h> 00006 #include <boost/gil/utilities.hpp> 00007 00008 #include <boost/math/special_functions/pow.hpp> 00009 00010 namespace tuttle { 00011 namespace plugin { 00012 namespace interact { 00013 00014 typedef double Scalar; 00015 typedef boost::gil::point2<Scalar> Point2; 00016 00017 /** 00018 * @brief A base class for all object to use in interact or overlay. 00019 * All sub classes needs to implement virtual functions from OFX::InteractI 00020 */ 00021 class InteractObject /*: public OFX::InteractI*/ 00022 { 00023 public: 00024 InteractObject(); 00025 virtual ~InteractObject() = 0; 00026 00027 /** @brief the function called to draw in the interact */ 00028 virtual bool draw( const OFX::DrawArgs& args ) const { return false; } 00029 00030 virtual MotionType intersect( const OFX::PenArgs& args ) 00031 { 00032 MotionType m; 00033 m._axis = eAxisNone; 00034 m._mode = eMotionNone; 00035 return m; 00036 } 00037 virtual bool isIn( const OfxRectD& ) { return false; } 00038 00039 virtual Point2 getPosition() const { return Point2(0.0, 0.0); } 00040 virtual void setPosition( const Point2& ) {} 00041 virtual void setPositionX( const Scalar x ) {} 00042 virtual void setPositionY( const Scalar y ) {} 00043 00044 virtual void translate( const Point2& previous, const Point2& vec ) 00045 { 00046 setPosition( previous + vec ); 00047 } 00048 virtual void rotate( const Point2& previous, const Point2& center, const Point2& from, const Point2& vec ) 00049 { 00050 using namespace boost::math; 00051 // a^2 = b^2 + c^2 - 2bc * cos(alpha) 00052 // alpha = -arccos( (a^2 - b^2 - c^2) / 2bc ) 00053 // const double a = std::sqrt( pow<2>(penPosition.x - _beginPenPosition.x) + pow<2>(penPosition.y - _beginPenPosition.y) ); 00054 // const double b = std::sqrt( pow<2>(_beginPenPosition.x - _manipulator->getPosition().x) + pow<2>(_beginPenPosition.y - _manipulator->getPosition().y) ); 00055 // const double c = std::sqrt( pow<2>(penPosition.x - _manipulator->getPosition().x) + pow<2>(penPosition.y - _manipulator->getPosition().y) ); 00056 00057 //rotate( center, -std::acos( (pow<2>(a) - pow<2>(b) - pow<2>(c)) / (2*abs(b)*abs(c)) ) ); 00058 } 00059 virtual void scale( const Point2& previous, const Point2& center, const Point2& factor ) 00060 { 00061 } 00062 00063 virtual void beginMove( const Point2& penPosition ) {} 00064 virtual void endMove( const Point2& penPosition ) {} 00065 00066 bool getSelected() const { return _selected; } 00067 void setSelected( const bool s ) { _selected = s; } 00068 00069 private: 00070 bool _selected; 00071 }; 00072 00073 } 00074 } 00075 } 00076 00077 #endif