axes.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 "axes.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 Axes::Axes(Ogre::SceneManager* scene_manager, Ogre::SceneNode* parent_node, float length, float radius)
43  : Object(scene_manager)
44 {
45  if (!parent_node)
46  {
47  parent_node = scene_manager_->getRootSceneNode();
48  }
49 
50  scene_node_ = parent_node->createChildSceneNode();
51 
55 
56  set(length, radius);
57 }
58 
60 {
61  delete x_axis_;
62  delete y_axis_;
63  delete z_axis_;
64 
65  scene_manager_->destroySceneNode(scene_node_->getName());
66 }
67 
68 void Axes::set(float length, float radius)
69 {
70  x_axis_->setScale(Ogre::Vector3(radius, length, radius));
71  y_axis_->setScale(Ogre::Vector3(radius, length, radius));
72  z_axis_->setScale(Ogre::Vector3(radius, length, radius));
73 
74  x_axis_->setPosition(Ogre::Vector3(length / 2.0f, 0.0f, 0.0f));
75  x_axis_->setOrientation(Ogre::Quaternion(Ogre::Degree(-90), Ogre::Vector3::UNIT_Z));
76  y_axis_->setPosition(Ogre::Vector3(0.0f, length / 2.0f, 0.0f));
77  z_axis_->setPosition(Ogre::Vector3(0.0, 0.0f, length / 2.0f));
78  z_axis_->setOrientation(Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3::UNIT_X));
79 
81 }
82 
83 void Axes::setPosition(const Ogre::Vector3& position)
84 {
85  scene_node_->setPosition(position);
86 }
87 
88 void Axes::setOrientation(const Ogre::Quaternion& orientation)
89 {
90  scene_node_->setOrientation(orientation);
91 }
92 
93 void Axes::setScale(const Ogre::Vector3& scale)
94 {
95  scene_node_->setScale(scale);
96 }
97 
98 void Axes::setColor(float /*r*/, float /*g*/, float /*b*/, float /*a*/)
99 {
100  // cannot change color globally, use set[XYZ]Color() instead
101 }
102 
103 const Ogre::Vector3& Axes::getPosition()
104 {
105  return scene_node_->getPosition();
106 }
107 
108 const Ogre::Quaternion& Axes::getOrientation()
109 {
110  return scene_node_->getOrientation();
111 }
112 
113 void Axes::setUserData(const Ogre::Any& data)
114 {
115  x_axis_->setUserData(data);
116  y_axis_->setUserData(data);
117  z_axis_->setUserData(data);
118 }
119 
120 void Axes::setXColor(const Ogre::ColourValue& col)
121 {
122  x_axis_->setColor(col.r, col.g, col.b, col.a);
123 }
124 
125 void Axes::setYColor(const Ogre::ColourValue& col)
126 {
127  y_axis_->setColor(col.r, col.g, col.b, col.a);
128 }
129 
130 void Axes::setZColor(const Ogre::ColourValue& col)
131 {
132  z_axis_->setColor(col.r, col.g, col.b, col.a);
133 }
134 
136 {
137  x_axis_->setColor(1.0f, 0.0f, 0.0f, 1.0f);
138  y_axis_->setColor(0.0f, 1.0f, 0.0f, 1.0f);
139  z_axis_->setColor(0.0f, 0.0f, 1.0f, 1.0f);
140 }
141 
142 const Ogre::ColourValue Axes::default_x_color_(1, 0, 0, 1);
143 const Ogre::ColourValue Axes::default_y_color_(0, 1, 0, 1);
144 const Ogre::ColourValue Axes::default_z_color_(0, 0, 1, 1);
145 
146 const Ogre::ColourValue& Axes::getDefaultXColor()
147 {
148  return default_x_color_;
149 }
150 
151 const Ogre::ColourValue& Axes::getDefaultYColor()
152 {
153  return default_y_color_;
154 }
155 
156 const Ogre::ColourValue& Axes::getDefaultZColor()
157 {
158  return default_z_color_;
159 }
160 
161 } // namespace rviz
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: axes.cpp:88
void setOrientation(const Ogre::Quaternion &orientation) override
Set the orientation of the object.
Definition: shape.cpp:155
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
Ogre::SceneNode * scene_node_
Definition: axes.h:131
static const Ogre::ColourValue & getDefaultYColor()
Definition: axes.cpp:151
Shape * y_axis_
Cylinder for the Y-axis.
Definition: axes.h:134
void setUserData(const Ogre::Any &data) override
Sets user data on all ogre objects we own.
Definition: shape.cpp:175
void setZColor(const Ogre::ColourValue &col)
Definition: axes.cpp:130
static const Ogre::ColourValue & getDefaultXColor()
Definition: axes.cpp:146
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
void setYColor(const Ogre::ColourValue &col)
Definition: axes.cpp:125
Base class for visible objects, providing a minimal generic interface.
Definition: object.h:50
void setXColor(const Ogre::ColourValue &col)
Definition: axes.cpp:120
Shape * x_axis_
Cylinder for the X-axis.
Definition: axes.h:133
void setToDefaultColors()
Definition: axes.cpp:135
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: axes.cpp:98
Axes(Ogre::SceneManager *manager, Ogre::SceneNode *parent_node=nullptr, float length=1.0f, float radius=0.1f)
Constructor.
Definition: axes.cpp:42
static const Ogre::ColourValue default_z_color_
Definition: axes.h:139
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: axes.cpp:83
void setPosition(const Ogre::Vector3 &position) override
Set the position of this object.
Definition: shape.cpp:150
Shape * z_axis_
Cylinder for the Z-axis.
Definition: axes.h:135
void set(float length, float radius)
Set the parameters on this object.
Definition: axes.cpp:68
Ogre::SceneManager * scene_manager_
Ogre scene manager this object is part of.
Definition: object.h:106
static const Ogre::ColourValue default_y_color_
Definition: axes.h:138
static const Ogre::ColourValue & getDefaultZColor()
Definition: axes.cpp:156
void setScale(const Ogre::Vector3 &scale) override
Set the scale of the object. Always relative to the identity orientation of the object.
Definition: axes.cpp:93
void setUserData(const Ogre::Any &data) override
Sets user data on all ogre objects we own.
Definition: axes.cpp:113
const Ogre::Vector3 & getPosition() override
Get the local position of this object.
Definition: axes.cpp:103
static const Ogre::ColourValue default_x_color_
Definition: axes.h:137
~Axes() override
Definition: axes.cpp:59
const Ogre::Quaternion & getOrientation() override
Get the local orientation of this object.
Definition: axes.cpp:108


rviz
Author(s): Dave Hershberger, David Gossow, Josh Faust
autogenerated on Sat May 27 2023 02:06:24