00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <osg/Notify>
00034 #include "cameramanipulatorRace.h"
00035 #include "mathutils.h"
00036 #include "pos.h"
00037 #include <stdio.h>
00038
00039
00040 #define square(x) ((x)*(x))
00041
00042 namespace lpzrobots {
00043
00044 using namespace osg;
00045 using namespace osgGA;
00046
00047 CameraManipulatorRace::CameraManipulatorRace(osg::Node* node,GlobalData& global)
00048 : CameraManipulator(node,global) {}
00049
00050 CameraManipulatorRace::~CameraManipulatorRace(){}
00051
00052
00053 void CameraManipulatorRace::calcMovementByAgent() {
00054 if (watchingAgent!=NULL) {
00055
00056 const double* robMove = (watchingAgent->getRobot()->getPosition()-oldPositionOfAgent).toArray();
00057
00058 for (int i=0;i<=2;i++) {
00059 if (!isNaN(robMove[i])) {
00060 desiredEye[i]+=robMove[i];}
00061 else
00062 std::cout << "NAN exception!" << std::endl;
00063 }
00064
00065
00066 matrix::Matrix Orientation= (watchingAgent->getRobot()->getOrientation());
00067 Orientation.toTranspose();
00068
00069 double eVecX[3] = {0,1,0};
00070 double eVecY[3] = {1,0,0};
00071 matrix::Matrix normVecX = Orientation * matrix::Matrix(3,1,eVecX);
00072 matrix::Matrix normVecY = Orientation * matrix::Matrix(3,1,eVecY);
00073
00074 Position robPos = watchingAgent->getRobot()->getPosition();
00075 double distance = sqrt(square(desiredEye[0]-robPos.x)+
00076 square(desiredEye[1]-robPos.y));
00077
00078 desiredEye[0]=robPos.x + distance *normVecX.val(1,0);
00079 desiredEye[1]=robPos.y - distance *normVecY.val(1,0);
00080
00081
00082
00083
00084 if (robPos.x-desiredEye[0]!=0) {
00085 desiredView[0]= atan((desiredEye[0]-robPos.x)/(robPos.y-desiredEye[1]))
00086 / PI*180.0f+180.0f;
00087 if (desiredEye[1]-robPos.y<0)
00088 desiredView[0]+=180.0f;
00089 }
00090
00091 if (robPos.z-desiredEye[2]!=0) {
00092
00093 desiredView[1]=-atan((sqrt(square(desiredEye[0]-robPos.x)+
00094 square(desiredEye[1]-robPos.y)))
00095 /(robPos.z-desiredEye[2]))
00096 / PI*180.0f-90.0f;
00097 if (desiredEye[2]-robPos.z<0)
00098 desiredView[1]+=180.0f;
00099 }
00100 }
00101 }
00102 }