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 <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   // NOTE: The second parameter to the create method is the resource group the material will be added to.
00057   // If the group you name does not exist (in your resources.cfg file) the library will assert() and your program will crash
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 }


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Oct 6 2014 07:26:35