Added support for min pixel size, max pixel size and max visable distance to
osgSim::LightPointNode, the max pixel size from was originally in osg::LightPoint. Added additional get/set methods to osg::LightPointNode. Increased the compute pixel size by a ratio 1.41 (sqrtf(2)) to correlate the computed size with the actual size seen on screen.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include <osg/Billboard>
|
||||
#include <osg/Geode>
|
||||
#include <osg/Group>
|
||||
#include <osg/ShapeDrawable>
|
||||
#include <osg/Notify>
|
||||
|
||||
#include <osgDB/Registry>
|
||||
@@ -32,7 +33,7 @@ void addToLightPointNode(osgSim::LightPointNode& lpn,osgSim::LightPoint& start,o
|
||||
float rend = 0.0f;
|
||||
float rdelta = 1.0f/((float)noSteps-1.0f);
|
||||
|
||||
lpn._lightPointList.reserve(noSteps);
|
||||
lpn.getLightPointList().reserve(noSteps);
|
||||
|
||||
for(unsigned int i=0;i<noSteps;++i,rend+=rdelta)
|
||||
{
|
||||
@@ -42,9 +43,6 @@ void addToLightPointNode(osgSim::LightPointNode& lpn,osgSim::LightPoint& start,o
|
||||
INTERPOLATE(_intensity);
|
||||
INTERPOLATE(_color);
|
||||
INTERPOLATE(_radius);
|
||||
//INTERPOLATE(_minPixelSize);
|
||||
//INTERPOLATE(_maxPixelSize);
|
||||
// INTERPOLATE(_maxVisibileDistance2);
|
||||
|
||||
lpn.addLightPoint(lp);
|
||||
|
||||
@@ -156,10 +154,7 @@ int main( int argc, char **argv )
|
||||
// load the nodes from the commandline arguments.
|
||||
rootnode->addChild(osgDB::readNodeFiles(arguments));
|
||||
rootnode->addChild(createLightPointsDatabase());
|
||||
if (!rootnode)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
// run optimization over the scene graph
|
||||
osgUtil::Optimizer optimzer;
|
||||
|
||||
@@ -45,7 +45,6 @@ class OSGSIM_EXPORT LightPoint
|
||||
const osg::Vec4& color,
|
||||
float intensity=1.0f,
|
||||
float radius=1.0f,
|
||||
float maxPixelSize=30,
|
||||
Sector* sector=0,
|
||||
BlinkSequence* blinkSequence=0,
|
||||
BlendingMode blendingMode=BLENDED);
|
||||
@@ -61,7 +60,6 @@ class OSGSIM_EXPORT LightPoint
|
||||
osg::Vec4 _color;
|
||||
float _intensity;
|
||||
float _radius;
|
||||
float _maxPixelSize;
|
||||
|
||||
osg::ref_ptr<Sector> _sector;
|
||||
osg::ref_ptr<BlinkSequence> _blinkSequence;
|
||||
|
||||
@@ -44,18 +44,35 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node
|
||||
|
||||
virtual void traverse(osg::NodeVisitor& nv);
|
||||
|
||||
|
||||
|
||||
unsigned int addLightPoint(const LightPoint& lp);
|
||||
|
||||
void removeLightPoint(unsigned int pos);
|
||||
|
||||
|
||||
LightPoint& getLightPoint(unsigned int pos) { return _lightPointList[pos]; }
|
||||
|
||||
const LightPoint& getLightPoint(unsigned int pos) const { return _lightPointList[pos]; }
|
||||
|
||||
void removeLightPoint(unsigned int pos);
|
||||
|
||||
void removeLightPoints(LightPointList::iterator start,LightPointList::iterator end);
|
||||
|
||||
LightPointList _lightPointList;
|
||||
void setLightPointList(const LightPointList& lpl) { _lightPointList=lpl; }
|
||||
|
||||
LightPointList& getLightPointList() { return _lightPointList; }
|
||||
|
||||
const LightPointList& getLightPointList() const { return _lightPointList; }
|
||||
|
||||
|
||||
void setMinPixelSize(float minPixelSize) { _minPixelSize = minPixelSize; }
|
||||
|
||||
float getMinPixelSize() const { return _minPixelSize; }
|
||||
|
||||
void setMaxPixelSize(float maxPixelSize) { _maxPixelSize = maxPixelSize; }
|
||||
|
||||
float getMaxPixelSize() const { return _maxPixelSize; }
|
||||
|
||||
void setMaxVisableDistance2(float maxVisableDistance2) { _maxVisableDistance2 = maxVisableDistance2; }
|
||||
|
||||
float setMaxVisableDistance2() const { return _maxVisableDistance2; }
|
||||
|
||||
protected:
|
||||
|
||||
@@ -67,6 +84,11 @@ class OSGSIM_EXPORT LightPointNode : public osg::Node
|
||||
|
||||
virtual bool computeBound() const;
|
||||
|
||||
LightPointList _lightPointList;
|
||||
|
||||
float _minPixelSize;
|
||||
float _maxPixelSize;
|
||||
float _maxVisableDistance2;
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -96,11 +96,11 @@ void CullStack::pushCullingSet()
|
||||
float P23 = P(2,3);
|
||||
float P33 = P(3,3);
|
||||
osg::Vec4 pixelSizeVector(M(0,2)*P23,
|
||||
M(1,2)*P23,
|
||||
M(2,2)*P23,
|
||||
M(3,2)*P23 + M(3,3)*P33);
|
||||
M(1,2)*P23,
|
||||
M(2,2)*P23,
|
||||
M(3,2)*P23 + M(3,3)*P33);
|
||||
|
||||
float scaleRatio = 1.0f/sqrtf(scale_00.length2()+scale_10.length2());
|
||||
float scaleRatio = 0.701f/sqrtf(scale_00.length2()+scale_10.length2());
|
||||
|
||||
pixelSizeVector *= scaleRatio;
|
||||
|
||||
|
||||
@@ -826,7 +826,7 @@ class ReaderWriterGEO : public ReaderWriter
|
||||
float blue=cls[2]/255.0f;
|
||||
//float alpha=1.0f; // cls[3]*frac/255.0f;
|
||||
osg::Vec4 colour(red,green,blue,1.0f);
|
||||
lpn->addLightPoint(osgSim::LightPoint(true,coord_pool[idx],colour,1.0f,1.0f,30,0,0,osgSim::LightPoint::BLENDED));
|
||||
lpn->addLightPoint(osgSim::LightPoint(true,coord_pool[idx],colour,1.0f,1.0f,0,0,osgSim::LightPoint::BLENDED));
|
||||
} else { // get colour from palette
|
||||
gfd=(*itr)->getField(GEO_DB_VRTX_COLOR_INDEX); // use color pool...
|
||||
int icp= gfd ? gfd->getInt() : 0;
|
||||
|
||||
@@ -21,7 +21,6 @@ LightPoint::LightPoint():
|
||||
_color(1.0f,1.0f,1.0f,1.0f),
|
||||
_intensity(1.0f),
|
||||
_radius(1.0f),
|
||||
_maxPixelSize(30),
|
||||
_sector(0),
|
||||
_blinkSequence(0),
|
||||
_blendingMode(BLENDED)
|
||||
@@ -34,7 +33,6 @@ LightPoint::LightPoint(const osg::Vec3& position,const osg::Vec4& color):
|
||||
_color(color),
|
||||
_intensity(1.0f),
|
||||
_radius(1.0f),
|
||||
_maxPixelSize(30),
|
||||
_sector(0),
|
||||
_blinkSequence(0),
|
||||
_blendingMode(BLENDED)
|
||||
@@ -46,7 +44,6 @@ LightPoint::LightPoint(bool on,
|
||||
const osg::Vec4& color,
|
||||
float intensity,
|
||||
float radius,
|
||||
float maxPixelSize,
|
||||
Sector* sector,
|
||||
BlinkSequence* blinkSequence,
|
||||
BlendingMode blendingMode):
|
||||
@@ -55,7 +52,6 @@ LightPoint::LightPoint(bool on,
|
||||
_color(color),
|
||||
_intensity(intensity),
|
||||
_radius(radius),
|
||||
_maxPixelSize(maxPixelSize),
|
||||
_sector(sector),
|
||||
_blinkSequence(blinkSequence),
|
||||
_blendingMode(blendingMode)
|
||||
@@ -68,7 +64,6 @@ LightPoint::LightPoint(const LightPoint& lp):
|
||||
_color(lp._color),
|
||||
_intensity(lp._intensity),
|
||||
_radius(lp._radius),
|
||||
_maxPixelSize(lp._maxPixelSize),
|
||||
_sector(lp._sector),
|
||||
_blinkSequence(lp._blinkSequence),
|
||||
_blendingMode(lp._blendingMode)
|
||||
@@ -82,7 +77,6 @@ LightPoint& LightPoint::operator = (const LightPoint& lp)
|
||||
_color = lp._color;
|
||||
_intensity = lp._intensity;
|
||||
_radius = lp._radius;
|
||||
_maxPixelSize = lp._maxPixelSize;
|
||||
_sector = lp._sector;
|
||||
_blinkSequence = lp._blinkSequence;
|
||||
_blendingMode = lp._blendingMode;
|
||||
|
||||
@@ -26,14 +26,20 @@
|
||||
|
||||
using namespace osgSim;
|
||||
|
||||
LightPointNode::LightPointNode()
|
||||
LightPointNode::LightPointNode():
|
||||
_minPixelSize(0.0f),
|
||||
_maxPixelSize(30.0f),
|
||||
_maxVisableDistance2(FLT_MAX)
|
||||
{
|
||||
}
|
||||
|
||||
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
||||
LightPointNode::LightPointNode(const LightPointNode& lpn,const osg::CopyOp& copyop):
|
||||
osg::Node(lpn,copyop),
|
||||
_lightPointList(lpn._lightPointList)
|
||||
_lightPointList(lpn._lightPointList),
|
||||
_minPixelSize(lpn._minPixelSize),
|
||||
_maxPixelSize(lpn._maxPixelSize),
|
||||
_maxVisableDistance2(lpn._maxVisableDistance2)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -55,11 +61,6 @@ void LightPointNode::removeLightPoint(unsigned int pos)
|
||||
dirtyBound();
|
||||
}
|
||||
|
||||
void LightPointNode::removeLightPoints(LightPointList::iterator start,LightPointList::iterator end)
|
||||
{
|
||||
_lightPointList.erase(start,end);
|
||||
}
|
||||
|
||||
bool LightPointNode::computeBound() const
|
||||
{
|
||||
_bsphere.init();
|
||||
@@ -81,9 +82,13 @@ bool LightPointNode::computeBound() const
|
||||
itr!=_lightPointList.end();
|
||||
++itr)
|
||||
{
|
||||
_bsphere.expandRadiusBy(itr->_position);
|
||||
osg::Vec3 dv(itr->_position-_bsphere.center());
|
||||
float radius = dv.length()+itr->_radius;
|
||||
if (_bsphere.radius()<radius) _bsphere.radius()=radius;
|
||||
}
|
||||
|
||||
_bsphere.radius()+=1.0f;
|
||||
|
||||
_bsphere_computed=true;
|
||||
return true;
|
||||
}
|
||||
@@ -231,6 +236,13 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
|
||||
// slip light point if it is intensity is 0.0 or negative.
|
||||
if (intensity<=minimumIntensity) continue;
|
||||
|
||||
|
||||
if (_maxVisableDistance2!=FLT_MAX)
|
||||
{
|
||||
if (dv.length2()>_maxVisableDistance2) continue;
|
||||
}
|
||||
|
||||
|
||||
osg::Vec4 color = lp._color;
|
||||
|
||||
// check the sector.
|
||||
@@ -265,7 +277,9 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
|
||||
|
||||
// adjust pixel size to account for intensity.
|
||||
if (intensity!=1.0) pixelSize *= sqrt(intensity);
|
||||
|
||||
|
||||
// round up to the minimum pixel size if required.
|
||||
if (pixelSize<_minPixelSize) pixelSize = _minPixelSize;
|
||||
|
||||
osg::Vec3 xpos(position*matrix);
|
||||
|
||||
@@ -281,7 +295,7 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
|
||||
|
||||
drawable->addBlendedLightPoint(0, xpos,color);
|
||||
}
|
||||
else if (pixelSize<lp._maxPixelSize)
|
||||
else if (pixelSize<_maxPixelSize)
|
||||
{
|
||||
|
||||
unsigned int lowerBoundPixelSize = (unsigned int)pixelSize;
|
||||
@@ -295,7 +309,7 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
|
||||
}
|
||||
else // use a billboard geometry.
|
||||
{
|
||||
drawable->addBlendedLightPoint((unsigned int)(lp._maxPixelSize-1.0), xpos,color);
|
||||
drawable->addBlendedLightPoint((unsigned int)(_maxPixelSize-1.0), xpos,color);
|
||||
}
|
||||
}
|
||||
else // ADDITIVE blending.
|
||||
@@ -310,7 +324,7 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
|
||||
|
||||
drawable->addAdditiveLightPoint(0, xpos,color);
|
||||
}
|
||||
else if (pixelSize<lp._maxPixelSize)
|
||||
else if (pixelSize<_maxPixelSize)
|
||||
{
|
||||
|
||||
unsigned int lowerBoundPixelSize = (unsigned int)pixelSize;
|
||||
@@ -325,7 +339,7 @@ void LightPointNode::traverse(osg::NodeVisitor& nv)
|
||||
}
|
||||
else // use a billboard geometry.
|
||||
{
|
||||
drawable->addAdditiveLightPoint((unsigned int)(lp._maxPixelSize-1.0), xpos,color);
|
||||
drawable->addAdditiveLightPoint((unsigned int)(_maxPixelSize-1.0), xpos,color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user