Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

gfx/LookAtCameraManipulator

Go to the documentation of this file.
00001 /* **-*-c++-*-**************************************************************
00002   Copyright (C)2002 David Jung <opensim@pobox.com>
00003 
00004   This program/file is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008   
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details. (http://www.gnu.org)
00013   
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00017   
00018   $Id: LookAtCameraManipulator 1030 2004-02-11 20:46:17Z jungd $
00019   $Revision: 1.5 $
00020   $Date: 2004-02-11 15:46:17 -0500 (Wed, 11 Feb 2004) $
00021   $Author: jungd $
00022  
00023 ****************************************************************************/
00024 
00025 #ifndef _ROBOT_GFX_LOOKATCAMERAMANIPULATOR_
00026 #define _ROBOT_GFX_LOOKATCAMERAMANIPULATOR_
00027 
00028 #include <gfx/gfx>
00029 
00030 #include <osgGA/MatrixManipulator>
00031 
00032 
00033 namespace gfx {
00034 
00035 /// OSG Specific Camera manipulator for looking at specific points
00036 /// \todo reimplement (as this is broken since switch to Producer)
00037 class LookAtCameraManipulator : public osgGA::MatrixManipulator
00038 {
00039 public:
00040   LookAtCameraManipulator(Real alpha = 90, Real theta=10, Real d=5, Real targetx = 0, Real targety = 0, Real targetz = 0);
00041   virtual ~LookAtCameraManipulator();
00042 
00043   void setAlpha(Real alpha) { this->alpha = Math::degToRad(alpha); }
00044   void setTheta(Real theta) { this->theta = Math::degToRad(theta); }
00045   void setD(Real d) { this->d = d; }
00046   Real getAlpha() const { return Math::radToDeg(alpha); }
00047   Real getTheta() const { return Math::radToDeg(theta); }
00048   Real getD() const { return d; }
00049   
00050   
00051   void setTarget(Real targetx, Real targety, Real targetz)
00052   {
00053     target[0] = targetx;
00054     target[1] = targety;
00055     target[2] = targetz; 
00056   }
00057 
00058   Point3 getTarget() const 
00059   {
00060     return Point3(target[0], target[1], target[2]);
00061   }
00062   
00063   
00064   void trackingEnable() { tracking=true; }
00065   void trackingDisable() { tracking=false; }
00066   
00067   bool trackingEnabled() const { return tracking; }
00068   
00069   /** Attach a node to the manipulator. 
00070       Automatically detaches previously attached node.
00071       setNode(NULL) detaches previously nodes.
00072       Is ignored by manipulators which do not require a reference model.*/
00073   virtual void setNode(osg::Node*);
00074   
00075   /** Return node if attached.*/
00076   virtual const osg::Node* getNode() const;
00077   
00078   /** Return node if attached.*/
00079   virtual osg::Node* getNode();
00080   
00081   /** Move the camera to the default position. 
00082       May be ignored by manipulators if home functionality is not appropriate.*/
00083   virtual void home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
00084   
00085   /** Start/restart the manipulator.*/
00086   virtual void init(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
00087   
00088   
00089   /** handle events, return true if handled, false otherwise.*/
00090   virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& us);
00091   
00092   virtual osg::Matrixd getMatrix() const;  
00093   virtual osg::Matrixd getInverseMatrix() const;
00094   virtual void setByMatrix(const osg::Matrixd& matrix);
00095   virtual void setByInverseMatrix(const osg::Matrixd& matrix);
00096 
00097 
00098 protected:
00099   osg::Vec3 target; // target to look at
00100   bool tracking;  // continous tracking on?
00101 
00102   Real alpha; // angle about the z 'up' axis
00103   Real theta; // angle rotated out of the x-y plane (into +z)
00104   Real d;     // distance from target
00105 
00106   Real halpha; // home pos
00107   Real htheta; 
00108   Real hd;     
00109 
00110   // values at button press
00111   Real x,y;
00112   Real ialpha, itheta, id;
00113   osg::Vec3 itarget;
00114 
00115   osg::Vec3 calcPos() const; // calc eye pos from d,alpha & theta
00116 
00117 //  void updateCamera(osgGA::GUIActionAdapter& us);
00118 };
00119   
00120 } // gfx
00121 
00122 #endif
00123 

Generated on Thu Jul 29 15:56:19 2004 for OpenSim by doxygen 1.3.6