CurveBrush/CurveDisplayer.cpp

#include "CurveDisplayer.h"
#include "CurveCreator.h"

#include <Mudbox/MudBoxGL.h>
#include <QtGui/QApplication>
#include <QtCore/QVector>

#include <float.h>

MB_PLUGIN( "CurveBrush", "Draw", "Autodesk", "http://www.mudbox3d.com", CurveDisplayer::Initializer );


IMPLEMENT_CLASS( CurveDisplayer, Node, "CurveDisplayer" );

CurveDisplayer* CurveDisplayer::s_pThis = 0;   

void CurveDisplayer::Initializer( void )
{
    MB_ADD_CONFIG2( CurveCreator, 0, NTR("Create Curve"), tr("Create Curve"), NTR("Curve Tools"), tr("Curve Tools"), tr("createCurveToolTip"));

    CurveDisplayer::s_pThis = CreateInstance<CurveDisplayer>(); 
};

CurveDisplayer::CurveDisplayer( void ) : m_eEndRender(this)
{
    m_eEndRender.Connect( Kernel()->EndRenderEvent );
};
void CurveDisplayer::OnEvent( const EventGate &e )
{
    if ( e == m_eEndRender )
    {
        QVector< Store<Vector>* >& lines = CurveCreator::Lines();

        glMatrixMode( GL_PROJECTION );

        // work around z-fighting, by bringing the curve closer to the eyepoint
        {
            Matrix m = Kernel()->Scene()->ActiveCamera()->Matrix();
            Matrix m2 = Kernel()->Scene()->ActiveCamera()->Transformation()->LocalToWorldMatrix();
            Matrix m3 = Kernel()->Scene()->ActiveCamera()->Transformation()->WorldToLocalMatrix();
            m = m2 * m;
            Matrix move;
            move.SetIdentity();
            move(3,2) = 0.4f;
            m = m3 * move * m;                                                 
            glLoadMatrixf( m );
        };

        glMatrixMode( GL_MODELVIEW );
        Matrix m;
        m.SetIdentity();
        glLoadMatrixf( m );
        Color c = Color::blue;
        glColor4f( 0,1,0,0.3f);

        // draw the lines
        for( unsigned int i = 0; i < lines.size(); ++i )
        {
            if(lines[i]->ItemCount() > 2 )
            {
                glBegin( GL_LINE_STRIP );
                for( unsigned int j = 0; j < lines[i]->ItemCount(); ++j )
                    glVertex3fv( lines[i]->operator[](j) );
                glEnd();
            };
        };
    };
};