Go to the documentation of this file.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 #include "view_controller.h"
00031 #include "viewport_mouse_event.h"
00032 #include "visualization_manager.h"
00033 #include "frame_manager.h"
00034
00035 #include <OGRE/OgreCamera.h>
00036 #include <OGRE/OgreSceneNode.h>
00037 #include <OGRE/OgreSceneManager.h>
00038
00039 namespace rviz
00040 {
00041
00042 ViewController::ViewController(VisualizationManager* manager, const std::string& name, Ogre::SceneNode* target_scene_node)
00043 : manager_(manager)
00044 , camera_(0)
00045 , target_scene_node_(target_scene_node)
00046 , name_(name)
00047 {
00048 }
00049
00050 ViewController::~ViewController()
00051 {
00052
00053 }
00054
00055 void ViewController::activate(Ogre::Camera* camera, const std::string& reference_frame)
00056 {
00057 camera_ = camera;
00058 reference_frame_ = reference_frame;
00059 updateTargetSceneNode();
00060 target_scene_node_->attachObject(camera_);
00061
00062 onActivate();
00063 }
00064
00065 void ViewController::deactivate()
00066 {
00067 onDeactivate();
00068
00069 target_scene_node_->detachObject(camera_);
00070 camera_ = 0;
00071 }
00072
00073 void ViewController::update(float dt, float ros_dt)
00074 {
00075 updateTargetSceneNode();
00076 onUpdate(dt, ros_dt);
00077 }
00078
00079 void ViewController::setTargetFrame(const std::string& reference_frame)
00080 {
00081 Ogre::Vector3 old_position;
00082 Ogre::Quaternion old_orientation;
00083 FrameManager::instance()->getTransform(reference_frame_, ros::Time(), old_position, old_orientation);
00084
00085 reference_frame_ = reference_frame;
00086
00087 Ogre::Vector3 position;
00088 Ogre::Quaternion orientation;
00089 FrameManager::instance()->getTransform(reference_frame_, ros::Time(), position, orientation);
00090
00091 reference_position_ = position;
00092 reference_orientation_ = orientation;
00093
00094 onTargetFrameChanged( old_position, old_orientation );
00095 }
00096
00097 void ViewController::updateTargetSceneNode()
00098 {
00099 Ogre::Vector3 new_reference_position;
00100 Ogre::Quaternion new_reference_orientation;
00101
00102 if (FrameManager::instance()->getTransform(reference_frame_, ros::Time(), new_reference_position, new_reference_orientation) )
00103 {
00104 target_scene_node_->setPosition( new_reference_position );
00105
00106 reference_position_ = new_reference_position;
00107 reference_orientation_ = new_reference_orientation;
00108
00109 manager_->queueRender();
00110 }
00111 }
00112
00113 }