OpenFrames
Sphere.hpp
Go to the documentation of this file.
1 /***********************************
2  Copyright 2018 Ravishankar Mathur
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 ***********************************/
16 
21 #ifndef _OF_SPHERE_
22 #define _OF_SPHERE_
23 
24 #include <OpenFrames/Export.h>
26 #include <osg/Geode>
27 #include <osg/Material>
28 #include <string>
29 
30 namespace OpenFrames
31 {
41  class OF_EXPORT Sphere : public ReferenceFrame
42  {
43  public:
44  Sphere( const std::string &name );
45  Sphere( const std::string &name, const osg::Vec3 &color );
46  Sphere( const std::string &name, const osg::Vec4 &color );
47  Sphere( const std::string &name , float r, float g, float b, float a = 1.0 );
48 
49  // Show/hide this frame's contents, e.g. everything a frame shows (excluding axes, labels, and children)
50  // Inherited from ReferenceFrame
51  virtual void showContents(bool showContents);
52  virtual bool getContentsShown() const;
53 
57  void restoreTexCoords();
58 
61  void setRadius( const double &radius );
62  double getRadius() const;
63 
65  void setSpherePosition( const double &x, const double &y, const double &z );
66 
67  void setSpherePosition( const osg::Vec3d &pos )
68  { _sphereXform->setPosition(pos); }
69 
70  void getSpherePosition( double &x, double &y, double &z ) const
71  { _sphereXform->getPosition(x, y, z); }
72 
73  void getSpherePosition( osg::Vec3d &pos ) const
74  { _sphereXform->getPosition(pos); }
75 
78  void setSphereAttitude( const osg::Quat &att )
79  { _sphereXform->setAttitude(att); }
80 
81  void getSphereAttitude( osg::Quat &att ) const
82  { _sphereXform->getAttitude(att); }
83 
86  void setSphereScale( const double &sx, const double &sy, const double &sz);
87 
88  void getSphereScale( double &sx, double &sy, double &sz ) const
89  {
90  _sphereXform->getScale(sx, sy, sz);
91  }
92 
95  bool setTextureMap( const std::string &fname, unsigned int unit = 0, bool force_reload = false );
96 
98  bool setTexEnv(osg::StateAttribute* texenv, unsigned int unit);
99 
102  bool setNightTextureMap(const std::string &fname, unsigned int unit = 1, bool force_reload = false);
103 
106  void setAutoLOD( bool lod );
107 
111  virtual void setColor( const osg::Vec4 &color );
112  using ReferenceFrame::setColor; // Unhide other setColor() functions
113 
117  void setMaterial( osg::Material *mat );
118  osg::Material* getMaterial() const
119  { return dynamic_cast<osg::Material*>(_sphereSD->getStateSet()->getAttribute(osg::StateAttribute::MATERIAL)); }
120 
122  virtual const osg::BoundingSphere& getBound() const;
123 
124  protected:
125  virtual ~Sphere();
126 
127  void repositionAxes();
128 
130  osg::ref_ptr<FrameTransform> _sphereXform;
131 
132  osg::ref_ptr<osg::Geode> _geode; // Node containing the sphere
133  osg::ref_ptr<osg::ShapeDrawable> _sphereSD; // The actual sphere
134 
135  private:
136  void _init();
137  };
138 
139 } // !namespace OpenFrames
140 
141 #endif
osg::ref_ptr< FrameTransform > _sphereXform
Definition: Sphere.hpp:130
Definition: CoordinateAxes.hpp:29
A ReferenceFrame with a sphere at the origin.
Definition: Sphere.hpp:41
Definition: ReferenceFrame.hpp:54
void setSphereAttitude(const osg::Quat &att)
Definition: Sphere.hpp:78