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 "arrow.h"
00031 #include "shape.h"
00032
00033 #include <OGRE/OgreSceneManager.h>
00034 #include <OGRE/OgreSceneNode.h>
00035 #include <OGRE/OgreVector3.h>
00036 #include <OGRE/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_radius,
00044 float head_length, float head_radius )
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_radius, head_length, head_radius );
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_radius, float head_length, float head_radius )
00072 {
00073 shaft_->setScale(Ogre::Vector3(shaft_radius / 2.0f, shaft_length, shaft_radius / 2.0f));
00074 shaft_->setPosition( Ogre::Vector3( 0.0f, shaft_length/2.0f, 0.0f ) );
00075
00076 head_->setScale( Ogre::Vector3( head_radius / 2.0f, head_length, head_radius / 2.0f ) );
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
00119 scene_node_->setOrientation( orientation * Ogre::Quaternion( Ogre::Degree( -90 ), Ogre::Vector3::UNIT_X ) );
00120 }
00121
00122 void Arrow::setDirection( const Ogre::Vector3& direction )
00123 {
00124 if( !direction.isZeroLength() )
00125 {
00126 setOrientation( Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo( direction ));
00127 }
00128 }
00129
00130 void Arrow::setScale( const Ogre::Vector3& scale )
00131 {
00132 scene_node_->setScale( Ogre::Vector3( scale.x, scale.z, scale.y ) );
00133 }
00134
00135 const Ogre::Vector3& Arrow::getPosition()
00136 {
00137 return scene_node_->getPosition();
00138 }
00139
00140 const Ogre::Quaternion& Arrow::getOrientation()
00141 {
00142 return scene_node_->getOrientation();
00143 }
00144
00145 void Arrow::setUserData( const Ogre::Any& data )
00146 {
00147 head_->setUserData( data );
00148 shaft_->setUserData( data );
00149 }
00150
00151 }
00152