void GlassLayer::draw(Graphics* const TheGraphics, const Pnt2f& TopLeft, const Pnt2f& BottomRight, const Real32 Opacity) const
{
    Pnt2f IntermediatePosition;
    Vec3f Bounds(BottomRight- TopLeft);
    
    //Setup the Blending equations properly
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);

    glBegin(GL_TRIANGLE_FAN);
        glColor4f(getEdgeColor().red(),getEdgeColor().green(),getEdgeColor().blue(),getEdgeColor().alpha() * Opacity);
        glVertex2f(getStartPosition().x(), getEndPosition().y());
        glColor4f(getCenterColor().red(),getCenterColor().green(),getCenterColor().blue(),getCenterColor().alpha() * Opacity);
        glVertex2fv(getStartPosition().getValues());
        for(UInt32 i(0) ; i<_Segments.size(); ++i)
        {
            IntermediatePosition.setValues(_Segments[i].x() * Bounds.x(),_Segments[i].y() * Bounds.y());
            glVertex2fv(IntermediatePosition.getValues());
        }
        glVertex2fv(getEndPosition().getValues());
    glEnd();

    glDisable(GL_BLEND);

}
Beispiel #2
0
void Data::OsgEdge::updateCoordinates( osg::Vec3 srcPos, osg::Vec3 dstPos )
{
	coordinates->clear();
	edgeTexCoords->clear();

	osg::Vec3d viewVec( 0, 0, 1 );
	osg::Vec3d up;

	if ( camera != 0 ) {
		osg::Vec3d eye;
		osg::Vec3d center;

		camera->getViewMatrixAsLookAt( eye,center,up );

		viewVec = eye - center;

		//	std::cout << eye.x() << " " << eye.y() << " " << eye.z() << "\n";
		//	std::cout << center.x() << " " << center.y() << " " << center.z() << "\n";
	}

	viewVec.normalize();

	//getting setting for edge scale

	osg::Vec3 x, y;
	x.set( srcPos );
	y.set( dstPos );

	osg::Vec3d edgeDir = x - y;
	length = edgeDir.length();

	up = edgeDir ^ viewVec;
	up.normalize();

	up *= this->scale;

	//updating edge coordinates due to scale
	coordinates->push_back( osg::Vec3d( x.x() + up.x(), x.y() + up.y(), x.z() + up.z() ) );
	coordinates->push_back( osg::Vec3d( x.x() - up.x(), x.y() - up.y(), x.z() - up.z() ) );
	coordinates->push_back( osg::Vec3d( y.x() - up.x(), y.y() - up.y(), y.z() - up.z() ) );
	coordinates->push_back( osg::Vec3d( y.x() + up.x(), y.y() + up.y(), y.z() + up.z() ) );

	float repeatCnt = static_cast<float>( length / ( 2.f * this->scale ) );

	//init edge-text (label) coordinates
	edgeTexCoords->push_back( osg::Vec2( 0,1.0f ) );
	edgeTexCoords->push_back( osg::Vec2( 0,0.0f ) );
	edgeTexCoords->push_back( osg::Vec2( repeatCnt,0.0f ) );
	edgeTexCoords->push_back( osg::Vec2( repeatCnt,1.0f ) );

	if ( label != NULL ) {
		label->setPosition( ( srcPos + dstPos ) / 2 );
	}
	osg::Geometry* geometry = NULL;
//	osg::Geometry* geometry = getDrawable( 0 )->asGeometry();
	if ( geometry != NULL ) {
		geometry->setVertexArray( coordinates );
		geometry->setTexCoordArray( 0, edgeTexCoords );

		osg::Vec4Array* colorArray =  dynamic_cast<osg::Vec4Array*>( geometry->getColorArray() );

		colorArray->pop_back();
		/*osg::Vec4f color;
		color.r()=getEdgeColor()[0];
		color.g()=getEdgeColor()[1];
		color.b()=getEdgeColor()[2];
		color.a()=getEdgeColor()[3];*/
		colorArray->push_back( getEdgeColor() );
	}
}