Sector
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSGSIM_SECTOR
#define OSGSIM_SECTOR 1
#include <osgSim/Export>
#include <osg/Quat>
#include <osg/Vec3>
#include <osg/Vec4>
#include <osg/Matrix>
#include <osg/Math>
#include <osg/Object>
namespace osgSim {
class Sector : public osg::Object
{
public:
Sector() {}
Sector(const Sector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
osg::Object(copy,copyop) {}
virtual const char *libraryName() const { return "osgSim"; }
virtual const char *className() const { return "Sector"; }
virtual bool isSameKindAs(const osg::Object *obj) const { return dynamic_cast<const Sector *>(obj) != 0; }
virtual float operator() (const osg::Vec3& /*eyeLocal*/) const = 0;
protected:
virtual ~Sector() {}
};
class OSGSIM_EXPORT AzimRange
{
public:
AzimRange():
_cosAzim(1.0f),
_sinAzim(0.0f),
_cosAngle(-1.0f),
_cosFadeAngle(-1.0f) {}
void setAzimuthRange(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f);
void getAzimuthRange(float& minAzimuth, float& maxAzimuth, float& fadeAngle) const;
inline float azimSector(const osg::Vec3& eyeLocal) const
{
float dotproduct = eyeLocal.x()*_sinAzim+eyeLocal.y()*_cosAzim;
float length = sqrt(osg::square(eyeLocal.x())+osg::square(eyeLocal.y()));
if (dotproduct<_cosFadeAngle*length) return 0.0f; // out of sector.
if (dotproduct>=_cosAngle*length) return 1.0f; // fully in sector.
return (dotproduct-_cosFadeAngle*length)/((_cosAngle-_cosFadeAngle)*length);
}
protected:
float _cosAzim;
float _sinAzim;
float _cosAngle;
float _cosFadeAngle;
};
class OSGSIM_EXPORT ElevationRange
{
public:
ElevationRange():
_cosMinElevation(-1.0f),
_cosMinFadeElevation(-1.0f),
_cosMaxElevation(1.0),
_cosMaxFadeElevation(1.0) {}
void setElevationRange(float minElevation,float maxElevation,float fadeAngle=0.0f);
float getMinElevation() const;
float getMaxElevation() const;
float getFadeAngle() const;
inline float elevationSector(const osg::Vec3& eyeLocal) const
{
float dotproduct = eyeLocal.z(); // against z axis - eyeLocal*(0,0,1).
float length = eyeLocal.length();
if (dotproduct>_cosMaxFadeElevation*length) return 0.0f; // out of sector
if (dotproduct<_cosMinFadeElevation*length) return 0.0f; // out of sector
if (dotproduct>_cosMaxElevation*length)
{
// in uppoer fade band.
return (dotproduct-_cosMaxFadeElevation*length)/((_cosMaxElevation-_cosMaxFadeElevation)*length);
}
if (dotproduct<_cosMinElevation*length)
{
// in lower fade band.
return (dotproduct-_cosMinFadeElevation*length)/((_cosMinElevation-_cosMinFadeElevation)*length);
}
return 1.0f; // fully in sector
}
protected:
float _cosMinElevation;
float _cosMinFadeElevation;
float _cosMaxElevation;
float _cosMaxFadeElevation;
};
class OSGSIM_EXPORT AzimSector : public Sector, public AzimRange
{
public:
AzimSector():
Sector(),
AzimRange() {}
AzimSector(const AzimSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
Sector(copy,copyop),
AzimRange(copy) {}
AzimSector(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f);
META_Object(osgSim,AzimSector);
virtual float operator() (const osg::Vec3& eyeLocal) const;
protected:
virtual ~AzimSector() {}
};
class OSGSIM_EXPORT ElevationSector : public Sector, public ElevationRange
{
public:
ElevationSector():
Sector(),
ElevationRange() {}
ElevationSector(const ElevationSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
Sector(copy,copyop),
ElevationRange(copy) {}
ElevationSector(float minElevation,float maxElevation,float fadeAngle=0.0f);
META_Object(osgSim,ElevationSector);
virtual float operator() (const osg::Vec3& eyeLocal) const;
protected:
virtual ~ElevationSector() {}
};
class OSGSIM_EXPORT AzimElevationSector : public Sector, public AzimRange, public ElevationRange
{
public:
AzimElevationSector():
Sector(),
AzimRange(),
ElevationRange() {}
AzimElevationSector(const AzimElevationSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
Sector(copy,copyop),
AzimRange(copy),
ElevationRange(copy) {}
AzimElevationSector(float minAzimuth,float maxAzimuth,float minElevation,float maxElevation,float fadeAngle=0.0f);
META_Object(osgSim,AzimElevationSector);
virtual float operator() (const osg::Vec3& eyeLocal) const;
protected:
virtual ~AzimElevationSector() {}
};
class OSGSIM_EXPORT ConeSector : public Sector
{
public:
ConeSector():
Sector(),
_axis(0.0f,0.0f,1.0f),
_cosAngle(-1.0f),
_cosAngleFade(-1.0f) {}
ConeSector(const ConeSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
Sector(copy,copyop),
_axis(copy._axis),
_cosAngle(copy._cosAngle),
_cosAngleFade(copy._cosAngleFade) {}
ConeSector(const osg::Vec3& axis,float angle,float fadeangle=0.0f);
META_Object(osgSim,ConeSector);
void setAxis(const osg::Vec3& axis);
const osg::Vec3& getAxis() const;
void setAngle(float angle,float fadeangle=0.0f);
float getAngle() const;
float getFadeAngle() const;
virtual float operator() (const osg::Vec3& eyeLocal) const;
protected:
virtual ~ConeSector() {}
osg::Vec3 _axis;
float _cosAngle;
float _cosAngleFade;
};
/* The DirectionalSector class was created to better handle OpenFlight directional
lightpoints. The Elevation and Azimuth Sectors above impose invalid limits on
the elevation range which cause lightpoints whose direction vectors are not
on the XY plane to be displayed incorrectly. Corbin Holtz 4/04 */
class OSGSIM_EXPORT DirectionalSector : public Sector
{
public:
DirectionalSector():
Sector(),
_direction(0.0f, 0.0f, 1.0f),
_rollAngle(0.0f),
_cosHorizAngle(-1.0f),
_cosVertAngle(-1.0f),
_cosHorizFadeAngle(-1.0f),
_cosVertFadeAngle(-1.0f) {computeMatrix();}
DirectionalSector(const DirectionalSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
Sector(copy,copyop),
_direction(copy._direction),
_rollAngle(copy._rollAngle),
_local_to_LP(copy._local_to_LP),
_cosHorizAngle(copy._cosHorizAngle),
_cosVertAngle(copy._cosVertAngle),
_cosHorizFadeAngle(copy._cosHorizFadeAngle),
_cosVertFadeAngle(copy._cosVertFadeAngle) {}
DirectionalSector(const osg::Vec3& direction,float horizLobeAngle, float vertLobeAngle, float lobeRollAngle, float fadeAngle=0.0f);
META_Object(osgSim,DirectionalSector);
void setDirection(const osg::Vec3& direction);
const osg::Vec3& getDirection() const;
void setHorizLobeAngle(float angle);
float getHorizLobeAngle() const;
void setLobeRollAngle(float angle);
float getLobeRollAngle() const;
void setVertLobeAngle(float angle);
float getVertLobeAngle() const;
void setFadeAngle(float angle);
float getFadeAngle() const;
virtual float operator() (const osg::Vec3& eyeLocal) const;
void computeMatrix() ;
protected:
virtual ~DirectionalSector() {}
osg::Vec3 _direction ;
float _rollAngle ;
osg::Matrix _local_to_LP ;
float _cosHorizAngle;
float _cosVertAngle;
float _cosHorizFadeAngle;
float _cosVertFadeAngle;
};
}
#endif
Math
Matrix
Object
Quat
Vec3
Vec4
osgSim::AzimElevationSector::~AzimElevationSector
virtual ~AzimElevationSector()
Definition Sector:197
osgSim::AzimElevationSector::AzimElevationSector
AzimElevationSector(const AzimElevationSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition Sector:184
osgSim::AzimElevationSector::META_Object
META_Object(osgSim, AzimElevationSector)
osgSim::AzimElevationSector::AzimElevationSector
AzimElevationSector(float minAzimuth, float maxAzimuth, float minElevation, float maxElevation, float fadeAngle=0.0f)
osgSim::AzimElevationSector::AzimElevationSector
AzimElevationSector()
Definition Sector:179
osgSim::AzimRange::AzimRange
AzimRange()
Definition Sector:52
osgSim::AzimRange::_cosAzim
float _cosAzim
Definition Sector:73
osgSim::AzimRange::_cosFadeAngle
float _cosFadeAngle
Definition Sector:76
osgSim::AzimRange::azimSector
float azimSector(const osg::Vec3 &eyeLocal) const
Definition Sector:62
osgSim::AzimRange::getAzimuthRange
void getAzimuthRange(float &minAzimuth, float &maxAzimuth, float &fadeAngle) const
osgSim::AzimRange::setAzimuthRange
void setAzimuthRange(float minAzimuth, float maxAzimuth, float fadeAngle=0.0f)
osgSim::AzimRange::_sinAzim
float _sinAzim
Definition Sector:74
osgSim::AzimRange::_cosAngle
float _cosAngle
Definition Sector:75
osgSim::AzimSector::~AzimSector
virtual ~AzimSector()
Definition Sector:146
osgSim::AzimSector::AzimSector
AzimSector(const AzimSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition Sector:134
osgSim::AzimSector::META_Object
META_Object(osgSim, AzimSector)
osgSim::AzimSector::AzimSector
AzimSector(float minAzimuth, float maxAzimuth, float fadeAngle=0.0f)
osgSim::AzimSector::AzimSector
AzimSector()
Definition Sector:130
osgSim::ConeSector::ConeSector
ConeSector(const osg::Vec3 &axis, float angle, float fadeangle=0.0f)
osgSim::ConeSector::META_Object
META_Object(osgSim, ConeSector)
osgSim::ConeSector::setAngle
void setAngle(float angle, float fadeangle=0.0f)
osgSim::ConeSector::~ConeSector
virtual ~ConeSector()
Definition Sector:235
osgSim::ConeSector::ConeSector
ConeSector(const ConeSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition Sector:211
osgSim::ConeSector::_axis
osg::Vec3 _axis
Definition Sector:237
osgSim::ConeSector::_cosAngle
float _cosAngle
Definition Sector:238
osgSim::ConeSector::getAngle
float getAngle() const
osgSim::ConeSector::setAxis
void setAxis(const osg::Vec3 &axis)
osgSim::ConeSector::getFadeAngle
float getFadeAngle() const
osgSim::ConeSector::_cosAngleFade
float _cosAngleFade
Definition Sector:239
osgSim::ConeSector::ConeSector
ConeSector()
Definition Sector:205
osgSim::ConeSector::getAxis
const osg::Vec3 & getAxis() const
osgSim::DirectionalSector::getFadeAngle
float getFadeAngle() const
osgSim::DirectionalSector::getVertLobeAngle
float getVertLobeAngle() const
osgSim::DirectionalSector::_cosVertAngle
float _cosVertAngle
Definition Sector:307
osgSim::DirectionalSector::DirectionalSector
DirectionalSector(const osg::Vec3 &direction, float horizLobeAngle, float vertLobeAngle, float lobeRollAngle, float fadeAngle=0.0f)
osgSim::DirectionalSector::computeMatrix
void computeMatrix()
osgSim::DirectionalSector::setFadeAngle
void setFadeAngle(float angle)
osgSim::DirectionalSector::getDirection
const osg::Vec3 & getDirection() const
osgSim::DirectionalSector::setDirection
void setDirection(const osg::Vec3 &direction)
osgSim::DirectionalSector::DirectionalSector
DirectionalSector(const DirectionalSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition Sector:261
osgSim::DirectionalSector::getHorizLobeAngle
float getHorizLobeAngle() const
osgSim::DirectionalSector::DirectionalSector
DirectionalSector()
Definition Sector:252
osgSim::DirectionalSector::~DirectionalSector
virtual ~DirectionalSector()
Definition Sector:301
osgSim::DirectionalSector::_rollAngle
float _rollAngle
Definition Sector:304
osgSim::DirectionalSector::setVertLobeAngle
void setVertLobeAngle(float angle)
osgSim::DirectionalSector::_direction
osg::Vec3 _direction
Definition Sector:303
osgSim::DirectionalSector::_cosHorizFadeAngle
float _cosHorizFadeAngle
Definition Sector:308
osgSim::DirectionalSector::_local_to_LP
osg::Matrix _local_to_LP
Definition Sector:305
osgSim::DirectionalSector::_cosHorizAngle
float _cosHorizAngle
Definition Sector:306
osgSim::DirectionalSector::setLobeRollAngle
void setLobeRollAngle(float angle)
osgSim::DirectionalSector::META_Object
META_Object(osgSim, DirectionalSector)
osgSim::DirectionalSector::getLobeRollAngle
float getLobeRollAngle() const
osgSim::DirectionalSector::_cosVertFadeAngle
float _cosVertFadeAngle
Definition Sector:309
osgSim::DirectionalSector::setHorizLobeAngle
void setHorizLobeAngle(float angle)
osgSim::ElevationRange::ElevationRange
ElevationRange()
Definition Sector:85
osgSim::ElevationRange::getMaxElevation
float getMaxElevation() const
osgSim::ElevationRange::getMinElevation
float getMinElevation() const
osgSim::ElevationRange::getFadeAngle
float getFadeAngle() const
osgSim::ElevationRange::_cosMaxFadeElevation
float _cosMaxFadeElevation
Definition Sector:123
osgSim::ElevationRange::_cosMaxElevation
float _cosMaxElevation
Definition Sector:122
osgSim::ElevationRange::_cosMinFadeElevation
float _cosMinFadeElevation
Definition Sector:121
osgSim::ElevationRange::_cosMinElevation
float _cosMinElevation
Definition Sector:120
osgSim::ElevationRange::setElevationRange
void setElevationRange(float minElevation, float maxElevation, float fadeAngle=0.0f)
osgSim::ElevationRange::elevationSector
float elevationSector(const osg::Vec3 &eyeLocal) const
Definition Sector:99
osgSim::ElevationSector::ElevationSector
ElevationSector(float minElevation, float maxElevation, float fadeAngle=0.0f)
osgSim::ElevationSector::ElevationSector
ElevationSector()
Definition Sector:155
osgSim::ElevationSector::ElevationSector
ElevationSector(const ElevationSector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition Sector:159
osgSim::ElevationSector::~ElevationSector
virtual ~ElevationSector()
Definition Sector:171
osgSim::ElevationSector::META_Object
META_Object(osgSim, ElevationSector)
osgSim::Sector::className
virtual const char * className() const
Definition Sector:38
osgSim::Sector::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition Sector:39
osgSim::Sector::Sector
Sector()
Definition Sector:32
osgSim::Sector::libraryName
virtual const char * libraryName() const
Definition Sector:37
osgSim::Sector::~Sector
virtual ~Sector()
Definition Sector:45
osgSim::Sector::Sector
Sector(const Sector &copy, const osg::CopyOp &copyop=osg::CopyOp::SHALLOW_COPY)
Definition Sector:34
osgSim::Sector::operator()
virtual float operator()(const osg::Vec3 &) const =0
osg::CopyOp
Definition CopyOp:41
osg::CopyOp::SHALLOW_COPY
@ SHALLOW_COPY
Definition CopyOp:47
osg::Object
Definition Object:61
osg::Object::Object
Object()
Definition Object:69
osg::Vec3f::z
value_type & z()
Definition Vec3f:82
osg::Vec3f::y
value_type & y()
Definition Vec3f:81
osg::Vec3f::x
value_type & x()
Definition Vec3f:80
osg::Vec3f::length
value_type length() const
Definition Vec3f:176
osgSim
Definition BlinkSequence:27
osg
Definition AlphaFunc:19
osg::Vec3
Vec3f Vec3
Definition Vec3:21
osg::square
T square(T v)
Definition Math:107
osg::Matrix
Matrixd Matrix
Definition Matrix:27
Export
OSGSIM_EXPORT
#define OSGSIM_EXPORT
Definition osgSim/Export:38