MechanicalStateController.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 //
00026 // C++ Interface: MechanicalStateController
00027 //
00028 // Description:
00029 //
00030 //
00031 // Author: Pierre-Jean Bensoussan, Digital Trainers (2008)
00032 //
00033 // Copyright: See COPYING file that comes with this distribution
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 } // namespace controller
00182 
00183 } // namespace component
00184 
00185 } // namespace sofa
00186 
00187 #endif // SOFA_COMPONENT_CONTROLLER_MECHANICALSTATECONTROLLER_H

Generated on Sun Nov 23 02:50:35 2008 for Sofa by  doxygen 1.5.7.1