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 "line.h"
00031
00032 #include <sstream>
00033
00034 #include <OGRE/OgreSceneNode.h>
00035 #include <OGRE/OgreSceneManager.h>
00036 #include <OGRE/OgreManualObject.h>
00037 #include <OGRE/OgreMaterialManager.h>
00038
00039 namespace rviz
00040 {
00041
00042 Line::Line( Ogre::SceneManager* manager, Ogre::SceneNode* parent_node )
00043 : Object( manager )
00044 {
00045 if (!parent_node)
00046 {
00047 parent_node = manager->getRootSceneNode();
00048 }
00049 manual_object_ = manager->createManualObject();
00050 scene_node_ = parent_node->createChildSceneNode();
00051
00052 static int count = 0;
00053 std::stringstream ss;
00054 ss << "LineMaterial" << count++;
00055
00056
00057
00058 manual_object_material_ = Ogre::MaterialManager::getSingleton().create(ss.str(),"rviz");
00059 manual_object_material_->setReceiveShadows(false);
00060 manual_object_material_->getTechnique(0)->setLightingEnabled(true);
00061 manual_object_material_->getTechnique(0)->getPass(0)->setDiffuse(0,0,0,0);
00062 manual_object_material_->getTechnique(0)->getPass(0)->setAmbient(1,1,1);
00063
00064 scene_node_->attachObject(manual_object_);
00065 }
00066
00067 Line::~Line()
00068 {
00069 if ( scene_node_->getParentSceneNode() )
00070 {
00071 scene_node_->getParentSceneNode()->removeChild(scene_node_);
00072 }
00073 scene_manager_->destroySceneNode(scene_node_);
00074 scene_manager_->destroyManualObject( manual_object_ );
00075 Ogre::MaterialManager::getSingleton().remove(manual_object_material_->getName());
00076 }
00077
00078 void Line::setPoints( Ogre::Vector3 start, Ogre::Vector3 end )
00079 {
00080 manual_object_->clear();
00081 manual_object_->begin(manual_object_material_->getName(), Ogre::RenderOperation::OT_LINE_LIST);
00082 manual_object_->position(start);
00083 manual_object_->position(end);
00084 manual_object_->end();
00085 setVisible(true);
00086 }
00087
00088 void Line::setVisible( bool visible )
00089 {
00090 scene_node_->setVisible(visible,true);
00091 }
00092
00093
00094 void Line::setPosition( const Ogre::Vector3& position )
00095 {
00096 scene_node_->setPosition( position );
00097 }
00098
00099 void Line::setOrientation( const Ogre::Quaternion& orientation )
00100 {
00101 scene_node_->setOrientation( orientation );
00102 }
00103
00104 void Line::setScale( const Ogre::Vector3& scale )
00105 {
00106 scene_node_->setScale( scale );
00107 }
00108
00109 void Line::setColor( float r, float g, float b, float a )
00110 {
00111 manual_object_material_->getTechnique(0)->getPass(0)->setDiffuse(r,g,b,a);
00112 }
00113
00114 const Ogre::Vector3& Line::getPosition()
00115 {
00116 return scene_node_->getPosition();
00117 }
00118
00119 const Ogre::Quaternion& Line::getOrientation()
00120 {
00121 return scene_node_->getOrientation();
00122 }
00123
00124 void Line::setUserData( const Ogre::Any& data )
00125 {
00126 manual_object_->setUserAny( data );
00127 }
00128
00129
00130 }