cameramanipulatorTV.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Robot Group Leipzig                             *
00003  *    martius@informatik.uni-leipzig.de                                    *
00004  *    fhesse@informatik.uni-leipzig.de                                     *
00005  *    der@informatik.uni-leipzig.de                                        *
00006  *    frankguettler@gmx.de                                                 *
00007  *                                                                         *
00008  *   This program is free software; you can redistribute it and/or modify  *
00009  *   it under the terms of the GNU General Public License as published by  *
00010  *   the Free Software Foundation; either version 2 of the License, or     *
00011  *   (at your option) any later version.                                   *
00012  *                                                                         *
00013  *   This program is distributed in the hope that it will be useful,       *
00014  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00015  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00016  *   GNU General Public License for more details.                          *
00017  *                                                                         *
00018  *   You should have received a copy of the GNU General Public License     *
00019  *   along with this program; if not, write to the                         *
00020  *   Free Software Foundation, Inc.,                                       *
00021  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00022  ***************************************************************************
00023  *                                                                         *
00024  *                                                                         *
00025  *   $Log: cameramanipulatorTV.cpp,v $
00026  *   Revision 1.1.2.6  2006/03/19 13:36:52  robot3
00027  *   race mode now works
00028  *
00029  *   Revision 1.1.2.5  2006/03/18 13:54:42  robot3
00030  *   syntax error fix
00031  *
00032  *   Revision 1.1.2.4  2006/03/18 13:49:05  robot3
00033  *   TV mode works now, the appropiate pan and tilt are calculated
00034  *
00035  *   Revision 1.1.2.3  2006/03/06 16:57:53  robot3
00036  *   minor changes
00037  *
00038  *   Revision 1.1.2.2  2006/03/03 12:08:50  robot3
00039  *   preparations made for new cameramanipulators
00040  *
00041  *   Revision 1.1.2.1  2006/02/01 10:24:34  robot3
00042  *   new camera manipulator added
00043  *
00044  *                                                                         *
00045  ***************************************************************************/
00046 
00047 #include <osg/Notify>
00048 #include "cameramanipulatorTV.h"
00049 #include "mathutils.h"
00050 #include "pos.h"
00051 #include <stdio.h>
00052 
00053 
00054 #define square(x) ((x)*(x))
00055 
00056 namespace lpzrobots {
00057 
00058   using namespace osg;
00059   using namespace osgGA;
00060 
00061   CameraManipulatorTV::CameraManipulatorTV(osg::Node* node,GlobalData& global)
00062     : CameraManipulator(node,global) {}
00063 
00064   CameraManipulatorTV::~CameraManipulatorTV(){}
00065 
00066 
00067   void CameraManipulatorTV::calcMovementByAgent() {
00068     if (watchingAgent!=NULL) {
00069       // the actual position of the agent has to be recognized
00070       // we use the Position getPosition() from OdeRobot
00071       Position robPos = watchingAgent->getRobot()->getPosition();
00072       // desiredEye is the position of the camera
00073       // calculate the horizontal angle, means pan (view.x)
00074       if (robPos.x-desiredEye[0]!=0) { // division by zero
00075         desiredView[0]= atan((desiredEye[0]-robPos.x)/(robPos.y-desiredEye[1]))
00076           / PI*180.0f+180.0f;
00077         if (desiredEye[1]-robPos.y<0) // we must switch
00078                   desiredView[0]+=180.0f;
00079       }
00080       // calculate the vertical angle
00081       if (robPos.z-desiredEye[2]!=0) { // division by zero
00082         // need dz and sqrt(dx^2+dy^2) for calulation
00083         desiredView[1]=-atan((sqrt(square(desiredEye[0]-robPos.x)+
00084                                   square(desiredEye[1]-robPos.y)))
00085                             /(robPos.z-desiredEye[2]))
00086           / PI*180.0f-90.0f;
00087         if (desiredEye[2]-robPos.z<0) // we must switch
00088           desiredView[1]+=180.0f;
00089       }
00090     }
00091   }
00092 
00093   
00094     void CameraManipulatorTV::setHomeViewByAgent() {
00095     // the default camera manipulator does not need to change the view
00096     // normally the desired view should be changed
00097   }
00098 
00099 
00100   void CameraManipulatorTV::setHomeEyeByAgent() {
00101     // the default camera manipulator does not need to change the eye
00102     // normally the desired eye should be changed
00103   }
00104 }

Generated on Tue Apr 4 19:05:03 2006 for Robotsystem from Robot Group Leipzig by  doxygen 1.4.5