TranslationManipulatorNode.hh

00001 /*===========================================================================*\
00002  *                                                                           *
00003  *                              OpenFlipper                                  *
00004  *      Copyright (C) 2001-2009 by Computer Graphics Group, RWTH Aachen      *
00005  *                           www.openflipper.org                             *
00006  *                                                                           *
00007  *---------------------------------------------------------------------------*
00008  *  This file is part of OpenFlipper.                                        *
00009  *                                                                           *
00010  *  OpenFlipper is free software: you can redistribute it and/or modify      *
00011  *  it under the terms of the GNU Lesser General Public License as           *
00012  *  published by the Free Software Foundation, either version 3 of           *
00013  *  the License, or (at your option) any later version with the              *
00014  *  following exceptions:                                                    *
00015  *                                                                           *
00016  *  If other files instantiate templates or use macros                       *
00017  *  or inline functions from this file, or you compile this file and         *
00018  *  link it with other files to produce an executable, this file does        *
00019  *  not by itself cause the resulting executable to be covered by the        *
00020  *  GNU Lesser General Public License. This exception does not however       *
00021  *  invalidate any other reasons why the executable file might be            *
00022  *  covered by the GNU Lesser General Public License.                        *
00023  *                                                                           *
00024  *  OpenFlipper is distributed in the hope that it will be useful,           *
00025  *  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
00026  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
00027  *  GNU Lesser General Public License for more details.                      *
00028  *                                                                           *
00029  *  You should have received a copy of the GNU LesserGeneral Public          *
00030  *  License along with OpenFlipper. If not,                                  *
00031  *  see <http://www.gnu.org/licenses/>.                                      *
00032  *                                                                           *
00033 \*===========================================================================*/
00034 
00035 /*===========================================================================*\
00036  *                                                                           *
00037  *   $Revision: 8548 $                                                       *
00038  *   $Author: moebius $                                                      *
00039  *   $Date: 2010-02-12 14:40:13 +0100 (Fr, 12. Feb 2010) $                   *
00040  *                                                                           *
00041 \*===========================================================================*/
00042 
00043 
00044 
00045 
00046 //=============================================================================
00047 //
00048 //  CLASS TranslationManipulatorNode
00049 //
00050 //=============================================================================
00051 
00052 
00053 #ifndef ACG_TRANSLATIONMANIPULATOR_NODE_HH
00054 #define ACG_TRANSLATIONMANIPULATOR_NODE_HH
00055 
00056 
00057 //== INCLUDES =================================================================
00058 
00059 // GMU
00060 #include "BaseNode.hh"
00061 #include "TransformNode.hh"
00062 
00063 // Qt
00064 #include <QEvent>
00065 #include <QMouseEvent>
00066 
00067 
00068 //== NAMESPACES ===============================================================
00069 
00070 namespace ACG {
00071 namespace SceneGraph {
00072 
00073 
00074 //== CLASS DEFINITION =========================================================
00075 
00076 
00081 class ACGDLLEXPORT TranslationManipulatorNode : public TransformNode
00082 {
00083 public:
00084 
00085   enum AutoSizeMode {
00086     Never,
00087     Once,
00088     Always
00089   };
00090 
00091   enum ManipulatorMode {
00092     TranslationRotation,
00093     LocalRotation,
00094     Resize,
00095     Place
00096   };
00097 
00099   TranslationManipulatorNode( BaseNode* _parent=0,
00100                    const std::string& _name="<TranslationTranslationManipulatorNode>" );
00101 
00103   ~TranslationManipulatorNode();
00104 
00105 
00107   ACG_CLASSNAME(TranslationManipulatorNode);
00108 
00109 
00110   //
00111   // METHODS
00112   //
00113 
00114   virtual void setIdentity();
00115 
00117   void set_draw_cylinder(bool _b) { draw_manipulator_ = _b; }
00118 
00120   bool draw_manipulator() const { return draw_manipulator_; }
00121 
00123   void set_direction(const Vec3d& _directionX, const Vec3d& _directionY);
00124 
00126   Vec3d directionX() const;
00128   Vec3d directionY() const;
00130   Vec3d directionZ() const;
00131 
00133   void set_size( double _size) { set_manipulator_height_ = _size;
00134                                  set_manipulator_radius_ = _size/10.0;
00135                                  setDirty (); }
00136 
00138   double size() const { return set_manipulator_height_; }
00139 
00141   void set_autosize (AutoSizeMode _mode) { auto_size_ = _mode; }
00142 
00144   AutoSizeMode autosize () const { return auto_size_; }
00145 
00146   void rotate (double _angle, Vec3d _axis)
00147   {
00148     TransformNode::rotate(_angle, _axis);
00149   }
00150 
00152   void draw(GLState& _state, DrawModes::DrawMode _drawMode);
00153 
00155   // void leave(GLState& _state, DrawModes::DrawMode _drawMode);
00156 
00158   void pick(GLState& _state, PickTarget _target);
00159 
00161   virtual void mouseEvent(GLState& _state, QMouseEvent* _event);
00162 
00164   void boundingBox(Vec3d& _bbMin, Vec3d& _bbMax);
00165 
00167   void setMode (ManipulatorMode _mode);
00168 
00170   ManipulatorMode getMode () const { return mode_; };
00171 
00172 
00173 private:
00174 
00175   enum StateUpdates {
00176     None,
00177     Over,
00178     Click
00179   };
00180 
00181   enum Elements {
00182     Origin = 0,
00183     XTop,
00184     YTop,
00185     ZTop,
00186     XAxis,
00187     YAxis,
00188     ZAxis,
00189     XRing,
00190     YRing,
00191     ZRing,
00192     NumElements
00193   };
00194 
00195   class Element {
00196     public:
00197       Element ();
00198 
00199       Vec4f active_target_color_;
00200       Vec4f active_current_color_;
00201       Vec4f inactive_target_color_;
00202       Vec4f inactive_current_color_;
00203 
00204       bool  clicked_;
00205       bool  over_;
00206   };
00207 
00209   void update_manipulator_system(GLState& _state);
00210 
00212   void update_rotation(GLState& _state);
00213 
00214   bool hitSphere(GLState& _state, const Vec2i& _v2);
00215   bool hitOuterSphere(GLState& _state, const Vec2i& _v2);
00216 
00217   void drawManipulator (GLState& _state, bool _active);
00218 
00219   void drawCircle(const float innerRadius, const float outerRadius);
00220 
00221   bool mapToCylinder (GLState& _state, const Vec2i& _v2, double& axis_hit, StateUpdates _updateStates = None);
00222   bool mapToCylinderTop (GLState& _state, const Vec2i& _v2, double& axis_hit, StateUpdates _updateStates = None);
00223 
00224   bool mapToSphere (GLState& _state, const Vec2i& _v2, Vec3d& _v3, StateUpdates _updateStates = None);
00225 
00226   void updateTargetColors ();
00227   bool updateCurrentColors (GLState& _state);
00228 
00229   double get_screen_length (GLState& _state, Vec3d& _point) const;
00230 
00231   void updateSize (GLState& _state);
00232 
00233   // ELEMENTS
00234   bool               draw_manipulator_;
00235 
00236   Vec3d              dirX_;
00237   Vec3d              dirY_;
00238   Vec3d              dirZ_;
00239 
00240   GLUquadricObj*     axis_;
00241   GLUquadricObj*     circle_;
00242   GLUquadricObj*     sphere_;
00243 
00244   double             manipulator_radius_;
00245   double             manipulator_height_;
00246   double             set_manipulator_radius_;
00247   double             set_manipulator_height_;
00248   int                manipulator_slices_;
00249   int                manipulator_stacks_;
00250 
00251   bool               any_axis_clicked_;
00252   bool               any_top_clicked_;
00253   bool               outer_ring_clicked_;
00254 
00255   bool               any_axis_over_;
00256   bool               any_top_over_;
00257   bool               outer_ring_over_;
00258 
00259 
00260   Element            element_[NumElements];
00261   float              resize_current_;
00262 
00263   ManipulatorMode    mode_;
00264   bool               ignoreTime_;
00265 
00266   Vec2i              oldPoint2D_;
00267   Vec3d              draggingOrigin3D_;
00268   bool               dragging_;
00269 
00270   Vec3d              currentScale_;
00271 
00272   GLMatrixd          localTransformation_;
00273 
00274   AutoSizeMode       auto_size_;
00275   double             auto_size_length_;
00276 };
00277 
00278 
00279 //=============================================================================
00280 } // namespace SceneGraph
00281 } // namespace ACG
00282 //=============================================================================
00283 #endif // ACG_TRANSLATIONMANIPULATOR_NODE_HH defined
00284 //=============================================================================
00285 

acg pic Project OpenFlipper, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .