axes.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 "axes.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 Axes::Axes( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node, float length, float radius )
00044     : Object( scene_manager )
00045 {
00046   if ( !parent_node )
00047   {
00048     parent_node = scene_manager_->getRootSceneNode();
00049   }
00050 
00051   scene_node_ = parent_node->createChildSceneNode();
00052 
00053   x_axis_ = new Shape( Shape::Cylinder, scene_manager_, scene_node_ );
00054   y_axis_ = new Shape( Shape::Cylinder, scene_manager_, scene_node_ );
00055   z_axis_ = new Shape( Shape::Cylinder, scene_manager_, scene_node_ );
00056 
00057   set( length, radius );
00058 }
00059 
00060 Axes::~Axes()
00061 {
00062   delete x_axis_;
00063   delete y_axis_;
00064   delete z_axis_;
00065 
00066   scene_manager_->destroySceneNode( scene_node_->getName() );
00067 }
00068 
00069 void Axes::set( float length, float radius )
00070 {
00071   x_axis_->setScale(Ogre::Vector3( radius, length, radius ));
00072   y_axis_->setScale(Ogre::Vector3( radius, length, radius ));
00073   z_axis_->setScale(Ogre::Vector3( radius, length, radius ));
00074 
00075   x_axis_->setPosition( Ogre::Vector3( length/2.0f, 0.0f, 0.0f ) );
00076   x_axis_->setOrientation( Ogre::Quaternion( Ogre::Degree( -90 ), Ogre::Vector3::UNIT_Z ) );
00077   y_axis_->setPosition( Ogre::Vector3( 0.0f, length/2.0f, 0.0f ) );
00078   z_axis_->setPosition( Ogre::Vector3( 0.0, 0.0f, length/2.0f ) );
00079   z_axis_->setOrientation( Ogre::Quaternion( Ogre::Degree( 90 ), Ogre::Vector3::UNIT_X ) );
00080 
00081   setToDefaultColors();
00082 }
00083 
00084 void Axes::setPosition( const Ogre::Vector3& position )
00085 {
00086   scene_node_->setPosition( position );
00087 }
00088 
00089 void Axes::setOrientation( const Ogre::Quaternion& orientation )
00090 {
00091   scene_node_->setOrientation( orientation );
00092 }
00093 
00094 void Axes::setScale( const Ogre::Vector3& scale )
00095 {
00096   scene_node_->setScale( scale );
00097 }
00098 
00099 void Axes::setColor( float r, float g, float b, float a )
00100 {
00101   // for now, do nothing
00103 }
00104 
00105 const Ogre::Vector3& Axes::getPosition()
00106 {
00107   return scene_node_->getPosition();
00108 }
00109 
00110 const Ogre::Quaternion& Axes::getOrientation()
00111 {
00112   return scene_node_->getOrientation();
00113 }
00114 
00115 void Axes::setUserData( const Ogre::Any& data )
00116 {
00117   x_axis_->setUserData( data );
00118   y_axis_->setUserData( data );
00119   z_axis_->setUserData( data );
00120 }
00121 
00122 void Axes::setXColor(const Ogre::ColourValue& col)
00123 {
00124   x_axis_->setColor(col.r, col.g, col.b, col.a);
00125 }
00126 
00127 void Axes::setYColor(const Ogre::ColourValue& col)
00128 {
00129   y_axis_->setColor(col.r, col.g, col.b, col.a);
00130 }
00131 
00132 void Axes::setZColor(const Ogre::ColourValue& col)
00133 {
00134   z_axis_->setColor(col.r, col.g, col.b, col.a);
00135 }
00136 
00137 void Axes::setToDefaultColors()
00138 {
00139   x_axis_->setColor( 1.0f, 0.0f, 0.0f, 1.0f );
00140   y_axis_->setColor( 0.0f, 1.0f, 0.0f, 1.0f );
00141   z_axis_->setColor( 0.0f, 0.0f, 1.0f, 1.0f );
00142 }
00143 
00144 const Ogre::ColourValue Axes::default_x_color_( 1, 0, 0, 1 );
00145 const Ogre::ColourValue Axes::default_y_color_( 0, 1, 0, 1 );
00146 const Ogre::ColourValue Axes::default_z_color_( 0, 0, 1, 1 );
00147 
00148 const Ogre::ColourValue& Axes::getDefaultXColor()
00149 {
00150   return default_x_color_;
00151 }
00152 
00153 const Ogre::ColourValue& Axes::getDefaultYColor()
00154 {
00155   return default_y_color_;
00156 }
00157 
00158 const Ogre::ColourValue& Axes::getDefaultZColor()
00159 {
00160   return default_z_color_;
00161 }
00162 
00163 } // namespace rviz
00164 


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