2006-07-18 23:21:48 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-01-22 00:45:36 +08:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2002-11-19 18:57:40 +08:00
|
|
|
|
|
|
|
#ifndef OSGSIM_SECTOR
|
|
|
|
#define OSGSIM_SECTOR 1
|
|
|
|
|
|
|
|
#include <osgSim/Export>
|
|
|
|
|
|
|
|
#include <osg/Quat>
|
|
|
|
#include <osg/Vec3>
|
|
|
|
#include <osg/Vec4>
|
2004-05-09 06:18:38 +08:00
|
|
|
#include <osg/Matrix>
|
2002-11-19 18:57:40 +08:00
|
|
|
#include <osg/Math>
|
2003-09-06 04:48:42 +08:00
|
|
|
#include <osg/Object>
|
2002-11-19 18:57:40 +08:00
|
|
|
|
|
|
|
namespace osgSim {
|
|
|
|
|
2003-07-22 18:33:56 +08:00
|
|
|
class Sector : public osg::Object
|
2002-11-19 18:57:40 +08:00
|
|
|
{
|
|
|
|
public:
|
2003-07-22 18:33:56 +08:00
|
|
|
|
|
|
|
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; }
|
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
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) {}
|
2003-07-22 18:33:56 +08:00
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
void setAzimuthRange(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f);
|
2003-07-23 22:06:32 +08:00
|
|
|
void getAzimuthRange(float& minAzimuth, float& maxAzimuth, float& fadeAngle) const;
|
2002-11-19 18:57:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
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.
|
2004-05-09 06:18:38 +08:00
|
|
|
if (dotproduct>=_cosAngle*length) return 1.0f; // fully in sector.
|
2002-11-19 18:57:40 +08:00
|
|
|
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;
|
|
|
|
|
2003-07-23 22:06:32 +08:00
|
|
|
float getFadeAngle() const;
|
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
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() {}
|
|
|
|
|
2003-07-22 18:33:56 +08:00
|
|
|
AzimSector(const AzimSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
|
|
|
|
Sector(copy,copyop),
|
|
|
|
AzimRange(copy) {}
|
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
AzimSector(float minAzimuth,float maxAzimuth,float fadeAngle=0.0f);
|
|
|
|
|
2004-09-28 17:14:04 +08:00
|
|
|
META_Object(osgSim,AzimSector);
|
2003-07-22 18:33:56 +08:00
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
virtual float operator() (const osg::Vec3& eyeLocal) const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
virtual ~AzimSector() {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class OSGSIM_EXPORT ElevationSector : public Sector, public ElevationRange
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
|
|
ElevationSector():
|
|
|
|
Sector(),
|
|
|
|
ElevationRange() {}
|
|
|
|
|
2003-07-22 18:33:56 +08:00
|
|
|
ElevationSector(const ElevationSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
|
|
|
|
Sector(copy,copyop),
|
|
|
|
ElevationRange(copy) {}
|
2002-11-19 18:57:40 +08:00
|
|
|
|
|
|
|
ElevationSector(float minElevation,float maxElevation,float fadeAngle=0.0f);
|
|
|
|
|
2004-09-28 17:14:04 +08:00
|
|
|
META_Object(osgSim,ElevationSector);
|
2003-07-22 18:33:56 +08:00
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
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() {}
|
|
|
|
|
2003-07-22 18:33:56 +08:00
|
|
|
AzimElevationSector(const AzimElevationSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
|
|
|
|
Sector(copy,copyop),
|
|
|
|
AzimRange(copy),
|
|
|
|
ElevationRange(copy) {}
|
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
AzimElevationSector(float minAzimuth,float maxAzimuth,float minElevation,float maxElevation,float fadeAngle=0.0f);
|
|
|
|
|
2004-09-28 17:14:04 +08:00
|
|
|
META_Object(osgSim,AzimElevationSector);
|
2003-07-22 18:33:56 +08:00
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
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) {}
|
|
|
|
|
2003-07-22 18:33:56 +08:00
|
|
|
ConeSector(const ConeSector& copy, const osg::CopyOp& copyop = osg::CopyOp::SHALLOW_COPY):
|
|
|
|
Sector(copy,copyop),
|
|
|
|
_axis(copy._axis),
|
|
|
|
_cosAngle(copy._cosAngle),
|
|
|
|
_cosAngleFade(copy._cosAngleFade) {}
|
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
ConeSector(const osg::Vec3& axis,float angle,float fadeangle=0.0f);
|
|
|
|
|
2004-09-28 17:14:04 +08:00
|
|
|
META_Object(osgSim,ConeSector);
|
2003-07-22 18:33:56 +08:00
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2004-05-09 06:18:38 +08:00
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
2004-09-28 17:14:04 +08:00
|
|
|
META_Object(osgSim,DirectionalSector);
|
2004-05-09 06:18:38 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2002-11-19 18:57:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|