//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : SceneAux.cpp Data : 25.02.14 Versione : 1.5b4 // Contenuto : Implementazione della gestione ausiliari della classe scena. // // // // Modifiche : 25.02.14 DS Creazione modulo. // // //---------------------------------------------------------------------------- //--------------------------- Include ---------------------------------------- #include "stdafx.h" #include "ObjOldGraphics.h" #include "ObjNewGraphics.h" #include "Scene.h" #include "GraphObjs.h" #include "/EgtDev/Include/EgtILogger.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGkFrame3d.h" #include "/EgtDev/Include/EgtPointerOwner.h" #include "/EgtDev/Include/EGkGdbIterator.h" #include "/EgtDev/Include/EGkCurve.h" using namespace std ; //------------------------------ Constants ----------------------------------- //---------------------------------------------------------------------------- bool Scene::SetWinRectAttribs( bool bOutline, Color WRcol) { m_bOutlineWR = bOutline ; m_colorWR = WRcol ; return true ; } //---------------------------------------------------------------------------- bool Scene::SetWinRect( const Point3d& ptWinRectP1, const Point3d& ptWinRectP2) { m_bWinRect = true ; m_ptWinRectP1 = ptWinRectP1 ; m_ptWinRectP2 = ptWinRectP2 ; return ( ! AreSamePointApprox( m_ptWinRectP1, m_ptWinRectP2)) ; } //---------------------------------------------------------------------------- bool Scene::ResetWinRect( void) { bool bOld = m_bWinRect ; m_bWinRect = false ; return bOld ; } //---------------------------------------------------------------------------- bool Scene::DrawWinRect( void) { // verifico sia da disegnare if ( ! m_bWinRect) return true ; // rendo neutre matrici di proiezione e di modello/vista glMatrixMode( GL_PROJECTION) ; glPushMatrix() ; glLoadIdentity() ; glMatrixMode( GL_MODELVIEW) ; glPushMatrix() ; glLoadIdentity() ; // recupero le dimensioni della viewport GLint vPort[ 4] ; glGetIntegerv( GL_VIEWPORT, vPort) ; // estremi del rettangolo nel riferimento Win ( 0,0 in alto a sinistra e Y verso il basso) double dWinXmin = __min( m_ptWinRectP1.x, m_ptWinRectP2.x) ; double dWinXmax = __max( m_ptWinRectP1.x, m_ptWinRectP2.x) ; double dWinYmin = __min( m_ptWinRectP1.y, m_ptWinRectP2.y) ; double dWinYmax = __max( m_ptWinRectP1.y, m_ptWinRectP2.y) ; // estremi del rettangolo nel riferimento View (0,0 in centro, quindi estremi -1,-1 e +1,+1 assi soliti) float dViewXmin = float( - 1 + 2 * ( 1 + dWinXmin) / ( vPort[2] + 1)) ; float dViewXmax = float( - 1 + 2 * ( 1 + dWinXmax) / ( vPort[2] + 1)) ; float dViewYmin = float( - 1 + 2 * ( vPort[3] - dWinYmax) / ( vPort[3] + 1)) ; float dViewYmax = float( - 1 + 2 * ( vPort[3] - dWinYmin) / ( vPort[3] + 1)) ; // eseguo il disegno del rettangolo if ( ! m_bNewWay) { if ( m_bOutlineWR) { glBegin( GL_LINE_LOOP) ; glColor3f( m_colorWR.GetRed(), m_colorWR.GetGreen(), m_colorWR.GetBlue()) ; glVertex3f( dViewXmin, dViewYmin, 0.5) ; glVertex3f( dViewXmax, dViewYmin, 0.5) ; glVertex3f( dViewXmax, dViewYmax, 0.5) ; glVertex3f( dViewXmin, dViewYmax, 0.5) ; glEnd() ; } else { glEnable( GL_BLEND) ; glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ; glBegin( GL_TRIANGLE_STRIP) ; glColor4f( m_colorWR.GetRed(), m_colorWR.GetGreen(), m_colorWR.GetBlue(), m_colorWR.GetAlpha()) ; glVertex3f( dViewXmin, dViewYmin, 0.5) ; glVertex3f( dViewXmax, dViewYmin, 0.5) ; glVertex3f( dViewXmin, dViewYmax, 0.5) ; glVertex3f( dViewXmax, dViewYmax, 0.5) ; glEnd() ; glDisable( GL_BLEND) ; } } else { // predispongo VAO e VBO usa e getta unsigned int nVaoId ; unsigned int nVboId ; // definizione glGenVertexArrays( 1, &nVaoId) ; if ( nVaoId == 0) return false ; glBindVertexArray( nVaoId) ; glGenBuffers( 1, &nVboId) ; glBindBuffer( GL_ARRAY_BUFFER, nVboId) ; glBufferData( GL_ARRAY_BUFFER, 4 * SIZEV3F, NULL, GL_STATIC_DRAW) ; glVertexPointer( 3, GL_FLOAT, SIZEV3F, ((void*)(0))) ; glEnableClientState( GL_VERTEX_ARRAY) ; // se contorno if ( m_bOutlineWR) { // assegno i vertici (ordine S) Vert3f v3V ; v3V.Set( dViewXmin, dViewYmin, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &v3V) ; v3V.Set( dViewXmax, dViewYmin, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &v3V) ; v3V.Set( dViewXmax, dViewYmax, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &v3V) ; v3V.Set( dViewXmin, dViewYmax, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &v3V) ; // imposto colore glColor3f( m_colorWR.GetRed(), m_colorWR.GetGreen(), m_colorWR.GetBlue()) ; // disegno glDrawArrays( GL_LINE_LOOP, 0, 4) ; } // altrimenti area else { // assegno i vertici (ordine S) Vert3f v3V ; v3V.Set( dViewXmin, dViewYmin, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 0 * SIZEV3F, SIZEV3F, &v3V) ; v3V.Set( dViewXmax, dViewYmin, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 1 * SIZEV3F, SIZEV3F, &v3V) ; v3V.Set( dViewXmin, dViewYmax, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 2 * SIZEV3F, SIZEV3F, &v3V) ; v3V.Set( dViewXmax, dViewYmax, 0.5) ; glBufferSubData( GL_ARRAY_BUFFER, 3 * SIZEV3F, SIZEV3F, &v3V) ; // imposto blending e colore glEnable( GL_BLEND) ; glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) ; glColor4f( m_colorWR.GetRed(), m_colorWR.GetGreen(), m_colorWR.GetBlue(), m_colorWR.GetAlpha()) ; // disegno glDrawArrays( GL_TRIANGLE_STRIP, 0, 4) ; // disabilito blending glDisable( GL_BLEND) ; } // cancello VAO e VBO glBindBuffer( GL_ARRAY_BUFFER, 0) ; glDeleteBuffers( 1, &nVboId) ; glBindVertexArray( 0) ; glDeleteVertexArrays( 1, &nVaoId) ; } // ripristino le matrici di proiezione e di modello/vista originali glMatrixMode( GL_PROJECTION) ; glPopMatrix() ; glMatrixMode( GL_MODELVIEW) ; glPopMatrix() ; return true ; }