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 <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
00119
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
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 }
00154