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