MechanicalStateController.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef SOFA_COMPONENT_CONTROLLER_MECHANICALSTATECONTROLLER_H
00038 #define SOFA_COMPONENT_CONTROLLER_MECHANICALSTATECONTROLLER_H
00039
00040 #include <sofa/component/controller/Controller.h>
00041 #include <sofa/defaulttype/Vec3Types.h>
00042 #include <sofa/defaulttype/Quat.h>
00043
00044 namespace sofa { namespace core { namespace componentmodel { namespace behavior { template<class DataTypes> class MechanicalState; } } } }
00045
00046
00047 namespace sofa
00048 {
00049
00050 namespace component
00051 {
00052
00053 namespace controller
00054 {
00055
00056 using namespace sofa::defaulttype;
00057
00064 template<class DataTypes>
00065 class MechanicalStateController : public Controller
00066 {
00067 public:
00068 typedef typename DataTypes::VecCoord VecCoord;
00069 typedef typename DataTypes::VecDeriv VecDeriv;
00070 typedef typename DataTypes::Coord Coord ;
00071 typedef typename DataTypes::Deriv Deriv ;
00072 typedef typename Coord::value_type Real ;
00073
00077 MechanicalStateController();
00078
00082 virtual ~MechanicalStateController(){};
00083
00087 void init();
00088
00093
00097 void onMouseEvent(core::objectmodel::MouseEvent *mev);
00098
00102 void onOmniEvent(core::objectmodel::OmniEvent *mev);
00103
00107 void onBeginAnimationStep();
00108
00110
00115
00119 core::componentmodel::behavior::MechanicalState<DataTypes> *getMechanicalState(void) const;
00120
00124 void setMechanicalState(core::componentmodel::behavior::MechanicalState<DataTypes> *);
00125
00129 unsigned int getIndex(void) const;
00130
00134 void setIndex(const unsigned int);
00135
00139 void setMainDirection(const sofa::defaulttype::Vec<3,Real>);
00140
00144 const sofa::defaulttype::Vec<3,Real> &getMainDirection() const;
00145
00147
00151 void applyController(void);
00152
00153 virtual std::string getTemplateName() const
00154 {
00155 return templateName(this);
00156 }
00157
00158 static std::string templateName(const MechanicalStateController<DataTypes>* = NULL)
00159 {
00160 return DataTypes::Name();
00161 }
00162 protected:
00163
00164 Data< unsigned int > index;
00165 core::componentmodel::behavior::MechanicalState<DataTypes> *mState;
00166
00167 sofa::defaulttype::Vec<3,Real> mainDirection;
00168 DataPtr< sofa::defaulttype::Vec<3,Real> > mainDirectionPtr;
00169
00170 enum MouseMode { None=0, BtLeft, BtRight, BtMiddle, Wheel };
00171 bool omni;
00172 MouseMode mouseMode;
00173
00174 int eventX, eventY;
00175 double omniX, omniY, omniZ;
00176 int mouseSavedPosX, mouseSavedPosY;
00177 Vector3 position;
00178 Quat orientation;
00179 };
00180
00181 }
00182
00183 }
00184
00185 }
00186
00187 #endif // SOFA_COMPONENT_CONTROLLER_MECHANICALSTATECONTROLLER_H