25 #include <osgText/Text>
26 #include <osg/LineWidth>
27 #include <osg/Geometry>
29 #include "../../WGraphicsEngine.h"
30 #include "../../WGECamera.h"
32 #include "WGEBorderLayout.h"
36 m_geode( new osg::Geode() ),
37 m_lineGeode( new osg::Geode() ),
38 m_screen( new osg::Projection() )
42 osg::ref_ptr< osg::MatrixTransform > matrix =
new osg::MatrixTransform();
43 setDataVariance( osg::Object::DYNAMIC );
44 matrix->setMatrix( osg::Matrix::identity() );
45 matrix->setReferenceFrame( osg::Transform::ABSOLUTE_RF );
51 m_geode->setDataVariance( osg::Object::DYNAMIC );
52 m_lineGeode->setDataVariance( osg::Object::DYNAMIC );
53 m_screen->setDataVariance( osg::Object::DYNAMIC );
58 getOrCreateStateSet()->setRenderBinDetails( 11,
"RenderBin" );
59 getOrCreateStateSet()->setDataVariance( osg::Object::DYNAMIC );
60 getOrCreateStateSet()->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF );
61 getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
79 unsigned int vwidth = cam->getViewport()->width();
80 unsigned int vheight = cam->getViewport()->height();
81 m_layouter->m_screen->setMatrix( osg::Matrix::ortho2D( 0, vwidth, 0, vheight ) );
84 osg::ref_ptr< osg::Vec3Array > v =
new osg::Vec3Array;
86 for(
unsigned int i = 0; i <
m_layouter->m_geode->getNumDrawables(); ++i )
89 osg::ref_ptr< WGELabel > t =
static_cast< WGELabel*
>(
m_layouter->m_geode->getDrawable( i ) );
92 osg::Vec4 anchor = osg::Vec4( t->getAnchor(), 1.0 );
93 osg::Matrixd projection = cam->getProjectionMatrix();
94 osg::Matrixd view = cam->getViewMatrix();
95 osg::Matrixd window = cam->getViewport()->computeWindowMatrix();
96 osg::Vec4 anchorScreen = anchor * view * projection * window;
104 if( anchorScreen.x() >= vwidth / 2 )
106 leadPos = osg::Vec3( vwidth - 10.0, anchorScreen.y(), 0.0 );
108 t->setPosition( osg::Vec3( vwidth - 10.0, anchorScreen.y() + 5, 0.0 ) );
109 t->setAlignment( osgText::Text::RIGHT_BOTTOM );
113 leadPos = osg::Vec3( 10.0, anchorScreen.y(), 0.0 );
115 t->setPosition( osg::Vec3( 10.0, anchorScreen.y() + 5, 0.0 ) );
116 t->setAlignment( osgText::Text::LEFT_BOTTOM );
119 v->push_back( leadPos );
120 v->push_back( osg::Vec3( anchorScreen.x(), anchorScreen.y(), anchorScreen.z() ) );
124 osg::ref_ptr< osg::Geometry > g =
new osg::Geometry;
125 g->setDataVariance( osg::Object::DYNAMIC );
126 osg::ref_ptr< osg::DrawArrays > da =
new osg::DrawArrays( osg::PrimitiveSet::LINES, 0, v->size() );
127 g->setVertexArray( v );
128 osg::ref_ptr< osg::Vec4Array > colors =
new osg::Vec4Array;
129 colors->push_back( osg::Vec4( 0.0f, 0.0f, 0.0f, 1.0f ) );
130 g->setColorArray( colors );
131 g->setColorBinding( osg::Geometry::BIND_OVERALL );
132 g->addPrimitiveSet( da );
134 osg::LineWidth* linewidth =
new osg::LineWidth();
135 linewidth->setWidth( 2.0f );
136 g->getOrCreateStateSet()->setAttributeAndModes( linewidth, osg::StateAttribute::ON );
142 traverse( node, nv );
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
operator () - called during the update traversal.
osg::ref_ptr< WGEBorderLayout > m_layouter
The layouter owning this callback.
WGEBorderLayout()
Default constructor.
virtual ~WGEBorderLayout()
Destructor.
osg::ref_ptr< osg::Projection > m_screen
The projection to the screen.
osg::ref_ptr< osg::Geode > m_lineGeode
Contains all lead lines.
friend class SafeUpdateCallback
Grant access for its inner class.
virtual void addLayoutable(osg::ref_ptr< WGELabel > obj)
Adds the specified object to the list of layouted objects.
osg::ref_ptr< osg::Geode > m_geode
The geode containing all drawables.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
void insert(osg::ref_ptr< osg::Node > node)
Adds the specified node to the child list of this node in a safe manner.
static std::shared_ptr< WGraphicsEngine > getGraphicsEngine()
Returns instance of the graphics engine.