OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SphereSegment.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSGSIM_SPHERESEGMENT
15 #define OSGSIM_SPHERESEGMENT 1
16 
17 #include <osgSim/Export>
18 
19 #include <osg/Vec3>
20 #include <osg/Vec4>
21 #include <osg/Geode>
22 #include <osg/Matrixd>
23 #include <osg/BlendFunc>
24 
25 namespace osgSim{
26 
60 {
61 public:
62 
70  enum DrawMask{
71  SURFACE = 0x00000001,
72  SPOKES = 0x00000002,
73  EDGELINE = 0x00000008,
74  SIDES = 0x00000010,
75  ALL = 0x7fffffff
76  };
77 
78 
80  SphereSegment():osg::Geode(),
81  _centre(0.0f,0.0f,0.0f), _radius(1.0f),
82  _azMin(0.0f), _azMax(osg::PI/2.0f),
83  _elevMin(0.0f), _elevMax(osg::PI/2.0f),
84  _density(10),
85  _drawMask(DrawMask(ALL))
86  {
87  init();
88  }
89 
103  SphereSegment(const osg::Vec3& centre, float radius, float azMin, float azMax,
104  float elevMin, float elevMax, int density):
105  osg::Geode(),
106  _centre(centre), _radius(radius),
107  _azMin(azMin), _azMax(azMax),
108  _elevMin(elevMin), _elevMax(elevMax),
109  _density(density),
110  _drawMask(DrawMask(ALL))
111  {
112  init();
113  }
114 
125  SphereSegment(const osg::Vec3& centre, float radius, const osg::Vec3& vec, float azRange,
126  float elevRange, int density);
127 
129  SphereSegment(const SphereSegment& rhs, const osg::CopyOp& co):
130  osg::Geode(rhs,co),
131  _centre(rhs._centre), _radius(rhs._radius),
132  _azMin(rhs._azMin), _azMax(rhs._azMax),
133  _elevMin(rhs._elevMin), _elevMax(rhs._elevMax),
134  _density(rhs._density),
135  _drawMask(rhs._drawMask)
136  {
137  init();
138  }
139 
141  void setCentre(const osg::Vec3& c);
142 
144  const osg::Vec3& getCentre() const;
145 
147  void setRadius(float r);
148 
150  float getRadius() const;
151 
159  void setArea(const osg::Vec3& vec, float azRange, float elevRange);
160 
168  void getArea(osg::Vec3& vec, float& azRange, float& elevRange) const;
169 
176  void setArea(float azMin, float azMax, float elevMin, float elevMax);
177 
184  void getArea(float &azMin, float &azMax, float &elevMin, float &elevMax) const;
185 
187  void setDensity(int d);
188 
190  int getDensity() const;
191 
197  void setDrawMask(int dm);
198 
200  int getDrawMask() const { return _drawMask; }
201 
203  void setSurfaceColor(const osg::Vec4& c);
204 
206  const osg::Vec4& getSurfaceColor() const { return _surfaceColor; }
207 
209  void setSpokeColor(const osg::Vec4& c);
210 
212  const osg::Vec4& getSpokeColor() const { return _spokeColor; }
213 
215  void setEdgeLineColor(const osg::Vec4& c);
216 
218  const osg::Vec4& getEdgeLineColor() const { return _edgeLineColor; }
219 
221  void setSideColor(const osg::Vec4& c);
222 
224  const osg::Vec4& getSideColor() const { return _planeColor; }
225 
227  void setAllColors(const osg::Vec4& c);
228 
230 
232  typedef std::vector< osg::ref_ptr<osg::Vec3Array> > LineList;
233 
237  LineList computeIntersection(const osg::Matrixd& matrix, osg::Node* subgraph);
238 
242  LineList computeIntersection(const osg::Matrixd& matrix, osg::Drawable* drawable);
243 
247  osg::Node* computeIntersectionSubgraph(const osg::Matrixd& matrix, osg::Node* subgraph);
248 
252  osg::Node* computeIntersectionSubgraph(const osg::Matrixd& matrix, osg::Drawable* drawable);
253 
254 
255 private:
256 
257  void init(); // Shared constructor code, generates the drawables
258 
259  void dirtyAllDrawableDisplayLists(); // Force re-calling of gl functions
260  void dirtyAllDrawableBounds(); // Force recalculation of bound geometry
261 
262  // SphereSegment is actually made up of a number of Drawable classes,
263  // all of which are nested private classes, as declared below. These
264  // classes are defined in the .cpp for minimum visibility and physical
265  // coupling. (Reduces time spent compiling! :-)
266  //
267  // Each of the nested classes holds a pointer to the SphereSegment
268  // 'parent', which stores the geometry details, and performs any
269  // work required. The nested classes are lightweight objects which
270  // just pass the work on.
271  //
272  // Why are things done with these sub-Drawables? Alpha-blended
273  // Drawables need to be drawn last, depth sorted, and the various
274  // components of a SphereSegment also need to be depth sorted
275  // against one another (they may all be drawn with alpha blending).
276  // Making these Drawables allows us to get the OSG to depth sort
277  // for us.
278 
279  class Surface;
280  friend class Surface;
281  bool Surface_computeBound(osg::BoundingBox&) const;
282  void Surface_drawImplementation(osg::State&) const;
283 
284  class EdgeLine;
285  friend class EdgeLine;
286  bool EdgeLine_computeBound(osg::BoundingBox&) const;
287  void EdgeLine_drawImplementation(osg::State&) const;
288 
289  enum BoundaryAngle{MIN,MAX}; // Why here and not in Side class? Because we can't forward
290  enum SideOrientation{AZIM,ELEV}; // declare enums, Side is in the .cpp, and this is tidier...
291  class Side;
292  friend class Side;
293  bool Side_computeBound(osg::BoundingBox&, SideOrientation, BoundaryAngle) const;
294  void Side_drawImplementation(osg::State&, SideOrientation, BoundaryAngle) const;
295 
296  class Spoke;
297  friend class Spoke;
298  bool Spoke_computeBound(osg::BoundingBox&, BoundaryAngle, BoundaryAngle) const;
299  void Spoke_drawImplementation(osg::State&, BoundaryAngle, BoundaryAngle) const;
300 
301  // Sphere segment geometry details
302  osg::Vec3 _centre;
303  float _radius;
304  float _azMin, _azMax, _elevMin, _elevMax;
305  int _density;
306 
307  // Draw details
308  int _drawMask;
309  osg::Vec4 _surfaceColor;
310  osg::Vec4 _spokeColor;
311  osg::Vec4 _edgeLineColor;
312  osg::Vec4 _planeColor;
313 };
314 
315 }
316 
317 #endif
#define OSGSIM_EXPORT
Definition: Export.h:38
SphereSegment(const osg::Vec3 &centre, float radius, float azMin, float azMax, float elevMin, float elevMax, int density)
const osg::Vec4 & getSpokeColor() const
#define META_Node(library, name)
Definition: Node.h:59
const osg::Vec4 & getSideColor() const
std::vector< osg::ref_ptr< osg::Vec3Array > > LineList
const osg::Vec4 & getEdgeLineColor() const
SphereSegment(const SphereSegment &rhs, const osg::CopyOp &co)
const osg::Vec4 & getSurfaceColor() const
const double PI
Definition: Math.h:30
Definition: Node.h:71
Definition: AlphaFunc.h:19
int getDrawMask() const