25 #include <osgText/Text>
26 #include <osg/LineWidth>
28 #include "../../WGraphicsEngine.h"
30 #include "WGEBorderLayout.h"
34 m_geode( new osg::
Geode() ),
35 m_lineGeode( new osg::
Geode() ),
40 osg::ref_ptr< osg::MatrixTransform > matrix =
new osg::MatrixTransform();
41 setDataVariance( osg::Object::DYNAMIC );
42 matrix->setMatrix( osg::Matrix::identity() );
43 matrix->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
49 m_geode->setDataVariance( osg::Object::DYNAMIC );
50 m_lineGeode->setDataVariance( osg::Object::DYNAMIC );
51 m_screen->setDataVariance( osg::Object::DYNAMIC );
56 getOrCreateStateSet()->setRenderBinDetails( 11,
"RenderBin" );
57 getOrCreateStateSet()->setDataVariance( osg::Object::DYNAMIC );
58 getOrCreateStateSet()->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
59 getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
77 unsigned int vwidth = cam->getViewport()->width();
78 unsigned int vheight = cam->getViewport()->height();
79 m_layouter->m_screen->setMatrix( osg::Matrix::ortho2D( 0, vwidth, 0, vheight ) );
82 osg::ref_ptr< osg::Vec3Array > v =
new osg::Vec3Array;
84 for(
unsigned int i = 0; i <
m_layouter->m_geode->getNumDrawables(); ++i )
87 osg::ref_ptr< WGELabel > t =
static_cast< WGELabel*
>(
m_layouter->m_geode->getDrawable( i ) );
90 osg::Vec4 anchor = osg::Vec4( t->getAnchor(), 1.0 );
91 osg::Matrixd projection = cam->getProjectionMatrix();
92 osg::Matrixd view = cam->getViewMatrix();
93 osg::Matrixd window = cam->getViewport()->computeWindowMatrix();
94 osg::Vec4 anchorScreen = anchor * view * projection * window;
102 if( anchorScreen.x() >= vwidth / 2 )
104 leadPos = osg::Vec3( vwidth - 10.0, anchorScreen.y(), 0.0 );
106 t->setPosition( osg::Vec3( vwidth - 10.0, anchorScreen.y() + 5, 0.0 ) );
107 t->setAlignment( osgText::Text::RIGHT_BOTTOM );
111 leadPos = osg::Vec3( 10.0, anchorScreen.y(), 0.0 );
113 t->setPosition( osg::Vec3( 10.0, anchorScreen.y() + 5, 0.0 ) );
114 t->setAlignment( osgText::Text::LEFT_BOTTOM );
117 v->push_back( leadPos );
118 v->push_back( osg::Vec3( anchorScreen.x(), anchorScreen.y(), anchorScreen.z() ) );
122 osg::ref_ptr< osg::Geometry > g =
new osg::Geometry;
123 g->setDataVariance( osg::Object::DYNAMIC );
124 osg::ref_ptr< osg::DrawArrays > da =
new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, v->size() );
125 g->setVertexArray( v );
126 osg::ref_ptr< osg::Vec4Array > colors =
new osg::Vec4Array;
127 colors->push_back( osg::Vec4( 0.0f, 0.0f, 0.0f, 1.0f ) );
128 g->setColorArray( colors );
129 g->setColorBinding( osg::Geometry::BIND_OVERALL );
130 g->addPrimitiveSet( da );
132 osg::LineWidth* linewidth =
new osg::LineWidth();
133 linewidth->setWidth( 2.0f );
134 g->getOrCreateStateSet()->setAttributeAndModes( linewidth, osg::StateAttribute::ON );
140 traverse( node, nv );