Robotsystem from Robot Group Leipzig: cameramanipulatorFollow.cpp Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# cameramanipulatorFollow.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: cameramanipulatorFollow.cpp,v $
    00026  *   Revision 1.1.2.4  2006/03/19 13:37:29  robot3
    00027  *   race mode now works
    00028  *
    00029  *   Revision 1.1.2.3  2006/03/19 10:51:32  robot3
    00030  *   follow mode now centers the view on the robot
    00031  *   if the robot is choosed (only once)
    00032  *
    00033  *   Revision 1.1.2.2  2006/03/08 13:17:33  robot3
    00034  *   follow mode now works
    00035  *
    00036  *   Revision 1.1.2.1  2006/03/06 17:00:44  robot3
    00037  *   first dummy follow version
    00038  *
    00039  *                                                                         *
    00040  ***************************************************************************/
    00041
    00042 #include <osg/Notify>
    00043 #include "cameramanipulatorFollow.h"
    00044 //#include "mathutils.h"
    00045 #include "pos.h"
    00046
    00047 namespace lpzrobots {
    00048
    00049   using namespace osg;
    00050   using namespace osgGA;
    00051
    00052   CameraManipulatorFollow::CameraManipulatorFollow(osg::Node* node,GlobalData& global)
    00053     : CameraManipulator(node,global) {}
    00054
    00055   CameraManipulatorFollow::~CameraManipulatorFollow(){}
    00056
    00057   void CameraManipulatorFollow::calcMovementByAgent() {
    00058     if (watchingAgentDefined && oldPositionOfAgentDefined) {
    00059       // then manipulate desired view and desired eye
    00060       const double* robMove = (watchingAgent->getRobot()->getPosition()-oldPositionOfAgent).toArray();
    00061       // attach the robSpeed to desired eye
    00062       for (int i=0;i<=2;i++) {
    00063         if (!isNaN(robMove[i])) {
    00064           desiredEye[i]+=robMove[i];}
    00065         else
    00066           std::cout << "NAN exception!" << std::endl;
    00067       }
    00068     }
    00069   }
    00070
    00071
    00072   void CameraManipulatorFollow::setHomeViewByAgent() {
    00073     // ok here the camera will center on the robot
    00074     if (watchingAgent!=NULL) {
    00075       // the actual position of the agent has to be recognized
    00076       // we use the Position getPosition() from OdeRobot
    00077       Position robPos = watchingAgent->getRobot()->getPosition();
    00078       // desiredEye is the position of the camera
    00079       // calculate the horizontal angle, means pan (view.x)
    00080       if (robPos.x-desiredEye[0]!=0) { // division by zero
    00081         desiredView[0]= atan((desiredEye[0]-robPos.x)/(robPos.y-desiredEye[1]))
    00082           / PI*180.0f+180.0f;
    00083         if (desiredEye[1]-robPos.y<0) // we must switch
    00084                   desiredView[0]+=180.0f;
    00085       }
    00086       // calculate the vertical angle
    00087       if (robPos.z-desiredEye[2]!=0) { // division by zero
    00088         // need dz and sqrt(dx^2+dy^2) for calulation
    00089         desiredView[1]=-atan((sqrt(square(desiredEye[0]-robPos.x)+
    00090                                   square(desiredEye[1]-robPos.y)))
    00091                             /(robPos.z-desiredEye[2]))
    00092           / PI*180.0f-90.0f;
    00093         if (desiredEye[2]-robPos.z<0) // we must switch
    00094           desiredView[1]+=180.0f;
    00095       }
    00096     }
    00097   }
    00098
    00099 }