OpenSceneGraph 3.6.5
SphereSegment
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#include <osg/Geometry>
25
26namespace osgSim{
27
61{
62public:
63
72 SURFACE = 0x00000001,
73 SPOKES = 0x00000002,
74 EDGELINE = 0x00000008,
75 SIDES = 0x00000010,
76 ALL = 0x7fffffff
77 };
78
79
82 _centre(0.0f,0.0f,0.0f), _radius(1.0f),
83 _azMin(0.0f), _azMax(osg::PI/2.0f),
84 _elevMin(0.0f), _elevMax(osg::PI/2.0f),
85 _density(10),
86 _drawMask(DrawMask(ALL))
87 {
88 init();
89 }
90
104 SphereSegment(const osg::Vec3& centre, float radius, float azMin, float azMax, float elevMin, float elevMax, int density);
105
116 SphereSegment(const osg::Vec3& centre, float radius, const osg::Vec3& vec, float azRange, float elevRange, int density);
117
120
122
124 void setCentre(const osg::Vec3& c);
125
127 const osg::Vec3& getCentre() const;
128
130 void setRadius(float r);
131
133 float getRadius() const;
134
142 void setArea(const osg::Vec3& vec, float azRange, float elevRange);
143
151 void getArea(osg::Vec3& vec, float& azRange, float& elevRange) const;
152
159 void setArea(float azMin, float azMax, float elevMin, float elevMax);
160
167 void getArea(float &azMin, float &azMax, float &elevMin, float &elevMax) const;
168
170 void setDensity(int d);
171
173 int getDensity() const;
174
180 void setDrawMask(int dm);
181
183 int getDrawMask() const { return _drawMask; }
184
187
189 const osg::Vec4& getSurfaceColor() const { return (*_surfaceColor)[0]; }
190
192 void setSpokeColor(const osg::Vec4& c);
193
195 const osg::Vec4& getSpokeColor() const { return (*_spokeColor)[0]; }
196
199
201 const osg::Vec4& getEdgeLineColor() const { return (*_edgeLineColor)[0]; }
202
204 void setSideColor(const osg::Vec4& c);
205
207 const osg::Vec4& getSideColor() const { return (*_sideColor)[0]; }
208
210 void setAllColors(const osg::Vec4& c);
211
213
215 typedef std::vector< osg::ref_ptr<osg::Vec3Array> > LineList;
216
221
226
231
236
239
242
243
244 virtual void resizeGLObjectBuffers(unsigned int maxSize);
245 virtual void releaseGLObjects(osg::State* state = 0) const;
246
248
249private:
250
251 void init(); // Shared constructor code, generates the drawables
252
253 void dirty(); // Force re-calling of gl functions and bounding boxes
254
255 // Sphere segment geometry details
256 osg::Vec3 _centre;
257 float _radius;
258 float _azMin, _azMax, _elevMin, _elevMax;
259 int _density;
260
261 // Draw details
262 int _drawMask;
263 osg::ref_ptr<osg::Vec4Array> _surfaceColor;
265 osg::ref_ptr<osg::Vec4Array> _edgeLineColor;
267
270
271 osg::ref_ptr<osg::Geometry> _surfaceGeometry;
272 osg::ref_ptr<osg::Geometry> _spokesGeometry;
273 osg::ref_ptr<osg::Geometry> _edgeLineGeometry;
274 osg::ref_ptr<osg::Geometry> _sidesGeometry;
275
276 osg::ref_ptr<osg::StateSet> _litOpaqueState;
277 osg::ref_ptr<osg::StateSet> _unlitOpaqueState;
278 osg::ref_ptr<osg::StateSet> _litTransparentState;
279 osg::ref_ptr<osg::StateSet> _unlitTransparentState;
280
281 osg::StateSet* getLitStateSet(const osg::Vec4& color) { return (color.a()<1.0) ? _litTransparentState.get() : _litOpaqueState.get(); }
282 osg::StateSet* getUnlitStateSet(const osg::Vec4& color) { return (color.a()<1.0) ? _unlitTransparentState.get() : _unlitOpaqueState.get(); }
283
284};
285
286}
287
288#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
Vec3f Vec3
Definition Vec3:21
BoundingSphered BoundingSphere
Definition BoundingSphere:308
Vec4f Vec4
Definition Vec4:21
The osgSim library is a NodeKit that extends the core scene graph to support nodes and drawables that...
Definition BlinkSequence:27
Copy Op(erator) used to control whether shallow or deep copy is used during copy construction and clo...
Definition CopyOp:41
Pure virtual base class for drawable geometry.
Definition Drawable:89
A Geode is a "geometry node", that is, a leaf node on the scene graph that can have "renderable thing...
Definition Geode:29
Definition Matrixd:27
Base class for all internal nodes in the scene graph.
Definition Node:72
Visitor for type safe operations on osg::Nodes.
Definition NodeVisitor:82
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
Encapsulates the current applied OpenGL modes, attributes and vertex arrays settings,...
Definition State:80
Stores a set of modes and attributes which represent a set of OpenGL state.
Definition StateSet:46
value_type & a()
Definition Vec4f:100
const osg::Vec4 & getSideColor() const
Get the color of the planes.
Definition SphereSegment:207
void getArea(float &azMin, float &azMax, float &elevMin, float &elevMax) const
Get the area of the sphere segment.
void getArea(osg::Vec3 &vec, float &azRange, float &elevRange) const
Get the area of the sphere segment.
META_Node(osgSim, SphereSegment)
void setCentre(const osg::Vec3 &c)
Set the centre point of the SphereSegment.
DrawMask
DrawMask represents a bit field, the values of which may be OR'ed together to specify which parts of ...
Definition SphereSegment:71
@ ALL
Draw every part of the sphere segment.
Definition SphereSegment:76
@ EDGELINE
Draw the line round the edge of the area on the sphere's surface.
Definition SphereSegment:74
@ SIDES
Draw the planes from the sphere's centre to the edge of the sphere's surface.
Definition SphereSegment:75
@ SPOKES
Draw the spokes from the sphere's centre to the surface's corners.
Definition SphereSegment:73
@ SURFACE
Draw the specified area on the sphere's surface.
Definition SphereSegment:72
void updatePositions()
recompute the vertex positions of the rendering meshes/lines that represent the sphere segment.
void setArea(const osg::Vec3 &vec, float azRange, float elevRange)
Set the area of the sphere segment.
void setDensity(int d)
Set the density of the sphere segment.
virtual void releaseGLObjects(osg::State *state=0) const
If State is non-zero, this function releases any associated OpenGL objects for the specified graphics...
void setSurfaceColor(const osg::Vec4 &c)
Set the color of the surface.
void setDrawMask(int dm)
Specify the DrawMask.
void setArea(float azMin, float azMax, float elevMin, float elevMax)
Set the area of the sphere segment.
int getDensity() const
Get the density of the sphere segment.
void setSpokeColor(const osg::Vec4 &c)
Set the color of the spokes.
void setAllColors(const osg::Vec4 &c)
Set color of all components.
osg::Node * computeIntersectionSubgraph(const osg::Matrixd &matrix, osg::Node *subgraph)
Compute the intersection lines between subgraph and this sphere segment.
SphereSegment()
Default constructor.
Definition SphereSegment:81
void setSideColor(const osg::Vec4 &c)
Set the color of the planes.
LineList computeIntersection(const osg::Matrixd &matrix, osg::Node *subgraph)
Compute the intersection lines between subgraph and this sphere segment.
const osg::Vec4 & getSurfaceColor() const
Get the color of the surface.
Definition SphereSegment:189
float getRadius() const
Get the radius of the SphereSegment.
SphereSegment(const SphereSegment &rhs, const osg::CopyOp &co)
Copy constructor.
virtual void resizeGLObjectBuffers(unsigned int maxSize)
Resize any per context GLObject buffers to specified size.
int getDrawMask() const
Get the DrawMask.
Definition SphereSegment:183
std::vector< osg::ref_ptr< osg::Vec3Array > > LineList
A list of vertex arrays representing a list of lines.
Definition SphereSegment:215
void updatePrimitives()
recompute the primitives rendering meshes/lines thtat represent the sphere segment.
const osg::Vec4 & getEdgeLineColor() const
Get the color of the edge line.
Definition SphereSegment:201
void setEdgeLineColor(const osg::Vec4 &c)
Set the color of the edge line.
osg::Node * computeIntersectionSubgraph(const osg::Matrixd &matrix, osg::Drawable *drawable)
Compute the intersection lines between specified drawable and this sphere segment.
SphereSegment(const osg::Vec3 &centre, float radius, const osg::Vec3 &vec, float azRange, float elevRange, int density)
Construct by vector.
const osg::Vec3 & getCentre() const
Get the centre point of the SphereSegment.
LineList computeIntersection(const osg::Matrixd &matrix, osg::Drawable *drawable)
Compute the intersection lines between specified drawable and this sphere segment.
void setRadius(float r)
Set the radius of the SphereSegment.
void traverse(osg::NodeVisitor &nv)
Traverse downwards : calls children's accept method with NodeVisitor.
SphereSegment(const osg::Vec3 &centre, float radius, float azMin, float azMax, float elevMin, float elevMax, int density)
Construct by angle ranges.
virtual osg::BoundingSphere computeBound() const
Compute the bounding sphere around Node's geometry or children.
const osg::Vec4 & getSpokeColor() const
Get the color of the spokes.
Definition SphereSegment:195
#define OSGSIM_EXPORT
Definition Export:38

osg logo
Generated at Wed Jul 23 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.