OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Sector.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_SECTOR
15 #define OSGSIM_SECTOR 1
16 
17 #include <osgSim/Export>
18 
19 #include <osg/Quat>
20 #include <osg/Vec3>
21 #include <osg/Vec4>
22 #include <osg/Matrix>
23 #include <osg/Math>
24 #include <osg/Object>
25 
26 namespace osgSim {
27 
28 class Sector : public osg::Object
29 {
30  public:
31 
32  Sector() {}
33 
34  Sector(const Sector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
35  osg::Object(copy,copyop) {}
36 
37  virtual const char *libraryName() const { return "osgSim"; }
38  virtual const char *className() const { return "Sector"; }
39  virtual bool isSameKindAs(const osg::Object *obj) const { return dynamic_cast<const Sector *>(obj) != 0; }
40 
41  virtual float operator() (const osg::Vec3& /*eyeLocal*/) const = 0;
42 
43  protected:
44 
45  virtual ~Sector() {}
46 };
47 
49 {
50  public:
51 
53  _cosAzim(1.0f),
54  _sinAzim(0.0f),
55  _cosAngle(-1.0f),
56  _cosFadeAngle(-1.0f) {}
57 
58  void setAzimuthRange(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f);
59  void getAzimuthRange(float& minAzimuth, float& maxAzimuth, float& fadeAngle) const;
60 
61 
62  inline float azimSector(const osg::Vec3& eyeLocal) const
63  {
64  float dotproduct = eyeLocal.x()*_sinAzim+eyeLocal.y()*_cosAzim;
65  float length = sqrt(osg::square(eyeLocal.x())+osg::square(eyeLocal.y()));
66  if (dotproduct<_cosFadeAngle*length) return 0.0f; // out of sector.
67  if (dotproduct>=_cosAngle*length) return 1.0f; // fully in sector.
68  return (dotproduct-_cosFadeAngle*length)/((_cosAngle-_cosFadeAngle)*length);
69  }
70 
71  protected:
72 
73  float _cosAzim;
74  float _sinAzim;
75  float _cosAngle;
77 };
78 
79 
81 {
82  public:
83 
84 
86  _cosMinElevation(-1.0f),
87  _cosMinFadeElevation(-1.0f),
88  _cosMaxElevation(1.0),
89  _cosMaxFadeElevation(1.0) {}
90 
91  void setElevationRange(float minElevation,float maxElevation,float fadeAngle=0.0f);
92 
93  float getMinElevation() const;
94 
95  float getMaxElevation() const;
96 
97  float getFadeAngle() const;
98 
99  inline float elevationSector(const osg::Vec3& eyeLocal) const
100  {
101  float dotproduct = eyeLocal.z(); // against z axis - eyeLocal*(0,0,1).
102  float length = eyeLocal.length();
103  if (dotproduct>_cosMaxFadeElevation*length) return 0.0f; // out of sector
104  if (dotproduct<_cosMinFadeElevation*length) return 0.0f; // out of sector
105  if (dotproduct>_cosMaxElevation*length)
106  {
107  // in uppoer fade band.
108  return (dotproduct-_cosMaxFadeElevation*length)/((_cosMaxElevation-_cosMaxFadeElevation)*length);
109  }
110  if (dotproduct<_cosMinElevation*length)
111  {
112  // in lower fade band.
113  return (dotproduct-_cosMinFadeElevation*length)/((_cosMinElevation-_cosMinFadeElevation)*length);
114  }
115  return 1.0f; // fully in sector
116  }
117 
118  protected:
119 
124 };
125 
126 class OSGSIM_EXPORT AzimSector : public Sector, public AzimRange
127 {
128  public:
129 
131  Sector(),
132  AzimRange() {}
133 
135  Sector(copy,copyop),
136  AzimRange(copy) {}
137 
138  AzimSector(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f);
139 
141 
142  virtual float operator() (const osg::Vec3& eyeLocal) const;
143 
144  protected:
145 
146  virtual ~AzimSector() {}
147 
148 };
149 
151 {
152  public:
153 
154 
156  Sector(),
157  ElevationRange() {}
158 
160  Sector(copy,copyop),
161  ElevationRange(copy) {}
162 
163  ElevationSector(float minElevation,float maxElevation,float fadeAngle=0.0f);
164 
166 
167  virtual float operator() (const osg::Vec3& eyeLocal) const;
168 
169  protected:
170 
171  virtual ~ElevationSector() {}
172 };
173 
174 
176 {
177  public:
178 
180  Sector(),
181  AzimRange(),
182  ElevationRange() {}
183 
185  Sector(copy,copyop),
186  AzimRange(copy),
187  ElevationRange(copy) {}
188 
189  AzimElevationSector(float minAzimuth,float maxAzimuth,float minElevation,float maxElevation,float fadeAngle=0.0f);
190 
192 
193  virtual float operator() (const osg::Vec3& eyeLocal) const;
194 
195  protected:
196 
197  virtual ~AzimElevationSector() {}
198 };
199 
200 
202 {
203  public:
204 
206  Sector(),
207  _axis(0.0f,0.0f,1.0f),
208  _cosAngle(-1.0f),
209  _cosAngleFade(-1.0f) {}
210 
212  Sector(copy,copyop),
213  _axis(copy._axis),
214  _cosAngle(copy._cosAngle),
215  _cosAngleFade(copy._cosAngleFade) {}
216 
217  ConeSector(const osg::Vec3& axis,float angle,float fadeangle=0.0f);
218 
220 
221  void setAxis(const osg::Vec3& axis);
222 
223  const osg::Vec3& getAxis() const;
224 
225  void setAngle(float angle,float fadeangle=0.0f);
226 
227  float getAngle() const;
228 
229  float getFadeAngle() const;
230 
231  virtual float operator() (const osg::Vec3& eyeLocal) const;
232 
233  protected:
234 
235  virtual ~ConeSector() {}
236 
238  float _cosAngle;
240 };
241 
242 
243 /* The DirectionalSector class was created to better handle OpenFlight directional
244  lightpoints. The Elevation and Azimuth Sectors above impose invalid limits on
245  the elevation range which cause lightpoints whose direction vectors are not
246  on the XY plane to be displayed incorrectly. Corbin Holtz 4/04 */
247 
249 {
250  public:
251 
253  Sector(),
254  _direction(0.0f, 0.0f, 1.0f),
255  _rollAngle(0.0f),
256  _cosHorizAngle(-1.0f),
257  _cosVertAngle(-1.0f),
258  _cosHorizFadeAngle(-1.0f),
259  _cosVertFadeAngle(-1.0f) {computeMatrix();}
260 
262  Sector(copy,copyop),
263  _direction(copy._direction),
264  _rollAngle(copy._rollAngle),
265  _local_to_LP(copy._local_to_LP),
266  _cosHorizAngle(copy._cosHorizAngle),
267  _cosVertAngle(copy._cosVertAngle),
268  _cosHorizFadeAngle(copy._cosHorizFadeAngle),
269  _cosVertFadeAngle(copy._cosVertFadeAngle) {}
270 
271  DirectionalSector(const osg::Vec3& direction,float horizLobeAngle, float vertLobeAngle, float lobeRollAngle, float fadeAngle=0.0f);
272 
274 
275  void setDirection(const osg::Vec3& direction);
276 
277  const osg::Vec3& getDirection() const;
278 
279  void setHorizLobeAngle(float angle);
280 
281  float getHorizLobeAngle() const;
282 
283  void setLobeRollAngle(float angle);
284 
285  float getLobeRollAngle() const;
286 
287  void setVertLobeAngle(float angle);
288 
289  float getVertLobeAngle() const;
290 
291  void setFadeAngle(float angle);
292 
293  float getFadeAngle() const;
294 
295  virtual float operator() (const osg::Vec3& eyeLocal) const;
296 
297  void computeMatrix() ;
298 
299  protected:
300 
301  virtual ~DirectionalSector() {}
302 
304  float _rollAngle ;
310 };
311 
312 }
313 
314 #endif
#define OSGSIM_EXPORT
Definition: Export.h:38
osg::Vec3 _axis
Definition: Sector.h:237
virtual ~Sector()
Definition: Sector.h:45
virtual ~ConeSector()
Definition: Sector.h:235
Sector(const Sector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Sector.h:34
float _cosFadeAngle
Definition: Sector.h:76
ElevationSector(const ElevationSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Sector.h:159
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: Sector.h:39
value_type & x()
Definition: Vec3f.h:80
virtual float operator()(const osg::Vec3 &) const =0
value_type & z()
Definition: Vec3f.h:82
DirectionalSector(const DirectionalSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Sector.h:261
virtual ~AzimElevationSector()
Definition: Sector.h:197
virtual ~AzimSector()
Definition: Sector.h:146
float azimSector(const osg::Vec3 &eyeLocal) const
Definition: Sector.h:62
float _cosAngle
Definition: Sector.h:75
#define META_Object(library, name)
Definition: Object.h:42
AzimElevationSector(const AzimElevationSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Sector.h:184
Object()
Definition: Object.h:65
AzimSector(const AzimSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Sector.h:134
float _cosAngleFade
Definition: Sector.h:239
float _cosMinFadeElevation
Definition: Sector.h:121
ConeSector(const ConeSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition: Sector.h:211
virtual ~DirectionalSector()
Definition: Sector.h:301
value_type & y()
Definition: Vec3f.h:81
float _cosAzim
Definition: Sector.h:73
float _cosMaxFadeElevation
Definition: Sector.h:123
virtual ~ElevationSector()
Definition: Sector.h:171
osg::Matrix _local_to_LP
Definition: Sector.h:305
T square(T v)
Definition: Math.h:88
Definition: AlphaFunc.h:19
float elevationSector(const osg::Vec3 &eyeLocal) const
Definition: Sector.h:99
virtual const char * className() const
Definition: Sector.h:38
value_type length() const
Definition: Vec3f.h:176
virtual const char * libraryName() const
Definition: Sector.h:37
float _sinAzim
Definition: Sector.h:74