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 Arrow::Arrow(Ogre::SceneManager* scene_manager,
43  Ogre::SceneNode* parent_node,
44  float shaft_length,
45  float shaft_diameter,
46  float head_length,
47  float head_diameter)
48  : Object(scene_manager)
49 {
50  if (!parent_node)
51  {
52  parent_node = scene_manager_->getRootSceneNode();
53  }
54 
55  scene_node_ = parent_node->createChildSceneNode();
56 
59  head_->setOffset(Ogre::Vector3(0.0f, 0.5f, 0.0f));
60 
61  set(shaft_length, shaft_diameter, head_length, head_diameter);
62 
63  setOrientation(Ogre::Quaternion::IDENTITY);
64 }
65 
67 {
68  delete shaft_;
69  delete head_;
70 
71  scene_manager_->destroySceneNode(scene_node_->getName());
72 }
73 
74 void Arrow::set(float shaft_length, float shaft_diameter, float head_length, float head_diameter)
75 {
76  shaft_->setScale(Ogre::Vector3(shaft_diameter, shaft_length, shaft_diameter));
77  shaft_->setPosition(Ogre::Vector3(0.0f, shaft_length / 2.0f, 0.0f));
78 
79  head_->setScale(Ogre::Vector3(head_diameter, head_length, head_diameter));
80  head_->setPosition(Ogre::Vector3(0.0f, shaft_length, 0.0f));
81 }
82 
83 void Arrow::setColor(const Ogre::ColourValue& c)
84 {
85  setShaftColor(c);
86  setHeadColor(c);
87 }
88 
89 void Arrow::setColor(float r, float g, float b, float a)
90 {
91  setColor(Ogre::ColourValue(r, g, b, a));
92 }
93 
94 void Arrow::setShaftColor(const Ogre::ColourValue& c)
95 {
96  shaft_->setColor(c);
97 }
98 
99 void Arrow::setHeadColor(const Ogre::ColourValue& c)
100 {
101  head_->setColor(c);
102 }
103 
104 void Arrow::setShaftColor(float r, float g, float b, float a)
105 {
106  setShaftColor(Ogre::ColourValue(r, g, b, a));
107 }
108 
109 void Arrow::setHeadColor(float r, float g, float b, float a)
110 {
111  setHeadColor(Ogre::ColourValue(r, g, b, a));
112 }
113 
114 void Arrow::setPosition(const Ogre::Vector3& position)
115 {
116  scene_node_->setPosition(position);
117 }
118 
119 void Arrow::setOrientation(const Ogre::Quaternion& orientation)
120 {
121  // "forward" (negative z) should always be our identity orientation
122  // ... wouldn't need to mangle the orientation if we just fix the cylinders!
123  scene_node_->setOrientation(orientation * Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_X));
124 }
125 
126 void Arrow::setDirection(const Ogre::Vector3& direction)
127 {
128  if (!direction.isZeroLength())
129  {
130  setOrientation(Ogre::Vector3::NEGATIVE_UNIT_Z.getRotationTo(direction));
131  }
132 }
133 
134 void Arrow::setScale(const Ogre::Vector3& scale)
135 {
136  // Have to mangle the scale because of the default orientation of the cylinders :(
137  scene_node_->setScale(Ogre::Vector3(scale.z, scale.x, scale.y));
138 }
139 
140 const Ogre::Vector3& Arrow::getPosition()
141 {
142  return scene_node_->getPosition();
143 }
144 
145 const Ogre::Quaternion& Arrow::getOrientation()
146 {
147  return scene_node_->getOrientation();
148 }
149 
150 void Arrow::setUserData(const Ogre::Any& data)
151 {
152  head_->setUserData(data);
153  shaft_->setUserData(data);
154 }
155 
156 } // namespace rviz
Ogre::SceneNode * scene_node_
Definition: arrow.h:169
const Ogre::Vector3 & getPosition() override
Get the local position of this object.
Definition: arrow.cpp:140
f
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: shape.cpp:160
void setDirection(const Ogre::Vector3 &direction)
Set the direction of the arrow.
Definition: arrow.cpp:126
void setPosition(const Ogre::Vector3 &position) override
Set the position of the base of the arrow.
Definition: arrow.cpp:114
Arrow(Ogre::SceneManager *scene_manager, Ogre::SceneNode *parent_node=nullptr, float shaft_length=1.0f, float shaft_diameter=0.1f, float head_length=0.3f, float head_diameter=0.2f)
Constructor.
Definition: arrow.cpp:42
void setUserData(const Ogre::Any &data) override
Sets user data on all ogre objects we own.
Definition: shape.cpp:175
void set(float shaft_length, float shaft_diameter, float head_length, float head_diameter)
Set the parameters for this arrow.
Definition: arrow.cpp:74
void setColor(float r, float g, float b, float a) override
Set the color of the object. Values are in the range [0, 1].
Definition: shape.cpp:140
Base class for visible objects, providing a minimal generic interface.
Definition: object.h:50
~Arrow() override
Definition: arrow.cpp:66
Shape * head_
Cone used for the head of the arrow.
Definition: arrow.h:172
const Ogre::Quaternion & getOrientation() override
Get the local orientation of this object.
Definition: arrow.cpp:145
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:104
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: arrow.cpp:134
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: shape.cpp:150
void setUserData(const Ogre::Any &data) override
Sets user data on all ogre objects we own.
Definition: arrow.cpp:150
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation.
Definition: arrow.cpp:119
Ogre::SceneManager * scene_manager_
Ogre scene manager this object is part of.
Definition: object.h:106
void setColor(float r, float g, float b, float a) override
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:89
void setOffset(const Ogre::Vector3 &offset)
Set the offset for this shape.
Definition: shape.cpp:145
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:109
Shape * shaft_
Cylinder used for the shaft of the arrow.
Definition: arrow.h:171


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Mon Aug 15 2022 02:05:16