line.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Willow Garage, Inc.
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the Willow Garage, Inc. nor the names of its
00014  *       contributors may be used to endorse or promote products derived from
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
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   // NOTE: The second parameter to the create method is the resource group the material will be added to.
00058   // If the group you name does not exist (in your resources.cfg file) the library will assert() and your program will crash
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( float r, float g, float b, float a )
00111 {
00112   manual_object_material_->getTechnique(0)->getPass(0)->setDiffuse(r,g,b,a);
00113 }
00114 
00115 const Ogre::Vector3& Line::getPosition()
00116 {
00117   return scene_node_->getPosition();
00118 }
00119 
00120 const Ogre::Quaternion& Line::getOrientation()
00121 {
00122   return scene_node_->getOrientation();
00123 }
00124 
00125 void Line::setUserData( const Ogre::Any& data )
00126 {
00127   manual_object_->setUserAny( data );
00128 }
00129 
00130 
00131 }


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Thu Aug 27 2015 15:02:27