openscenegraph
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
81 SphereSegment():osg::Geode(),
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
Definition SphereSegment:61
const osg::Vec4 & getSideColor() const
Definition SphereSegment:207
void getArea(float &azMin, float &azMax, float &elevMin, float &elevMax) const
void getArea(osg::Vec3 &vec, float &azRange, float &elevRange) const
META_Node(osgSim, SphereSegment)
void setCentre(const osg::Vec3 &c)
DrawMask
Definition SphereSegment:71
void setArea(const osg::Vec3 &vec, float azRange, float elevRange)
void setDensity(int d)
virtual void releaseGLObjects(osg::State *state=0) const
void setSurfaceColor(const osg::Vec4 &c)
void setDrawMask(int dm)
void setArea(float azMin, float azMax, float elevMin, float elevMax)
int getDensity() const
void setSpokeColor(const osg::Vec4 &c)
void setAllColors(const osg::Vec4 &c)
osg::Node * computeIntersectionSubgraph(const osg::Matrixd &matrix, osg::Node *subgraph)
SphereSegment()
Definition SphereSegment:81
void setSideColor(const osg::Vec4 &c)
LineList computeIntersection(const osg::Matrixd &matrix, osg::Node *subgraph)
const osg::Vec4 & getSurfaceColor() const
Definition SphereSegment:189
float getRadius() const
SphereSegment(const SphereSegment &rhs, const osg::CopyOp &co)
virtual void resizeGLObjectBuffers(unsigned int maxSize)
int getDrawMask() const
Definition SphereSegment:183
std::vector< osg::ref_ptr< osg::Vec3Array > > LineList
Definition SphereSegment:215
const osg::Vec4 & getEdgeLineColor() const
Definition SphereSegment:201
void setEdgeLineColor(const osg::Vec4 &c)
osg::Node * computeIntersectionSubgraph(const osg::Matrixd &matrix, osg::Drawable *drawable)
SphereSegment(const osg::Vec3 &centre, float radius, const osg::Vec3 &vec, float azRange, float elevRange, int density)
const osg::Vec3 & getCentre() const
LineList computeIntersection(const osg::Matrixd &matrix, osg::Drawable *drawable)
void setRadius(float r)
void traverse(osg::NodeVisitor &nv)
SphereSegment(const osg::Vec3 &centre, float radius, float azMin, float azMax, float elevMin, float elevMax, int density)
virtual osg::BoundingSphere computeBound() const
const osg::Vec4 & getSpokeColor() const
Definition SphereSegment:195
Definition BoundingSphere:35
Definition CopyOp:41
Definition Drawable:89
Definition Geode:29
Definition Matrixd:27
Definition NodeVisitor:82
Definition Node:72
Definition StateSet:46
Definition State:80
Definition Vec3f:29
Definition Vec4f:28
value_type & a()
Definition Vec4f:100
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
Definition BlinkSequence:27
author: Julien Valentin 2017 (mp3butcher@hotmail.com)
Definition AlphaFunc:19
#define OSGSIM_EXPORT
Definition osgSim/Export:38