Changeset 13041 for OpenSceneGraph/trunk/src/osgText/FadeText.cpp
- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgText/FadeText.cpp (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgText/FadeText.cpp
r12597 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 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 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 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 26 26 _fadeText(fadeText), 27 27 _visible(true) {} 28 28 29 29 bool operator < (const FadeTextData& rhs) const 30 30 { 31 31 return _fadeText < rhs._fadeText; 32 } 33 32 } 33 34 34 double getNearestZ() const 35 35 { … … 59 59 _referenceVertexList.push_back(_vertices[3]); 60 60 } 61 61 62 62 void addEdgePlane(const osg::Vec3& corner, const osg::Vec3& edge) 63 63 { 64 64 osg::Vec3 normal( edge.y(), -edge.x(), 0.0f); 65 65 normal.normalize(); 66 66 67 67 add(osg::Plane(normal, corner)); 68 68 } 69 69 70 70 void buildPolytope() 71 71 { … … 83 83 add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[2], _vertices[3])); 84 84 add(osg::Plane( osg::Vec3d(0.0f,0.0f,0.0f), _vertices[3], _vertices[0])); 85 85 86 86 #if 0 87 87 OSG_NOTICE<<" normalFrontFace = "<<normalFrontFace<<std::endl; … … 96 96 if (needToFlip) flip(); 97 97 98 #if 0 98 #if 0 99 99 OSG_NOTICE<<" plane 0 "<< _planeList[0]<<std::endl; 100 100 OSG_NOTICE<<" plane 1 "<< _planeList[1]<<std::endl; … … 103 103 OSG_NOTICE<<" plane 4 "<< _planeList[4]<<std::endl; 104 104 #endif 105 106 } 107 105 106 } 107 108 108 inline bool contains(const std::vector<osg::Vec3>& vertices) 109 109 { … … 119 119 return false; 120 120 } 121 121 122 122 }; 123 123 … … 145 145 } 146 146 147 147 148 148 FadeTextUserData* createNewFadeTextUserData(osg::View* view) 149 149 { 150 150 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); 151 151 152 152 FadeTextUserData* userData = new FadeTextUserData; 153 153 … … 159 159 160 160 _viewMap[view].insert(userData); 161 161 162 162 return userData; 163 163 } 164 165 164 165 166 166 void update(unsigned int frameNumber) 167 167 { 168 168 _frameNumber = frameNumber; 169 169 170 170 for(GlobalFadeText::ViewUserDataMap::iterator vitr = _viewMap.begin(); 171 171 vitr != _viewMap.end(); 172 172 ++vitr) 173 173 { 174 174 175 175 osg::View* view = vitr->first; 176 176 … … 185 185 { 186 186 FadeTextUserData* userData = uitr->get(); 187 187 188 188 int frameDelta = frameNumber - userData->_frameNumber; 189 189 if (frameDelta<=1) … … 195 195 FadeTextData& fadeTextData = *fitr; 196 196 if (fadeTextSet.count(fadeTextData._fadeText)==0) 197 { 197 { 198 198 fadeTextSet.insert(fadeTextData._fadeText); 199 199 fadeTextPolytopeMap.insert(FadeTextPolytopeMap::value_type( … … 204 204 } 205 205 206 // for each FadeTexPoltopeData 206 // for each FadeTexPoltopeData 207 207 // create polytopes 208 208 // test against all FTPD's later in the list 209 209 // test all control points on FTPD against each plane of the current polytope 210 210 // if all control points removed or outside then discard FTPD and make FT visible = false; 211 212 FadeTextPolytopeMap::iterator outer_itr = fadeTextPolytopeMap.begin(); 213 while (outer_itr != fadeTextPolytopeMap.end()) 211 212 FadeTextPolytopeMap::iterator outer_itr = fadeTextPolytopeMap.begin(); 213 while (outer_itr != fadeTextPolytopeMap.end()) 214 214 { 215 215 FadeTextPolytopeMap::iterator inner_itr = outer_itr; … … 226 226 { 227 227 FadeTextPolytopeData& inner_ftpm = *(inner_itr->second); 228 228 229 229 // OSG_NOTICE<<"Inner z "<<inner_ftpm.getNearestZ()<<std::endl; 230 230 … … 234 234 // move to next ftpm 235 235 ++inner_itr; 236 236 237 237 fadeTextSet.erase(inner_ftpm._fadeText); 238 238 239 239 // need to remove inner_ftpm as its occluded. 240 240 fadeTextPolytopeMap.erase(erase_itr); 241 241 242 242 } 243 243 else … … 253 253 } 254 254 } 255 255 256 256 inline void updateIfRequired(unsigned int frameNumber) 257 257 { … … 279 279 osgText::FadeText* fadeText = dynamic_cast<osgText::FadeText*>(drawable); 280 280 if (!fadeText) return; 281 281 282 282 unsigned int frameNumber = nv->getFrameStamp()->getFrameNumber(); 283 283 284 284 GlobalFadeText* gft = getGlobalFadeText(); 285 285 gft->updateIfRequired(frameNumber); 286 286 287 287 osgText::FadeText::ViewBlendColourMap& vbcm = fadeText->getViewBlendColourMap(); 288 288 289 289 _ftd._fadeText = fadeText; 290 290 291 291 float fadeSpeed = fadeText->getFadeSpeed(); 292 292 … … 362 362 Text::drawImplementation(*renderInfo.getState(), osg::Vec4(1.0f,1.0f,1.0f,1.0f) ); 363 363 } 364 365 366 // now pass on new details 364 365 366 // now pass on new details 367 367 368 368 FadeTextUserData* userData = dynamic_cast<FadeTextUserData*>(renderInfo.getUserData()); … … 397 397 398 398 osgText::Text::AutoTransformCache& atc = _autoTransformCache[renderInfo.getContextID()]; 399 399 400 400 osg::Matrix lmv = atc._matrix; 401 401 lmv.postMult(state.getModelViewMatrix()); 402 402 403 403 if (renderInfo.getView() && renderInfo.getView()->getCamera()) 404 404 { … … 407 407 lmv.postMult(renderInfo.getView()->getCamera()->getViewMatrix()); 408 408 } 409 409 410 410 FadeTextData ftd(const_cast<osgText::FadeText*>(this)); 411 411 412 412 ftd._vertices[0].set(osg::Vec3d(_textBB.xMin(),_textBB.yMin(),_textBB.zMin())*lmv); 413 413 ftd._vertices[1].set(osg::Vec3d(_textBB.xMax(),_textBB.yMin(),_textBB.zMin())*lmv);
