arrow.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #include "arrow.h"
31 #include "shape.h"
32 
33 #include <OgreSceneManager.h>
34 #include <OgreSceneNode.h>
35 #include <OgreVector3.h>
36 #include <OgreQuaternion.h>
37 
38 #include <sstream>
39 
40 namespace rviz
41 {
42 
43 Arrow::Arrow( Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node, float shaft_length, float shaft_diameter,
44  float head_length, float head_diameter )
45 : Object( scene_manager )
46 {
47  if ( !parent_node )
48  {
49  parent_node = scene_manager_->getRootSceneNode();
50  }
51 
52  scene_node_ = parent_node->createChildSceneNode();
53 
56  head_->setOffset(Ogre::Vector3(0.0f, 0.5f, 0.0f));
57 
58  set( shaft_length, shaft_diameter, head_length, head_diameter );
59 
60  setOrientation( Ogre::Quaternion::IDENTITY );
61 }
62 
64 {
65  delete shaft_;
66  delete head_;
67 
68  scene_manager_->destroySceneNode( scene_node_->getName() );
69 }
70 
71 void Arrow::set( float shaft_length, float shaft_diameter, float head_length, float head_diameter )
72 {
73  shaft_->setScale(Ogre::Vector3(shaft_diameter, shaft_length, shaft_diameter));
74  shaft_->setPosition( Ogre::Vector3( 0.0f, shaft_length/2.0f, 0.0f ) );
75 
76  head_->setScale( Ogre::Vector3( head_diameter, head_length, head_diameter ) );
77  head_->setPosition( Ogre::Vector3( 0.0f, shaft_length, 0.0f ) );
78 }
79 
80 void Arrow::setColor(const Ogre::ColourValue& c)
81 {
82  setShaftColor(c);
83  setHeadColor(c);
84 }
85 
86 void Arrow::setColor( float r, float g, float b, float a )
87 {
88  setColor(Ogre::ColourValue(r, g, b, a));
89 }
90 
91 void Arrow::setShaftColor(const Ogre::ColourValue& c)
92 {
93  shaft_->setColor(c);
94 }
95 
96 void Arrow::setHeadColor(const Ogre::ColourValue& c)
97 {
98  head_->setColor(c);
99 }
100 
101 void Arrow::setShaftColor( float r, float g, float b, float a )
102 {
103  setShaftColor( Ogre::ColourValue(r, g, b, a ));
104 }
105 
106 void Arrow::setHeadColor( float r, float g, float b, float a )
107 {
108  setHeadColor( Ogre::ColourValue(r, g, b, a ));
109 }
110 
111 void Arrow::setPosition( const Ogre::Vector3& position )
112 {
113  scene_node_->setPosition( position );
114 }
115 
116 void Arrow::setOrientation( const Ogre::Quaternion& orientation )
117 {
118  // "forward" (negative z) should always be our identity orientation
119  // ... wouldn't need to mangle the orientation if we just fix the cylinders!
120  scene_node_->setOrientation( orientation * Ogre::Quaternion( Ogre::Degree( -90 ), Ogre::Vector3::UNIT_X ) );
121 }
122 
123 void Arrow::setDirection( const Ogre::Vector3& direction )
124 {
125  if( !direction.isZeroLength() )
126  {
127  setOrientation( Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo( direction ));
128  }
129 }
130 
131 void Arrow::setScale( const Ogre::Vector3& scale )
132 {
133  // Have to mangle the scale because of the default orientation of the cylinders :(
134  scene_node_->setScale( Ogre::Vector3( scale.z, scale.x, scale.y ) );
135 }
136 
137 const Ogre::Vector3& Arrow::getPosition()
138 {
139  return scene_node_->getPosition();
140 }
141 
142 const Ogre::Quaternion& Arrow::getOrientation()
143 {
144  return scene_node_->getOrientation();
145 }
146 
147 void Arrow::setUserData( const Ogre::Any& data )
148 {
149  head_->setUserData( data );
150  shaft_->setUserData( data );
151 }
152 
153 } // namespace rviz
154 
Ogre::SceneNode * scene_node_
Definition: arrow.h:154
virtual const Ogre::Vector3 & getPosition()
Get the local position of this object.
Definition: arrow.cpp:137
f
void setUserData(const Ogre::Any &data)
Sets user data on all ogre objects we own.
Definition: shape.cpp:177
void setDirection(const Ogre::Vector3 &direction)
Set the direction of the arrow.
Definition: arrow.cpp:123
virtual ~Arrow()
Definition: arrow.cpp:63
void set(float shaft_length, float shaft_diameter, float head_length, float head_diameter)
Set the parameters for this arrow.
Definition: arrow.cpp:71
virtual void setColor(float r, float g, float b, float a)
Set the color of the object. Values are in the range [0, 1].
Definition: shape.cpp:142
Base class for visible objects, providing a minimal generic interface.
Definition: object.h:49
void setUserData(const Ogre::Any &data)
Sets user data on all ogre objects we own.
Definition: arrow.cpp:147
virtual void setPosition(const Ogre::Vector3 &position)
Set the position of the base of the arrow.
Definition: arrow.cpp:111
virtual void setScale(const Ogre::Vector3 &scale)
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: arrow.cpp:131
virtual void setPosition(const Ogre::Vector3 &position)
Set the position of this object.
Definition: shape.cpp:152
Arrow(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node=0, float shaft_length=1.0f, float shaft_diameter=0.1f, float head_length=0.3f, float head_diameter=0.2f)
Constructor.
Definition: arrow.cpp:43
virtual const Ogre::Quaternion & getOrientation()
Get the local orientation of this object.
Definition: arrow.cpp:142
virtual void setColor(float r, float g, float b, float a)
Set the color of this arrow. Sets both the head and shaft color to the same value. Values are in the range [0, 1].
Definition: arrow.cpp:86
Shape * head_
Cone used for the head of the arrow.
Definition: arrow.h:157
virtual void setOrientation(const Ogre::Quaternion &orientation)
Set the orientation.
Definition: arrow.cpp:116
void setShaftColor(float r, float g, float b, float a=1.0f)
Set the color of the arrow&#39;s shaft. Values are in the range [0, 1].
Definition: arrow.cpp:101
Ogre::SceneManager * scene_manager_
Ogre scene manager this object is part of.
Definition: object.h:103
void setOffset(const Ogre::Vector3 &offset)
Set the offset for this shape.
Definition: shape.cpp:147
void setHeadColor(float r, float g, float b, float a=1.0f)
Set the color of the arrow&#39;s head. Values are in the range [0, 1].
Definition: arrow.cpp:106
virtual void setScale(const Ogre::Vector3 &scale)
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: shape.cpp:162
Shape * shaft_
Cylinder used for the shaft of the arrow.
Definition: arrow.h:156


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Wed Aug 28 2019 04:01:50