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::emitConfigChanged()
00080 {
00081 Q_EMIT configChanged();
00082 }
00083
00084 void ViewController::setTargetFrame(const std::string& reference_frame)
00085 {
00086 Ogre::Vector3 old_position;
00087 Ogre::Quaternion old_orientation;
00088 FrameManager::instance()->getTransform(reference_frame_, ros::Time(), old_position, old_orientation);
00089
00090 reference_frame_ = reference_frame;
00091
00092 Ogre::Vector3 position;
00093 Ogre::Quaternion orientation;
00094 FrameManager::instance()->getTransform(reference_frame_, ros::Time(), position, orientation);
00095
00096 reference_position_ = position;
00097 reference_orientation_ = orientation;
00098
00099 onTargetFrameChanged( old_position, old_orientation );
00100 }
00101
00102 void ViewController::updateTargetSceneNode()
00103 {
00104 Ogre::Vector3 new_reference_position;
00105 Ogre::Quaternion new_reference_orientation;
00106
00107 if (FrameManager::instance()->getTransform(reference_frame_, ros::Time(), new_reference_position, new_reference_orientation) )
00108 {
00109 target_scene_node_->setPosition( new_reference_position );
00110
00111 reference_position_ = new_reference_position;
00112 reference_orientation_ = new_reference_orientation;
00113
00114 manager_->queueRender();
00115 }
00116 }
00117
00118 }