Files
OpenSceneGraph/src/osgText/FadeText.cpp
Robert Osfield 93156fd2ce Merged from svn/trunk changeset 12597:
Resolved warnings reported by g++ 4.6's -Wunused-but-set-variable.

Warnings were:

src/osg/ShapeDrawable.cpp: In member function ?void PrimitiveShapeVisitor::createHalfSphere(unsigned int, unsigned int, float, int, float, const Matrix&)?:
src/osg/ShapeDrawable.cpp:1409:11: warning: variable ?nzBase? set but not used [-Wunused-but-set-variable]
src/osg/ShapeDrawable.cpp:1410:11: warning: variable ?nRatioBase? set but not used [-Wunused-but-set-variable]
src/osgUtil/DelaunayTriangulator.cpp: In function ?osgUtil::Triangle_list osgUtil::fillHole(osg::Vec3Array*, std::vector<unsigned int, std::allocator<unsigned int> >)?:
src/osgUtil/DelaunayTriangulator.cpp:569:27: warning: variable ?ptest? set but not used [-Wunused-but-set-variable]
src/osgUtil/DelaunayTriangulator.cpp: In member function ?bool osgUtil::DelaunayTriangulator::triangulate()?:
src/osgUtil/DelaunayTriangulator.cpp:979:45: warning: variable ?curp? set but not used [-Wunused-but-set-variable]
src/osgUtil/RenderStage.cpp: In member function ?void osgUtil::RenderStage::runCameraSetUp(osg::RenderInfo&)?:
src/osgUtil/RenderStage.cpp:631:18: warning: variable ?stencilAttached? set but not used [-Wunused-but-set-variable]
src/osgText/FadeText.cpp: In member function ?void FadeTextPolytopeData::buildPolytope()?:
src/osgText/FadeText.cpp:74:20: warning: variable ?edge23? set but not used [-Wunused-but-set-variable]
src/osgText/FadeText.cpp:75:20: warning: variable ?edge30? set but not used [-Wunused-but-set-variable]
src/osgText/Text.cpp: In member function ?void osgText::Text::computeBackdropPositions(unsigned int) const?:
src/osgText/Text.cpp:747:10: warning: variable ?is_valid_size? set but not used [-Wunused-but-set-variable]
src/osgGA/NodeTrackerManipulator.cpp: In member function ?virtual bool osgGA::NodeTrackerManipulator::performMovementLeftMouseButton(double, double, double)?:
src/osgGA/NodeTrackerManipulator.cpp:257:21: warning: variable ?lookVector? set but not used [-Wunused-but-set-variable]
src/osgGA/NodeTrackerManipulator.cpp:259:21: warning: variable ?upVector? set but not used [-Wunused-but-set-variable]
src/osgGA/TerrainManipulator.cpp: In member function ?virtual bool osgGA::TerrainManipulator::performMovementMiddleMouseButton(double, double, double)?:
src/osgGA/TerrainManipulator.cpp:217:11: warning: variable ?lookVector? set but not used [-Wunused-but-set-variable]
src/osgGA/TerrainManipulator.cpp:219:11: warning: variable ?upVector? set but not used [-Wunused-but-set-variable]
src/osgVolume/FixedFunctionTechnique.cpp: In member function ?virtual void osgVolume::FixedFunctionTechnique::init()?:
src/osgVolume/FixedFunctionTechnique.cpp:124:30: warning: variable ?tf? set but not used [-Wunused-but-set-variable]
src/osgParticle/FluidProgram.cpp: In member function ?virtual void osgParticle::FluidProgram::execute(double)?:
src/osgParticle/FluidProgram.cpp:38:23: warning: variable ?velBefore? set but not used [-Wunused-but-set-variable]
src/osgShadow/ParallelSplitShadowMap.cpp: In member function ?virtual void osgShadow::ParallelSplitShadowMap::cull(osgUtil::CullVisitor&)?:
src/osgShadow/ParallelSplitShadowMap.cpp:593:22: warning: variable ?bb? set but not used [-Wunused-but-set-variable]
src/osgTerrain/GeometryTechnique.cpp: In member function ?virtual void osgTerrain::GeometryTechnique::generateGeometry(osgTerrain::GeometryTechnique::BufferData&, osgTerrain::Locator*, const osg::Vec3d&)?:
src/osgTerrain/GeometryTechnique.cpp:777:12: warning: variable ?i_sampleFactor? set but not used [-Wunused-but-set-variable]
src/osgTerrain/GeometryTechnique.cpp:778:12: warning: variable ?j_sampleFactor? set but not used [-Wunused-but-set-variable]
src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ?osg::Image* ReadDDSFile(std::istream&)?:
src/osgPlugins/dds/ReaderWriterDDS.cpp:314:10: warning: variable ?is3dImage? set but not used [-Wunused-but-set-variable]
src/osgPlugins/dds/ReaderWriterDDS.cpp: In function ?bool WriteDDSFile(const osg::Image*, std::ostream&)?:
src/osgPlugins/dds/ReaderWriterDDS.cpp:721:10: warning: variable ?is3dImage? set but not used [-Wunused-but-set-variable]
src/osgPlugins/hdr/hdrloader.cpp: In static member function ?static bool HDRLoader::load(const char*, bool, HDRLoaderResult&)?:
src/osgPlugins/hdr/hdrloader.cpp:101:10: warning: variable ?cmd? set but not used [-Wunused-but-set-variable]
src/osgPlugins/vtf/ReaderWriterVTF.cpp: In function ?osg::Image* ReadVTFFile(std::istream&)?:
src/osgPlugins/vtf/ReaderWriterVTF.cpp:360:23: warning: variable ?base? set but not used [-Wunused-but-set-variable]
src/osgPlugins/jp2/ReaderWriterJP2.cpp: In function ?int putdata(jas_stream_t*, jas_image_t*, int)?:
src/osgPlugins/jp2/ReaderWriterJP2.cpp:41:13: warning: variable ?linelen? set but not used [-Wunused-but-set-variable]
src/osgPlugins/Inventor/ConvertToInventor.cpp: In member function ?void ConvertToInventor::processGeometry(const osg::Geometry*, ConvertToInventor::InventorState*)?:
src/osgPlugins/Inventor/ConvertToInventor.cpp:1639:10: warning: variable ?ok? set but not used [-Wunused-but-set-variable]
src/osgPlugins/Inventor/ConvertFromInventor.cpp: In member function ?virtual SbBool SoVRMLImageTextureOsg::readInstance(SoInput*, short unsigned int)?:
src/osgPlugins/Inventor/ConvertFromInventor.cpp:1264:16: warning: variable ?retval? set but not used [-Wunused-but-set-variable]
src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ?virtual void flt::Face::readRecord(flt::RecordInputStream&, flt::Document&)?:
src/osgPlugins/OpenFlight/GeometryRecords.cpp:369:19: warning: variable ?secondaryPackedColor? set but not used [-Wunused-but-set-variable]
src/osgPlugins/OpenFlight/GeometryRecords.cpp: In member function ?virtual void flt::Mesh::readRecord(flt::RecordInputStream&, flt::Document&)?:
src/osgPlugins/OpenFlight/GeometryRecords.cpp:942:19: warning: variable ?secondaryPackedColor? set but not used [-Wunused-but-set-variable]
src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp: In member function ?virtual osgDB::ReaderWriter::ReadResult FLTReaderWriter::readNode(std::istream&, const Options*) const?:
src/osgPlugins/OpenFlight/ReaderWriterFLT.cpp:427:40: warning: variable ?pos? set but not used [-Wunused-but-set-variable]
src/osgPlugins/ive/ShapeAttributeList.cpp: In member function ?void ive::ShapeAttributeList::write(ive::DataOutputStream*)?:
src/osgPlugins/ive/ShapeAttributeList.cpp:31:48: warning: variable ?it? set but not used [-Wunused-but-set-variable]
src/osgPlugins/ac/Geode.cpp: In member function ?void ac3d::Geode::ProcessGeometry(std::ostream&, unsigned int)?:
src/osgPlugins/ac/Geode.cpp:806:35: warning: variable ?fRep_s? set but not used [-Wunused-but-set-variable]
src/osgPlugins/ac/Geode.cpp:806:43: warning: variable ?fRep_t? set but not used [-Wunused-but-set-variable]
src/osgPlugins/ac/Geode.cpp:807:35: warning: variable ?fOffset_s? set but not used [-Wunused-but-set-variable]
src/osgPlugins/ac/Geode.cpp:807:46: warning: variable ?fOffset_t? set but not used [-Wunused-but-set-variable]
src/osgPlugins/ac/Geode.cpp:932:38: warning: variable ?primLength? set but not used [-Wunused-but-set-variable]
src/osgPlugins/txp/trpage_geom.cpp: In member function ?virtual bool trpgGeometry::Write(trpgWriteBuffer&)?:
src/osgPlugins/txp/trpage_geom.cpp:615:19: warning: variable ?u? set but not used [-Wunused-but-set-variable]
src/osgPlugins/txp/trpage_material.cpp: In member function ?int trpgMatTable::AddMaterial(const trpgMaterial&, bool)?:
src/osgPlugins/txp/trpage_material.cpp:103:10: warning: variable ?spaceInTable? set but not used [-Wunused-but-set-variable]
src/osgPlugins/txp/trpage_rarchive.cpp: In member function ?virtual bool trpgr_Archive::ReadHeader(bool)?:
src/osgPlugins/txp/trpage_rarchive.cpp:261:14: warning: variable ?headerHasTexTable? set but not used [-Wunused-but-set-variable]
src/osgPlugins/zip/unzip.cpp: In member function ?ZRESULT TUnzip::Get(int, ZIPENTRY*)?:
src/osgPlugins/zip/unzip.cpp:4055:8: warning: variable ?hidden? set but not used [-Wunused-but-set-variable]
src/osgPlugins/zip/unzip.cpp:4055:22: warning: variable ?system? set but not used [-Wunused-but-set-variable]
src/osgPlugins/zip/unzip.cpp:4055:36: warning: variable ?archive? set but not used [-Wunused-but-set-variable]
src/osgPlugins/zip/ZipArchive.cpp: In member function ?virtual bool ZipArchive::getFileNames(osgDB::Archive::FileNameList&) const?:
src/osgPlugins/zip/ZipArchive.cpp:91:37: warning: variable ?iterEnd? set but not used [-Wunused-but-set-variable]
src/osgPlugins/pvr/ReaderWriterPVR.cpp: In member function ?osgDB::ReaderWriter::ReadResult ReaderWriterPVR::readPVRStream(std::istream&) const?:
src/osgPlugins/pvr/ReaderWriterPVR.cpp:155:14: warning: variable ?hasAlpha? set but not used [-Wunused-but-set-variable]
src/osgViewer/View.cpp: In function ?osg::Geometry* create3DSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)?:
src/osgViewer/View.cpp:737:15: warning: variable ?cursor? set but not used [-Wunused-but-set-variable]
src/osgViewer/View.cpp: In function ?osg::Geometry* createParoramicSphericalDisplayDistortionMesh(const Vec3&, const Vec3&, const Vec3&, double, double, osg::Image*, const Matrix&)?:
src/osgViewer/View.cpp:1130:19: warning: variable ?cursor? set but not used [-Wunused-but-set-variable]
src/osgViewer/View.cpp:1118:15: warning: variable ?dx? set but not used [-Wunused-but-set-variable]
src/osgViewer/GraphicsWindowX11.cpp: In member function ?virtual void osgViewer::GraphicsWindowX11::checkEvents()?:
src/osgViewer/GraphicsWindowX11.cpp:1181:10: warning: variable ?destroyWindowRequested? set but not used [-Wunused-but-set-variable]
src/osgPlugins/cfg/ConfigParser.cpp: In member function ?bool osgProducer::CameraConfig::parseFile(const string&)?:
src/osgPlugins/cfg/ConfigParser.cpp:2247:13: warning: variable ?result? set but not used [-Wunused-but-set-variable]
src/osgQt/QGraphicsViewAdapter.cpp: In member function ?bool osgQt::QGraphicsViewAdapter::handlePointerEvent(int, int, int)?:
src/osgQt/QGraphicsViewAdapter.cpp:344:17: warning: variable ?viewportGeometry? set but not used [-Wunused-but-set-variable]
examples/osgdistortion/osgdistortion.cpp: In function ?osg::Node* createDistortionSubgraph(osg::Node*, const Vec4&)?:
examples/osgdistortion/osgdistortion.cpp:125:19: warning: variable ?cursor? set but not used [-Wunused-but-set-variable]
examples/osgdistortion/osgdistortion.cpp:126:19: warning: variable ?texcoord? set but not used [-Wunused-but-set-variable]
examples/osgdistortion/osgdistortion.cpp: In function ?osg::Geometry* createDomeDistortionMesh(const Vec3&, const Vec3&, const Vec3&, osg::ArgumentParser&)?:
examples/osgdistortion/osgdistortion.cpp:358:15: warning: variable ?cursor? set but not used [-Wunused-but-set-variable]
examples/osgposter/osgposter.cpp: In function ?int main(int, char**)?:
examples/osgposter/osgposter.cpp:253:31: warning: variable ?outputTiles? set but not used [-Wunused-but-set-variable]
examples/osgthreadedterrain/osgthreadedterrain.cpp: In function ?int main(int, char**)?:
examples/osgthreadedterrain/osgthreadedterrain.cpp:669:10: warning: variable ?readParameter? set but not used [-Wunused-but-set-variable]
examples/osgtext3D/TextNode.cpp: In member function ?virtual void osgText::Layout::layout(osgText::TextNode&) const?:
examples/osgtext3D/TextNode.cpp:80:11: warning: variable ?characterHeightScale? set but not used [-Wunused-but-set-variable]
examples/osgvolume/osgvolume.cpp: In function ?int main(int, char**)?:
examples/osgvolume/osgvolume.cpp:678:38: warning: variable ?internalFormatMode? set but not used [-Wunused-but-set-variable]
examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ?bool windowMouseOver(osgWidget::Event&)?:
examples/osgwidgetcanvas/osgwidgetcanvas.cpp:27:24: warning: variable ?xy? set but not used [-Wunused-but-set-variable]
examples/osgwidgetcanvas/osgwidgetcanvas.cpp: In function ?bool widgetMouseOver(osgWidget::Event&)?:
examples/osgwidgetcanvas/osgwidgetcanvas.cpp:35:24: warning: variable ?xy? set but not used [-Wunused-but-set-variable]
src/osgPlugins/p3d/ReaderWriterP3D.cpp: In member function ?osg::Node* ReaderWriterP3DXML::parseXmlGraph(osgDB::XmlNode*, bool, osgDB::Options*) const?:
src/osgPlugins/p3d/ReaderWriterP3D.cpp:2121:10: warning: variable ?readSlide? set but not used [-Wunused-but-set-variable]
applications/present3D/present3D.cpp: In function ?int main(int, char**)?:
applications/present3D/present3D.cpp:639:10: warning: variable ?sizesSpecified? set but not used [-Wunused-but-set-variable]
2011-06-22 12:38:53 +00:00

