1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
15#define OSGSIM_SECTOR 1
17#include <osgSim/Export>
28class Sector : public osg::Object
34 Sector(const Sector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
35 osg::Object(copy,copyop) {}
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; }
41 virtual float operator() (const osg::Vec3& /*eyeLocal*/) const = 0;
48class OSGSIM_EXPORT AzimRange
56 _cosFadeAngle(-1.0f) {}
58 void setAzimuthRange(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f);
59 void getAzimuthRange(float& minAzimuth, float& maxAzimuth, float& fadeAngle) const;
62 inline float azimSector(const osg::Vec3& eyeLocal) const
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);
80class OSGSIM_EXPORT ElevationRange
86 _cosMinElevation(-1.0f),
87 _cosMinFadeElevation(-1.0f),
88 _cosMaxElevation(1.0),
89 _cosMaxFadeElevation(1.0) {}
91 void setElevationRange(float minElevation,float maxElevation,float fadeAngle=0.0f);
93 float getMinElevation() const;
95 float getMaxElevation() const;
97 float getFadeAngle() const;
99 inline float elevationSector(const osg::Vec3& eyeLocal) const
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)
107 // in uppoer fade band.
108 return (dotproduct-_cosMaxFadeElevation*length)/((_cosMaxElevation-_cosMaxFadeElevation)*length);
110 if (dotproduct<_cosMinElevation*length)
112 // in lower fade band.
113 return (dotproduct-_cosMinFadeElevation*length)/((_cosMinElevation-_cosMinFadeElevation)*length);
115 return 1.0f; // fully in sector
120 float _cosMinElevation;
121 float _cosMinFadeElevation;
122 float _cosMaxElevation;
123 float _cosMaxFadeElevation;
126class OSGSIM_EXPORT AzimSector : public Sector, public AzimRange
134 AzimSector(const AzimSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
138 AzimSector(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f);
140 META_Object(osgSim,AzimSector);
142 virtual float operator() (const osg::Vec3& eyeLocal) const;
146 virtual ~AzimSector() {}
150class OSGSIM_EXPORT ElevationSector : public Sector, public ElevationRange
159 ElevationSector(const ElevationSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
161 ElevationRange(copy) {}
163 ElevationSector(float minElevation,float maxElevation,float fadeAngle=0.0f);
165 META_Object(osgSim,ElevationSector);
167 virtual float operator() (const osg::Vec3& eyeLocal) const;
171 virtual ~ElevationSector() {}
175class OSGSIM_EXPORT AzimElevationSector : public Sector, public AzimRange, public ElevationRange
179 AzimElevationSector():
184 AzimElevationSector(const AzimElevationSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
187 ElevationRange(copy) {}
189 AzimElevationSector(float minAzimuth,float maxAzimuth,float minElevation,float maxElevation,float fadeAngle=0.0f);
191 META_Object(osgSim,AzimElevationSector);
193 virtual float operator() (const osg::Vec3& eyeLocal) const;
197 virtual ~AzimElevationSector() {}
201class OSGSIM_EXPORT ConeSector : public Sector
207 _axis(0.0f,0.0f,1.0f),
209 _cosAngleFade(-1.0f) {}
211 ConeSector(const ConeSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
214 _cosAngle(copy._cosAngle),
215 _cosAngleFade(copy._cosAngleFade) {}
217 ConeSector(const osg::Vec3& axis,float angle,float fadeangle=0.0f);
219 META_Object(osgSim,ConeSector);
221 void setAxis(const osg::Vec3& axis);
223 const osg::Vec3& getAxis() const;
225 void setAngle(float angle,float fadeangle=0.0f);
227 float getAngle() const;
229 float getFadeAngle() const;
231 virtual float operator() (const osg::Vec3& eyeLocal) const;
235 virtual ~ConeSector() {}
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 */
248class OSGSIM_EXPORT DirectionalSector : public Sector
254 _direction(0.0f, 0.0f, 1.0f),
256 _cosHorizAngle(-1.0f),
257 _cosVertAngle(-1.0f),
258 _cosHorizFadeAngle(-1.0f),
259 _cosVertFadeAngle(-1.0f) {computeMatrix();}
261 DirectionalSector(const DirectionalSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
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) {}
271 DirectionalSector(const osg::Vec3& direction,float horizLobeAngle, float vertLobeAngle, float lobeRollAngle, float fadeAngle=0.0f);
273 META_Object(osgSim,DirectionalSector);
275 void setDirection(const osg::Vec3& direction);
277 const osg::Vec3& getDirection() const;
279 void setHorizLobeAngle(float angle);
281 float getHorizLobeAngle() const;
283 void setLobeRollAngle(float angle);
285 float getLobeRollAngle() const;
287 void setVertLobeAngle(float angle);
289 float getVertLobeAngle() const;
291 void setFadeAngle(float angle);
293 float getFadeAngle() const;
295 virtual float operator() (const osg::Vec3& eyeLocal) const;
297 void computeMatrix() ;
301 virtual ~DirectionalSector() {}
303 osg::Vec3 _direction ;
305 osg::Matrix _local_to_LP ;
306 float _cosHorizAngle;
308 float _cosHorizFadeAngle;
309 float _cosVertFadeAngle;