arrow.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, 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 "arrow.h"
00031 #include "shape.h"
00032 
00033 #include <OgreSceneManager.h>
00034 #include <OgreSceneNode.h>
00035 #include <OgreVector3.h>
00036 #include <OgreQuaternion.h>
00037 
00038 #include <sstream>
00039 
00040 namespace rviz
00041 {
00042 
00043 Arrow::Arrow( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node, float shaft_length, float shaft_diameter,
00044               float head_length, float head_diameter )
00045 : Object( scene_manager )
00046 {
00047   if ( !parent_node )
00048   {
00049     parent_node = scene_manager_->getRootSceneNode();
00050   }
00051 
00052   scene_node_ = parent_node->createChildSceneNode();
00053 
00054   shaft_ = new Shape( Shape::Cylinder, scene_manager_, scene_node_ );
00055   head_ = new Shape( Shape::Cone, scene_manager_, scene_node_ );
00056   head_->setOffset(Ogre::Vector3(0.0f, 0.5f, 0.0f));
00057 
00058   set( shaft_length, shaft_diameter, head_length, head_diameter );
00059 
00060   setOrientation( Ogre::Quaternion::IDENTITY );
00061 }
00062 
00063 Arrow::~Arrow()
00064 {
00065   delete shaft_;
00066   delete head_;
00067 
00068   scene_manager_->destroySceneNode( scene_node_->getName() );
00069 }
00070 
00071 void Arrow::set( float shaft_length, float shaft_diameter, float head_length, float head_diameter )
00072 {
00073   shaft_->setScale(Ogre::Vector3(shaft_diameter, shaft_length, shaft_diameter));
00074   shaft_->setPosition( Ogre::Vector3( 0.0f, shaft_length/2.0f, 0.0f ) );
00075 
00076   head_->setScale( Ogre::Vector3( head_diameter, head_length, head_diameter ) );
00077   head_->setPosition( Ogre::Vector3( 0.0f, shaft_length, 0.0f ) );
00078 }
00079 
00080 void Arrow::setColor(const Ogre::ColourValue& c)
00081 {
00082   setShaftColor(c);
00083   setHeadColor(c);
00084 }
00085 
00086 void Arrow::setColor( float r, float g, float b, float a )
00087 {
00088   setColor(Ogre::ColourValue(r, g, b, a));
00089 }
00090 
00091 void Arrow::setShaftColor(const Ogre::ColourValue& c)
00092 {
00093   shaft_->setColor(c);
00094 }
00095 
00096 void Arrow::setHeadColor(const Ogre::ColourValue& c)
00097 {
00098   head_->setColor(c);
00099 }
00100 
00101 void Arrow::setShaftColor( float r, float g, float b, float a )
00102 {
00103   setShaftColor( Ogre::ColourValue(r, g, b, a ));
00104 }
00105 
00106 void Arrow::setHeadColor( float r, float g, float b, float a )
00107 {
00108   setHeadColor( Ogre::ColourValue(r, g, b, a ));
00109 }
00110 
00111 void Arrow::setPosition( const Ogre::Vector3& position )
00112 {
00113   scene_node_->setPosition( position );
00114 }
00115 
00116 void Arrow::setOrientation( const Ogre::Quaternion& orientation )
00117 {
00118   // "forward" (negative z) should always be our identity orientation
00119   // ... wouldn't need to mangle the orientation if we just fix the cylinders!
00120   scene_node_->setOrientation( orientation * Ogre::Quaternion( Ogre::Degree( -90 ), Ogre::Vector3::UNIT_X ) );
00121 }
00122 
00123 void Arrow::setDirection( const Ogre::Vector3& direction )
00124 {
00125   if( !direction.isZeroLength() )
00126   {
00127     setOrientation( Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo( direction ));
00128   }
00129 }
00130 
00131 void Arrow::setScale( const Ogre::Vector3& scale )
00132 {
00133   // Have to mangle the scale because of the default orientation of the cylinders :(
00134   scene_node_->setScale( Ogre::Vector3( scale.z, scale.x, scale.y ) );
00135 }
00136 
00137 const Ogre::Vector3& Arrow::getPosition()
00138 {
00139   return scene_node_->getPosition();
00140 }
00141 
00142 const Ogre::Quaternion& Arrow::getOrientation()
00143 {
00144   return scene_node_->getOrientation();
00145 }
00146 
00147 void Arrow::setUserData( const Ogre::Any& data )
00148 {
00149   head_->setUserData( data );
00150   shaft_->setUserData( data );
00151 }
00152 
00153 } // namespace rviz
00154 


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