420 lines
13 KiB
C++

/* -*-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.
*/
#include <osgText/FadeText>
#include <osg/Notify>
#include <osg/io_utils>
#include <OpenThreads/Mutex>
#include <OpenThreads/ScopedLock>
using namespace osgText;
struct FadeTextData : public osg::Referenced
{
FadeTextData(FadeText* fadeText=0):
_fadeText(fadeText),
_visible(true) {}
bool operator < (const FadeTextData& rhs) const
{
return _fadeText < rhs._fadeText;
}
double getNearestZ() const
{
double nearestZ = _vertices[0].z();
if (nearestZ < _vertices[1].z()) nearestZ = _vertices[1].z();
if (nearestZ < _vertices[2].z()) nearestZ = _vertices[2].z();
if (nearestZ < _vertices[3].z()) nearestZ = _vertices[3].z();
// OSG_NOTICE<<"getNearestZ()="<<_fadeText->getText().createUTF8EncodedString()<<" "<<nearestZ<<std::endl;
return nearestZ;
}
FadeText* _fadeText;
osg::Vec3d _vertices[4];
bool _visible;
};
struct FadeTextPolytopeData : public FadeTextData, public osg::Polytope
{
FadeTextPolytopeData(FadeTextData& fadeTextData):
FadeTextData(fadeTextData)
{
_referenceVertexList.push_back(_vertices[0]);
_referenceVertexList.push_back(_vertices[1]);
_referenceVertexList.push_back(_vertices[2]);
_referenceVertexList.push_back(_vertices[3]);
}
void addEdgePlane(const osg::Vec3& corner, const osg::Vec3& edge)
{
osg::Vec3 normal( edge.y(), -edge.x(), 0.0f);
normal.normalize();
add(osg::Plane(normal, corner));
}
void buildPolytope()
{
osg::Vec3d edge01 = _vertices[1] - _vertices[0];
osg::Vec3d edge12 = _vertices[2] - _vertices[1];
osg::Vec3d normalFrontFace = edge01 ^ edge12;
bool needToFlip = normalFrontFace.z()>0.0f;
normalFrontFace.normalize();
add(osg::Plane(normalFrontFace, _vertices[0]));
add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[0], _vertices[1]));
add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[1], _vertices[2]));
add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[2], _vertices[3]));
add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[3], _vertices[0]));
#if 0
OSG_NOTICE<<" normalFrontFace = "<<normalFrontFace<<std::endl;
OSG_NOTICE<<" edge01 = "<<edge01<<std::endl;
OSG_NOTICE<<" edge12 = "<<edge12<<std::endl;
OSG_NOTICE<<" _vertices[0]= "<<_vertices[0]<<std::endl;
OSG_NOTICE<<" _vertices[1]= "<<_vertices[1]<<std::endl;
OSG_NOTICE<<" _vertices[2]= "<<_vertices[2]<<std::endl;
OSG_NOTICE<<" _vertices[3]= "<<_vertices[3]<<std::endl;
#endif
if (needToFlip) flip();
#if 0
OSG_NOTICE<<" plane 0 "<< _planeList[0]<<std::endl;
OSG_NOTICE<<" plane 1 "<< _planeList[1]<<std::endl;
OSG_NOTICE<<" plane 2 "<< _planeList[2]<<std::endl;
OSG_NOTICE<<" plane 3 "<< _planeList[3]<<std::endl;
OSG_NOTICE<<" plane 4 "<< _planeList[4]<<std::endl;
#endif
}
inline bool contains(const std::vector<osg::Vec3>& vertices)
{
for(std::vector<osg::Vec3>::const_iterator itr = vertices.begin();
itr != vertices.end();
++itr)
{
if (osg::Polytope::contains(*itr))
{
return true;
}
}
return false;
}
};
struct FadeTextUserData : public osg::Referenced
{
FadeTextUserData():
_frameNumber(0) {}
typedef std::list<FadeTextData> FadeTextList;
unsigned int _frameNumber;
FadeTextList _fadeTextInView;
};
struct GlobalFadeText : public osg::Referenced
{
typedef std::set< osg::ref_ptr<FadeTextUserData> > UserDataSet;
typedef std::set<FadeText*> FadeTextSet;
typedef std::multimap<double, osg::ref_ptr<FadeTextPolytopeData> > FadeTextPolytopeMap;
typedef std::map<osg::View*, UserDataSet> ViewUserDataMap;
typedef std::map<osg::View*, FadeTextSet > ViewFadeTextMap;
GlobalFadeText():
_frameNumber(0xffffffff)
{
}
FadeTextUserData* createNewFadeTextUserData(osg::View* view)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
FadeTextUserData* userData = new FadeTextUserData;
if (!userData)
{
OSG_NOTICE<<"Memory error, unable to create FadeTextUserData."<<std::endl;
return 0;
}
_viewMap[view].insert(userData);
return userData;
}
void update(unsigned int frameNumber)
{
_frameNumber = frameNumber;
for(GlobalFadeText::ViewUserDataMap::iterator vitr = _viewMap.begin();
vitr != _viewMap.end();
++vitr)
{
osg::View* view = vitr->first;
FadeTextSet& fadeTextSet = _viewFadeTextMap[view];
fadeTextSet.clear();
FadeTextPolytopeMap fadeTextPolytopeMap;
for(GlobalFadeText::UserDataSet::iterator uitr = vitr->second.begin();
uitr != vitr->second.end();
++uitr)
{
FadeTextUserData* userData = uitr->get();
int frameDelta = frameNumber - userData->_frameNumber;
if (frameDelta<=1)
{
for(FadeTextUserData::FadeTextList::iterator fitr = userData->_fadeTextInView.begin();
fitr != userData->_fadeTextInView.end();
++fitr)
{
FadeTextData& fadeTextData = *fitr;
if (fadeTextSet.count(fadeTextData._fadeText)==0)
{
fadeTextSet.insert(fadeTextData._fadeText);
fadeTextPolytopeMap.insert(FadeTextPolytopeMap::value_type(
-fadeTextData.getNearestZ(), new FadeTextPolytopeData(fadeTextData)));
}
}
}
}
// for each FadeTexPoltopeData
// create polytopes
// test against all FTPD's later in the list
// test all control points on FTPD against each plane of the current polytope
// if all control points removed or outside then discard FTPD and make FT visible = false;
FadeTextPolytopeMap::iterator outer_itr = fadeTextPolytopeMap.begin();
while (outer_itr != fadeTextPolytopeMap.end())
{
FadeTextPolytopeMap::iterator inner_itr = outer_itr;
++inner_itr;
if (inner_itr == fadeTextPolytopeMap.end()) break;
FadeTextPolytopeData& outer_ftpm = *(outer_itr->second);
outer_ftpm.buildPolytope();
// OSG_NOTICE<<"Outer z "<<outer_ftpm.getNearestZ()<<std::endl;
while(inner_itr != fadeTextPolytopeMap.end())
{
FadeTextPolytopeData& inner_ftpm = *(inner_itr->second);
// OSG_NOTICE<<"Inner z "<<inner_ftpm.getNearestZ()<<std::endl;
if (outer_ftpm.contains(inner_ftpm.getReferenceVertexList()))
{
FadeTextPolytopeMap::iterator erase_itr = inner_itr;
// move to next ftpm
++inner_itr;
fadeTextSet.erase(inner_ftpm._fadeText);
// need to remove inner_ftpm as its occluded.
fadeTextPolytopeMap.erase(erase_itr);
}
else
{
// move to next ftpm
++inner_itr;
}
}
++outer_itr;
}
}
}
inline void updateIfRequired(unsigned int frameNumber)
{
if (_frameNumber!=frameNumber) update(frameNumber);
}
unsigned int _frameNumber;
OpenThreads::Mutex _mutex;
ViewUserDataMap _viewMap;
ViewFadeTextMap _viewFadeTextMap;
};
GlobalFadeText* getGlobalFadeText()
{
static osg::ref_ptr<GlobalFadeText> s_globalFadeText = new GlobalFadeText;
return s_globalFadeText.get();
}
struct FadeText::FadeTextUpdateCallback : public osg::Drawable::UpdateCallback
{
FadeTextData _ftd;
virtual void update(osg::NodeVisitor* nv, osg::Drawable* drawable)
{
osgText::FadeText* fadeText = dynamic_cast<osgText::FadeText*>(drawable);
if (!fadeText) return;
unsigned int frameNumber = nv->getFrameStamp()->getFrameNumber();
GlobalFadeText* gft = getGlobalFadeText();
gft->updateIfRequired(frameNumber);
osgText::FadeText::ViewBlendColourMap& vbcm = fadeText->getViewBlendColourMap();
_ftd._fadeText = fadeText;
float fadeSpeed = fadeText->getFadeSpeed();
GlobalFadeText::ViewFadeTextMap& vftm = gft->_viewFadeTextMap;
for(GlobalFadeText::ViewFadeTextMap::iterator itr = vftm.begin();
itr != vftm.end();
++itr)
{
osg::View* view = itr->first;
GlobalFadeText::FadeTextSet& fadeTextSet = itr->second;
bool visible = fadeTextSet.count(fadeText)!=0;
osg::Vec4& tec = vbcm[view];
tec[0] = 1.0f;
tec[1] = 1.0f;
tec[2] = 1.0f;
if (visible)
{
if (tec[3]<1.0f)
{
tec[3] += fadeSpeed;
if (tec[3]>1.0f) tec[3] = 1.0f;
}
}
else
{
if (tec[3]>0.0f)
{
tec[3] -= fadeSpeed;
if (tec[3]<0.0f) tec[3] = 0.0f;
}
}
}
}
};
FadeText::FadeText()
{
init();
}
FadeText::FadeText(const Text& text,const osg::CopyOp& copyop):
Text(text,copyop)
{
init();
}
void FadeText::init()
{
setDataVariance(osg::Object::DYNAMIC);
_fadeSpeed = 0.01f;
setUpdateCallback(new FadeTextUpdateCallback());
}
void FadeText::drawImplementation(osg::RenderInfo& renderInfo) const
{
osg::State& state = *renderInfo.getState();
ViewBlendColourMap::iterator itr = _viewBlendColourMap.find(renderInfo.getView());
if (itr != _viewBlendColourMap.end())
{
Text::drawImplementation(*renderInfo.getState(), itr->second );
}
else
{
Text::drawImplementation(*renderInfo.getState(), osg::Vec4(1.0f,1.0f,1.0f,1.0f) );
}
// now pass on new details
FadeTextUserData* userData = dynamic_cast<FadeTextUserData*>(renderInfo.getUserData());
if (!userData)
{
if (renderInfo.getUserData())
{
OSG_NOTICE<<"Warning user data not of supported type."<<std::endl;
return;
}
userData = getGlobalFadeText()->createNewFadeTextUserData(renderInfo.getView());
if (!userData)
{
OSG_NOTICE<<"Memory error, unable to create FadeTextUserData."<<std::endl;
return;
}
renderInfo.setUserData(userData);
}
unsigned int frameNumber = renderInfo.getState()->getFrameStamp()->getFrameNumber();
if (frameNumber != userData->_frameNumber)
{
// new frame so must reset UserData structure.
userData->_frameNumber = frameNumber;
userData->_fadeTextInView.clear();
}
osgText::Text::AutoTransformCache& atc = _autoTransformCache[renderInfo.getContextID()];
osg::Matrix lmv = atc._matrix;
lmv.postMult(state.getModelViewMatrix());
if (renderInfo.getView() && renderInfo.getView()->getCamera())
{
// move from camera into the view space.
lmv.postMult(state.getInitialInverseViewMatrix());
lmv.postMult(renderInfo.getView()->getCamera()->getViewMatrix());
}
FadeTextData ftd(const_cast<osgText::FadeText*>(this));
ftd._vertices[0].set(osg::Vec3d(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*lmv);
ftd._vertices[1].set(osg::Vec3d(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*lmv);
ftd._vertices[2].set(osg::Vec3d(_textBB.xMax(),_textBB.yMax(),_textBB.zMin())*lmv);
ftd._vertices[3].set(osg::Vec3d(_textBB.xMin(),_textBB.yMax(),_textBB.zMin())*lmv);
userData->_fadeTextInView.push_back(ftd);
}