Further work on Bound class/Node::getBound() and Drawable::getBound() and usage in OSG codebase
This commit is contained in:
@@ -303,7 +303,7 @@ bool DePee::createHUD()
|
||||
osg::BoundingBox bb;
|
||||
for(unsigned int i=0;i<geode->getNumDrawables();++i)
|
||||
{
|
||||
bb.expandBy(geode->getDrawable(i)->getBound());
|
||||
bb.expandBy(geode->getDrawable(i)->getBoundingBox());
|
||||
}
|
||||
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
|
||||
@@ -151,7 +151,7 @@ osg::Camera* createHUD()
|
||||
osg::BoundingBox bb;
|
||||
for(unsigned int i=0;i<geode->getNumDrawables();++i)
|
||||
{
|
||||
bb.expandBy(geode->getDrawable(i)->getBound());
|
||||
bb.expandBy(geode->getDrawable(i)->getBoundingBox());
|
||||
}
|
||||
|
||||
osg::Geometry* geom = new osg::Geometry;
|
||||
|
||||
@@ -82,7 +82,11 @@ public:
|
||||
// an attempt to return a reasonable bounding box. Still does not prevent clipping of the heat map.
|
||||
virtual const osg::BoundingBox& getBoundingBox() const {return m_bounds;}
|
||||
virtual osg::BoundingBox computeBoundingBox() const {return m_bounds;}
|
||||
#ifdef OSG_USE_BOUND
|
||||
virtual osg::Bound getBound() const { return osg::Bound(m_bounds, m_bounds); }
|
||||
#else
|
||||
virtual const osg::BoundingSphere& getBound() const {return m_bsphere;}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
osg::BoundingBox m_bounds;
|
||||
|
||||
@@ -44,13 +44,13 @@ public:
|
||||
{
|
||||
double timeStamp = nv->getFrameStamp()?nv->getFrameStamp()->getReferenceTime():0.0;
|
||||
unsigned int frameNumber = nv->getFrameStamp()?nv->getFrameStamp()->getFrameNumber():0;
|
||||
|
||||
|
||||
pagedLOD->setFrameNumberOfLastTraversal( frameNumber );
|
||||
pagedLOD->setTimeStamp( numChildren-1, timeStamp );
|
||||
pagedLOD->setFrameNumber( numChildren-1, frameNumber );
|
||||
pagedLOD->getChild(numChildren-1)->accept(*nv);
|
||||
}
|
||||
|
||||
|
||||
// Request for new child
|
||||
if ( !pagedLOD->getDisableExternalChildrenPaging() &&
|
||||
nv->getDatabaseRequestHandler() &&
|
||||
@@ -114,7 +114,7 @@ void PosterVisitor::apply( osg::PagedLOD& node )
|
||||
for ( unsigned int i=0; i<node.getNumFileNames(); ++i )
|
||||
{
|
||||
if ( node.getFileName(i).empty() ) continue;
|
||||
|
||||
|
||||
PagedNodeNameSet::iterator itr = _pagedNodeNames.find( node.getFileName(i) );
|
||||
if ( itr!=_pagedNodeNames.end() )
|
||||
{
|
||||
@@ -153,10 +153,10 @@ osgUtil::Intersector* PosterIntersector::clone( osgUtil::IntersectionVisitor& iv
|
||||
if ( iv.getProjectionMatrix() ) matrix.preMult( *iv.getProjectionMatrix() );
|
||||
if ( iv.getViewMatrix() ) matrix.preMult( *iv.getViewMatrix() );
|
||||
if ( iv.getModelMatrix() ) matrix.preMult( *iv.getModelMatrix() );
|
||||
|
||||
|
||||
osg::Polytope transformedPolytope;
|
||||
transformedPolytope.setAndTransformProvidingInverse( _polytope, matrix );
|
||||
|
||||
|
||||
osg::ref_ptr<PosterIntersector> pi = new PosterIntersector( transformedPolytope );
|
||||
pi->_intersectionVisitor = &iv;
|
||||
pi->_parent = this;
|
||||
@@ -187,9 +187,9 @@ void PosterIntersector::reset()
|
||||
|
||||
void PosterIntersector::intersect( osgUtil::IntersectionVisitor& iv, osg::Drawable* drawable )
|
||||
{
|
||||
if ( !_polytope.contains(drawable->getBound()) ) return;
|
||||
if ( !_polytope.contains(drawable->getBoundingBox()) ) return;
|
||||
if ( iv.getDoDummyTraversal() ) return;
|
||||
|
||||
|
||||
// Find and collect all paged LODs in the node path
|
||||
osg::NodePath& nodePath = iv.getNodePath();
|
||||
for ( osg::NodePath::iterator itr=nodePath.begin(); itr!=nodePath.end(); ++itr )
|
||||
@@ -208,7 +208,7 @@ void PosterIntersector::intersect( osgUtil::IntersectionVisitor& iv, osg::Drawab
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
/*osg::LOD* lod = dynamic_cast<osg::LOD*>(*itr);
|
||||
if ( lod )
|
||||
{
|
||||
@@ -258,7 +258,7 @@ void PosterPrinter::frame( const osg::FrameStamp* fs, osg::Node* node )
|
||||
// and advance frame when all callbacks are dispatched.
|
||||
if ( addCullCallbacks(fs, node) )
|
||||
return;
|
||||
|
||||
|
||||
if ( _isFinishing )
|
||||
{
|
||||
if ( (fs->getFrameNumber()-_lastBindingFrame)>2 )
|
||||
@@ -270,16 +270,16 @@ void PosterPrinter::frame( const osg::FrameStamp* fs, osg::Node* node )
|
||||
std::cout << "Writing final result to file..." << std::endl;
|
||||
osgDB::writeImageFile( *_finalPoster, _outputPosterName );
|
||||
}
|
||||
|
||||
|
||||
// Release all cull callbacks to free unused paged nodes
|
||||
removeCullCallbacks( node );
|
||||
_visitor->clearNames();
|
||||
|
||||
|
||||
_isFinishing = false;
|
||||
std::cout << "Recording images finished." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( _isRunning )
|
||||
{
|
||||
// Every "copy-to-image" process seems to be finished in 2 frames.
|
||||
@@ -288,11 +288,11 @@ void PosterPrinter::frame( const osg::FrameStamp* fs, osg::Node* node )
|
||||
{
|
||||
// Record images and unref them to free memory
|
||||
recordImages();
|
||||
|
||||
|
||||
// Release all cull callbacks to free unused paged nodes
|
||||
removeCullCallbacks( node );
|
||||
_visitor->clearNames();
|
||||
|
||||
|
||||
if ( _camera.valid() )
|
||||
{
|
||||
std::cout << "Binding sub-camera " << _currentRow << "_" << _currentColumn
|
||||
@@ -325,11 +325,11 @@ bool PosterPrinter::addCullCallbacks( const osg::FrameStamp* fs, osg::Node* node
|
||||
{
|
||||
if ( !_visitor->inQueue() || done() )
|
||||
return false;
|
||||
|
||||
|
||||
_visitor->setAddingCallbacks( true );
|
||||
_camera->accept( *_visitor );
|
||||
_lastBindingFrame = fs->getFrameNumber();
|
||||
|
||||
|
||||
std::cout << "Dispatching callbacks to paged nodes... "
|
||||
<< _visitor->inQueue() << std::endl;
|
||||
return true;
|
||||
@@ -345,19 +345,19 @@ void PosterPrinter::bindCameraToImage( osg::Camera* camera, int row, int col )
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << "image_" << row << "_" << col;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Image> image = new osg::Image;
|
||||
image->setName( stream.str() );
|
||||
image->allocateImage( (int)_tileSize.x(), (int)_tileSize.y(), 1, GL_RGBA, GL_UNSIGNED_BYTE );
|
||||
_images[TilePosition(row,col)] = image.get();
|
||||
|
||||
|
||||
// Calculate projection matrix offset of each tile
|
||||
osg::Matrix offsetMatrix =
|
||||
osg::Matrix::scale(_tileColumns, _tileRows, 1.0) *
|
||||
osg::Matrix::translate(_tileColumns-1-2*col, _tileRows-1-2*row, 0.0);
|
||||
camera->setViewMatrix( _currentViewMatrix );
|
||||
camera->setProjectionMatrix( _currentProjectionMatrix * offsetMatrix );
|
||||
|
||||
|
||||
// Check intersections between the image-tile box and the model
|
||||
osgUtil::IntersectionVisitor iv( _intersector.get() );
|
||||
iv.setReadCallback( g_pagedLoadingCallback.get() );
|
||||
@@ -368,7 +368,7 @@ void PosterPrinter::bindCameraToImage( osg::Camera* camera, int row, int col )
|
||||
// Apply a cull calback to every paged node obtained, to force the highest level displaying.
|
||||
// This will be done by the PosterVisitor, who already records all the paged nodes.
|
||||
}
|
||||
|
||||
|
||||
// Reattach cameras and new allocated images
|
||||
camera->setRenderingCache( NULL ); // FIXME: Uses for reattaching camera with image, maybe inefficient?
|
||||
camera->detach( osg::Camera::COLOR_BUFFER );
|
||||
@@ -391,7 +391,7 @@ void PosterPrinter::recordImages()
|
||||
memcpy( target, source, image->s() * 4 * sizeof(unsigned char) );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( _outputTiles )
|
||||
osgDB::writeImageFile( *image, image->getName()+"."+_outputTileExt );
|
||||
}
|
||||
|
||||
@@ -57,13 +57,13 @@ osg::Group* createHUDText()
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different text layout
|
||||
//
|
||||
|
||||
osg::Vec4 layoutColor(1.0f,1.0f,0.0f,1.0f);
|
||||
float layoutCharacterSize = 20.0f;
|
||||
|
||||
float layoutCharacterSize = 20.0f;
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
@@ -107,32 +107,32 @@ osg::Group* createHUDText()
|
||||
text->setText("text->setLayout(osgText::Text::VERTICAL);");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different font resolution
|
||||
//
|
||||
|
||||
osg::Vec4 fontSizeColor(0.0f,1.0f,1.0f,1.0f);
|
||||
float fontSizeCharacterSize = 30;
|
||||
|
||||
|
||||
osg::Vec3 cursor = osg::Vec3(margin*2,windowHeight-margin*2,0.0f);
|
||||
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
text->setColor(fontSizeColor);
|
||||
text->setCharacterSize(fontSizeCharacterSize);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that uses 10 by 10 texels as a target resolution for fonts.
|
||||
text->setFontResolution(10,10); // blocky but small texture memory usage
|
||||
|
||||
|
||||
text->setText("text->setFontResolution(10,10); // blocky but small texture memory usage");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
cursor.y() -= fontSizeCharacterSize;
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@@ -140,14 +140,14 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontSizeColor);
|
||||
text->setCharacterSize(fontSizeCharacterSize);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that uses 20 by 20 texels as a target resolution for fonts.
|
||||
text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low).
|
||||
|
||||
|
||||
text->setText("text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low).");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
cursor.y() -= fontSizeCharacterSize;
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@@ -155,38 +155,38 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontSizeColor);
|
||||
text->setCharacterSize(fontSizeCharacterSize);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that uses 40 by 40 texels as a target resolution for fonts.
|
||||
text->setFontResolution(40,40); // even smoother but again higher texture memory usage.
|
||||
|
||||
|
||||
text->setText("text->setFontResolution(40,40); // even smoother but again higher texture memory usage.");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different sized text
|
||||
//
|
||||
|
||||
osg::Vec4 characterSizeColor(1.0f,0.0f,1.0f,1.0f);
|
||||
|
||||
|
||||
cursor.y() -= fontSizeCharacterSize*2.0f;
|
||||
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
text->setColor(characterSizeColor);
|
||||
text->setFontResolution(20,20);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that is 20 units high.
|
||||
text->setCharacterSize(20); // small
|
||||
|
||||
|
||||
text->setText("text->setCharacterSize(20.0f); // small");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
cursor.y() -= 30.0f;
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@@ -194,14 +194,14 @@ osg::Group* createHUDText()
|
||||
text->setColor(characterSizeColor);
|
||||
text->setFontResolution(30,30);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that is 30 units high.
|
||||
text->setCharacterSize(30.0f); // medium
|
||||
|
||||
|
||||
text->setText("text->setCharacterSize(30.0f); // medium");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
cursor.y() -= 50.0f;
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@@ -209,17 +209,17 @@ osg::Group* createHUDText()
|
||||
text->setColor(characterSizeColor);
|
||||
text->setFontResolution(40,40);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that is 60 units high.
|
||||
text->setCharacterSize(60.0f); // large
|
||||
|
||||
|
||||
text->setText("text->setCharacterSize(60.0f); // large");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different alignments
|
||||
//
|
||||
|
||||
@@ -227,7 +227,7 @@ osg::Group* createHUDText()
|
||||
float alignmentCharacterSize = 25.0f;
|
||||
cursor.x() = 640;
|
||||
cursor.y() = margin*4.0f;
|
||||
|
||||
|
||||
typedef std::pair<osgText::Text::AlignmentType,std::string> AlignmentPair;
|
||||
typedef std::vector<AlignmentPair> AlignmentList;
|
||||
AlignmentList alignmentList;
|
||||
@@ -264,49 +264,49 @@ osg::Group* createHUDText()
|
||||
text->setCharacterSize(alignmentCharacterSize);
|
||||
text->setPosition(cursor);
|
||||
text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX);
|
||||
|
||||
|
||||
text->setAlignment(itr->first);
|
||||
text->setText(itr->second);
|
||||
|
||||
|
||||
alignmentGeode->addDrawable(text);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
sequence->setMode(osg::Sequence::START);
|
||||
sequence->setInterval(osg::Sequence::LOOP, 0, -1);
|
||||
sequence->setDuration(1.0f, -1);
|
||||
|
||||
|
||||
rootNode->addChild(sequence);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different fonts...
|
||||
//
|
||||
|
||||
cursor.x() = margin*2.0f;
|
||||
cursor.y() = margin*2.0f;
|
||||
|
||||
|
||||
osg::Vec4 fontColor(1.0f,0.5f,0.0f,1.0f);
|
||||
float fontCharacterSize = 20.0f;
|
||||
float spacing = 40.0f;
|
||||
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
text->setFont(0);
|
||||
text->setText("text->setFont(0); // inbuilt font.");
|
||||
geode->addDrawable(text);
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
osgText::Font* arial = new osgText::Font(new osgQt::QFontImplementation(QFont("Arial")));
|
||||
|
||||
@@ -314,16 +314,16 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
text->setFont(arial);
|
||||
text->setText(arial!=0?
|
||||
"text->setFont(\"fonts/arial.ttf\");":
|
||||
"unable to load \"fonts/arial.ttf\"");
|
||||
geode->addDrawable(text);
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
osgText::Font* times = new osgText::Font(new osgQt::QFontImplementation(QFont("Times")));
|
||||
|
||||
@@ -331,16 +331,16 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
geode->addDrawable(text);
|
||||
text->setFont(times);
|
||||
text->setText(times!=0?
|
||||
"text->setFont(\"fonts/times.ttf\");":
|
||||
"unable to load \"fonts/times.ttf\"");
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
|
||||
cursor.x() = margin*2.0f;
|
||||
cursor.y() = margin;
|
||||
|
||||
@@ -351,34 +351,34 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
text->setFont(dirtydoz);
|
||||
text->setText(dirtydoz!=0?
|
||||
"text->setFont(\"fonts/dirtydoz.ttf\");":
|
||||
"unable to load \"fonts/dirtydoz.ttf\"");
|
||||
geode->addDrawable(text);
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
osgText::Font* fudd = new osgText::Font(new osgQt::QFontImplementation(QFont("Times")));
|
||||
|
||||
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
text->setFont(fudd);
|
||||
text->setText(fudd!=0?
|
||||
"text->setFont(\"fonts/fudd.ttf\");":
|
||||
"unable to load \"fonts/fudd.ttf\"");
|
||||
geode->addDrawable(text);
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
return rootNode;
|
||||
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
|
||||
@@ -391,12 +391,12 @@ osg::Group* create3DText(const osg::Vec3& center,float radius)
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up axis/orientation alignments
|
||||
//
|
||||
|
||||
float characterSize=radius*0.2f;
|
||||
|
||||
|
||||
osg::Vec3 pos(center.x()-radius*.5f,center.y()-radius*.5f,center.z()-radius*.5f);
|
||||
|
||||
osgText::Text* text1 = new osgText::Text;
|
||||
@@ -479,7 +479,7 @@ osg::Group* create3DText(const osg::Vec3& center,float radius)
|
||||
osg::Group* rootNode = new osg::Group;
|
||||
rootNode->addChild(geode);
|
||||
|
||||
return rootNode;
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
class MainWindow : public QWidget {
|
||||
@@ -535,7 +535,7 @@ int main(int argc, char** argv)
|
||||
// prepare scene.
|
||||
osg::Vec3 center(0.0f,0.0f,0.0f);
|
||||
float radius = 1.0f;
|
||||
|
||||
|
||||
// create the hud.
|
||||
osg::ref_ptr<osg::Camera> camera = new osg::Camera;
|
||||
camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
|
||||
@@ -544,7 +544,7 @@ int main(int argc, char** argv)
|
||||
camera->setClearMask(GL_DEPTH_BUFFER_BIT);
|
||||
camera->addChild(createHUDText());
|
||||
camera->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF);
|
||||
|
||||
|
||||
// make sure the root node is group so we can add extra nodes to it.
|
||||
osg::ref_ptr<osg::Group> group = new osg::Group;
|
||||
group->addChild(camera.get());
|
||||
@@ -552,7 +552,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// The qt window
|
||||
MainWindow widget;
|
||||
|
||||
|
||||
// set the scene to render
|
||||
widget.setSceneData(group.get());
|
||||
widget.setCameraManipulator(new osgGA::TrackballManipulator);
|
||||
|
||||
@@ -53,13 +53,13 @@ osg::Group* createHUDText()
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different text layout
|
||||
//
|
||||
|
||||
osg::Vec4 layoutColor(1.0f,1.0f,0.0f,1.0f);
|
||||
float layoutCharacterSize = 20.0f;
|
||||
|
||||
float layoutCharacterSize = 20.0f;
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
@@ -103,32 +103,32 @@ osg::Group* createHUDText()
|
||||
text->setText("text->setLayout(osgText::Text::VERTICAL);");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different font resolution
|
||||
//
|
||||
|
||||
osg::Vec4 fontSizeColor(0.0f,1.0f,1.0f,1.0f);
|
||||
float fontSizeCharacterSize = 30;
|
||||
|
||||
|
||||
osg::Vec3 cursor = osg::Vec3(margin*2,windowHeight-margin*2,0.0f);
|
||||
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
text->setColor(fontSizeColor);
|
||||
text->setCharacterSize(fontSizeCharacterSize);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that uses 10 by 10 texels as a target resolution for fonts.
|
||||
text->setFontResolution(10,10); // blocky but small texture memory usage
|
||||
|
||||
|
||||
text->setText("text->setFontResolution(10,10); // blocky but small texture memory usage");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
cursor.y() -= fontSizeCharacterSize;
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@@ -136,14 +136,14 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontSizeColor);
|
||||
text->setCharacterSize(fontSizeCharacterSize);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that uses 20 by 20 texels as a target resolution for fonts.
|
||||
text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low).
|
||||
|
||||
|
||||
text->setText("text->setFontResolution(20,20); // smoother but higher texture memory usage (but still quite low).");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
cursor.y() -= fontSizeCharacterSize;
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@@ -151,38 +151,38 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontSizeColor);
|
||||
text->setCharacterSize(fontSizeCharacterSize);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that uses 40 by 40 texels as a target resolution for fonts.
|
||||
text->setFontResolution(40,40); // even smoother but again higher texture memory usage.
|
||||
|
||||
|
||||
text->setText("text->setFontResolution(40,40); // even smoother but again higher texture memory usage.");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different sized text
|
||||
//
|
||||
|
||||
osg::Vec4 characterSizeColor(1.0f,0.0f,1.0f,1.0f);
|
||||
|
||||
|
||||
cursor.y() -= fontSizeCharacterSize*2.0f;
|
||||
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setFont(font);
|
||||
text->setColor(characterSizeColor);
|
||||
text->setFontResolution(20,20);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that is 20 units high.
|
||||
text->setCharacterSize(20); // small
|
||||
|
||||
|
||||
text->setText("text->setCharacterSize(20.0f); // small");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
cursor.y() -= 30.0f;
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@@ -190,14 +190,14 @@ osg::Group* createHUDText()
|
||||
text->setColor(characterSizeColor);
|
||||
text->setFontResolution(30,30);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that is 30 units high.
|
||||
text->setCharacterSize(30.0f); // medium
|
||||
|
||||
|
||||
text->setText("text->setCharacterSize(30.0f); // medium");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
cursor.y() -= 50.0f;
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
@@ -205,17 +205,17 @@ osg::Group* createHUDText()
|
||||
text->setColor(characterSizeColor);
|
||||
text->setFontResolution(40,40);
|
||||
text->setPosition(cursor);
|
||||
|
||||
|
||||
// use text that is 60 units high.
|
||||
text->setCharacterSize(60.0f); // large
|
||||
|
||||
|
||||
text->setText("text->setCharacterSize(60.0f); // large");
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different alignments
|
||||
//
|
||||
|
||||
@@ -223,7 +223,7 @@ osg::Group* createHUDText()
|
||||
float alignmentCharacterSize = 25.0f;
|
||||
cursor.x() = 640;
|
||||
cursor.y() = margin*4.0f;
|
||||
|
||||
|
||||
typedef std::pair<osgText::Text::AlignmentType,std::string> AlignmentPair;
|
||||
typedef std::vector<AlignmentPair> AlignmentList;
|
||||
AlignmentList alignmentList;
|
||||
@@ -260,49 +260,49 @@ osg::Group* createHUDText()
|
||||
text->setCharacterSize(alignmentCharacterSize);
|
||||
text->setPosition(cursor);
|
||||
text->setDrawMode(osgText::Text::TEXT|osgText::Text::ALIGNMENT|osgText::Text::BOUNDINGBOX);
|
||||
|
||||
|
||||
text->setAlignment(itr->first);
|
||||
text->setText(itr->second);
|
||||
|
||||
|
||||
alignmentGeode->addDrawable(text);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
sequence->setMode(osg::Sequence::START);
|
||||
sequence->setInterval(osg::Sequence::LOOP, 0, -1);
|
||||
sequence->setDuration(1.0f, -1);
|
||||
|
||||
|
||||
rootNode->addChild(sequence);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up different fonts...
|
||||
//
|
||||
|
||||
cursor.x() = margin*2.0f;
|
||||
cursor.y() = margin*2.0f;
|
||||
|
||||
|
||||
osg::Vec4 fontColor(1.0f,0.5f,0.0f,1.0f);
|
||||
float fontCharacterSize = 20.0f;
|
||||
float spacing = 40.0f;
|
||||
|
||||
|
||||
{
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
text->setFont(0);
|
||||
text->setText("text->setFont(0); // inbuilt font.");
|
||||
geode->addDrawable(text);
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
osgText::Font* arial = osgText::readFontFile("fonts/arial.ttf");
|
||||
|
||||
@@ -310,16 +310,16 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
text->setFont(arial);
|
||||
text->setText(arial!=0?
|
||||
"text->setFont(\"fonts/arial.ttf\");":
|
||||
"unable to load \"fonts/arial.ttf\"");
|
||||
geode->addDrawable(text);
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
osgText::Font* times = osgText::readFontFile("fonts/times.ttf");
|
||||
|
||||
@@ -327,16 +327,16 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
geode->addDrawable(text);
|
||||
text->setFont(times);
|
||||
text->setText(times!=0?
|
||||
"text->setFont(\"fonts/times.ttf\");":
|
||||
"unable to load \"fonts/times.ttf\"");
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
|
||||
cursor.x() = margin*2.0f;
|
||||
cursor.y() = margin;
|
||||
|
||||
@@ -347,34 +347,34 @@ osg::Group* createHUDText()
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
text->setFont(dirtydoz);
|
||||
text->setText(dirtydoz!=0?
|
||||
"text->setFont(\"fonts/dirtydoz.ttf\");":
|
||||
"unable to load \"fonts/dirtydoz.ttf\"");
|
||||
geode->addDrawable(text);
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
osgText::Font* fudd = osgText::readFontFile("fonts/fudd.ttf");
|
||||
|
||||
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setColor(fontColor);
|
||||
text->setPosition(cursor);
|
||||
text->setCharacterSize(fontCharacterSize);
|
||||
|
||||
|
||||
text->setFont(fudd);
|
||||
text->setText(fudd!=0?
|
||||
"text->setFont(\"fonts/fudd.ttf\");":
|
||||
"unable to load \"fonts/fudd.ttf\"");
|
||||
geode->addDrawable(text);
|
||||
|
||||
cursor.x() = text->getBound().xMax() + spacing ;
|
||||
cursor.x() = text->getBoundingBox().xMax() + spacing ;
|
||||
}
|
||||
|
||||
return rootNode;
|
||||
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
|
||||
@@ -386,9 +386,9 @@ osg::Group* create3DText(const osg::Vec3& center,float radius)
|
||||
|
||||
osg::Geode* geode = new osg::Geode;
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
//
|
||||
// Examples of how to set up axis/orientation alignments
|
||||
//
|
||||
|
||||
@@ -477,14 +477,14 @@ osg::Group* create3DText(const osg::Vec3& center,float radius)
|
||||
osg::Group* rootNode = new osg::Group;
|
||||
rootNode->addChild(geode);
|
||||
|
||||
return rootNode;
|
||||
return rootNode;
|
||||
}
|
||||
|
||||
class UpdateTextOperation : public osg::Operation
|
||||
{
|
||||
public:
|
||||
|
||||
UpdateTextOperation(const osg::Vec3& center, float diameter, osg::Group* group):
|
||||
UpdateTextOperation(const osg::Vec3& center, float diameter, osg::Group* group):
|
||||
Operation("UpdateTextOperation", true),
|
||||
_center(center),
|
||||
_diameter(diameter),
|
||||
@@ -502,13 +502,13 @@ public:
|
||||
if (viewer) update();
|
||||
else load();
|
||||
}
|
||||
|
||||
|
||||
void update()
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"*** Doing update"<<std::endl;
|
||||
|
||||
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
|
||||
|
||||
if (_mergeSubgraph.valid())
|
||||
{
|
||||
_group->addChild(_mergeSubgraph.get());
|
||||
@@ -525,14 +525,14 @@ public:
|
||||
}
|
||||
_group->removeChild(0,1);
|
||||
}
|
||||
|
||||
|
||||
_waitOnMergeBlock.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void load()
|
||||
{
|
||||
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"Doing load"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osg::Geode> geode;
|
||||
@@ -544,7 +544,7 @@ public:
|
||||
_availableSubgraph.pop_front();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!geode) geode = new osg::Geode;
|
||||
|
||||
for(unsigned int i=0; i<_maxNumTextPerGeode; ++i)
|
||||
@@ -560,7 +560,7 @@ public:
|
||||
{
|
||||
str.push_back(char(32.0 + (float(rand())/float(RAND_MAX))*128.0f));
|
||||
}
|
||||
|
||||
|
||||
osgText::Text* text = new osgText::Text;
|
||||
text->setDataVariance(osg::Object::DYNAMIC);
|
||||
text->setPosition(_center + position * _diameter);
|
||||
@@ -568,22 +568,22 @@ public:
|
||||
text->setText(str);
|
||||
text->setCharacterSize(0.025f * _diameter);
|
||||
text->setAxisAlignment(osgText::Text::SCREEN);
|
||||
|
||||
|
||||
geode->addDrawable(text);
|
||||
}
|
||||
|
||||
|
||||
{
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
|
||||
_mergeSubgraph = geode;
|
||||
}
|
||||
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"Waiting on merge"<<std::endl;
|
||||
|
||||
_waitOnMergeBlock.block();
|
||||
|
||||
}
|
||||
|
||||
|
||||
virtual void release()
|
||||
{
|
||||
_waitOnMergeBlock.release();
|
||||
@@ -595,13 +595,13 @@ public:
|
||||
float _diameter;
|
||||
unsigned int _maxNumChildren;
|
||||
unsigned int _maxNumTextPerGeode;
|
||||
|
||||
|
||||
OpenThreads::Mutex _mutex;
|
||||
osg::ref_ptr<osg::Group> _group;
|
||||
osg::ref_ptr<osg::Geode> _mergeSubgraph;
|
||||
AvailableList _availableSubgraph;
|
||||
OpenThreads::Block _waitOnMergeBlock;
|
||||
|
||||
|
||||
unsigned int _counter;
|
||||
|
||||
};
|
||||
@@ -613,7 +613,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// construct the viewer.
|
||||
osgViewer::Viewer viewer(arguments);
|
||||
|
||||
|
||||
typedef std::list< osg::ref_ptr<osg::OperationThread> > Threads;
|
||||
|
||||
Threads operationThreads;
|
||||
@@ -624,22 +624,22 @@ int main(int argc, char** argv)
|
||||
{
|
||||
// construct a multi-threaded text updating test.
|
||||
if (numThreads==0) numThreads = 1;
|
||||
|
||||
|
||||
// create a group to add everything into.
|
||||
osg::Group* mainGroup = new osg::Group;
|
||||
|
||||
|
||||
osg::Vec3 center(0.5f,0.5f,0.5f);
|
||||
float diameter = 1.0f;
|
||||
|
||||
|
||||
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFiles(arguments);
|
||||
if (loadedModel.valid())
|
||||
{
|
||||
mainGroup->addChild(loadedModel.get());
|
||||
|
||||
|
||||
center = loadedModel->getBound().center();
|
||||
diameter = loadedModel->getBound().radius() * 2.0f;
|
||||
}
|
||||
|
||||
|
||||
for(unsigned int i=0; i<numThreads; ++i)
|
||||
{
|
||||
osg::Group* textGroup = new osg::Group;
|
||||
@@ -647,7 +647,7 @@ int main(int argc, char** argv)
|
||||
|
||||
// create the background thread
|
||||
osg::OperationThread* operationThread = new osg::OperationThread;
|
||||
|
||||
|
||||
operationThreads.push_back(operationThread);
|
||||
|
||||
// create the operation that will run in the background and
|
||||
@@ -669,15 +669,15 @@ int main(int argc, char** argv)
|
||||
|
||||
mainGroup->addChild(geode);
|
||||
}
|
||||
|
||||
viewer.setSceneData(mainGroup);
|
||||
|
||||
viewer.setSceneData(mainGroup);
|
||||
}
|
||||
else
|
||||
{
|
||||
// prepare scene.
|
||||
osg::Vec3 center(0.0f,0.0f,0.0f);
|
||||
float radius = 1.0f;
|
||||
|
||||
|
||||
// make sure the root node is group so we can add extra nodes to it.
|
||||
osg::Group* group = new osg::Group;
|
||||
|
||||
@@ -715,7 +715,7 @@ int main(int argc, char** argv)
|
||||
viewer.addEventHandler(new osgViewer::StatsHandler());
|
||||
|
||||
viewer.run();
|
||||
|
||||
|
||||
if (!operationThreads.empty())
|
||||
{
|
||||
for(Threads::iterator itr = operationThreads.begin();
|
||||
|
||||
Reference in New Issue
Block a user