$search
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 <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 ogre_tools 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 // "forward" (negative z) should always be our identity orientation 00119 scene_node_->setOrientation( orientation * Ogre::Quaternion( Ogre::Degree( -90 ), Ogre::Vector3::UNIT_X ) ); 00120 } 00121 00122 void Arrow::setScale( const Ogre::Vector3& scale ) 00123 { 00124 scene_node_->setScale( Ogre::Vector3( scale.x, scale.z, scale.y ) ); 00125 } 00126 00127 const Ogre::Vector3& Arrow::getPosition() 00128 { 00129 return scene_node_->getPosition(); 00130 } 00131 00132 const Ogre::Quaternion& Arrow::getOrientation() 00133 { 00134 return scene_node_->getOrientation(); 00135 } 00136 00137 void Arrow::setUserData( const Ogre::Any& data ) 00138 { 00139 head_->setUserData( data ); 00140 shaft_->setUserData( data ); 00141 } 00142 00143 } // namespace ogre_tools 00144