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


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