diff --git a/EgtGraphics.rc b/EgtGraphics.rc index d41b977..cf4882b 100644 Binary files a/EgtGraphics.rc and b/EgtGraphics.rc differ diff --git a/ObjEGrGraphics.h b/ObjEGrGraphics.h index 8d6fdff..8e3af39 100644 --- a/ObjEGrGraphics.h +++ b/ObjEGrGraphics.h @@ -31,6 +31,8 @@ class ObjEGrGraphics : public IObjGraphics virtual Scene* GetScene( void) = 0 ; virtual void Clear( void) = 0 ; virtual bool AddColor( const Color& colC) = 0 ; + virtual bool AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec) = 0 ; + virtual bool AddBackMaterial( const Color& colAmbDiff) = 0 ; virtual bool AddPoint( const Point3d& ptP) = 0 ; virtual bool AddPolyLine( const PolyLine& PL) = 0 ; virtual bool StartTriangles( int nNum) = 0 ; diff --git a/ObjNewGraphics.cpp b/ObjNewGraphics.cpp index 9a0729b..d08b810 100644 --- a/ObjNewGraphics.cpp +++ b/ObjNewGraphics.cpp @@ -1,13 +1,13 @@ //---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- -// File : ObjNewGraphics.cpp Data : 10.02.14 Versione : 1.5b1 +// File : ObjNewGraphics.cpp Data : 23.04.14 Versione : 1.5d5 // Contenuto : Implementazione della classe grafica di un oggetto geometrico. // // // // Modifiche : 10.02.14 DS Creazione modulo. -// +// 23.04.14 DS Agg. gestione materiali. // //---------------------------------------------------------------------------- @@ -57,6 +57,27 @@ ObjNewGraphics::AddColor( const Color& colC) return AddColor( colC.GetRed(), colC.GetGreen(), colC.GetBlue(), colC.GetAlpha()) ; } +//---------------------------------------------------------------------------- +bool +ObjNewGraphics::AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec) +{ + return AddMaterial( NgAtom::MAT_A, colAmb.GetRed(), colAmb.GetGreen(), + colAmb.GetBlue(), colDiff.GetAlpha()) && + AddMaterial( NgAtom::MAT_D, colDiff.GetRed(), colDiff.GetGreen(), + colDiff.GetBlue(), colDiff.GetAlpha()) && + AddMaterial( NgAtom::MAT_S, colSpec.GetRed(), colSpec.GetGreen(), + colSpec.GetBlue(), colDiff.GetAlpha()) && + AddMaterial( NgAtom::MAT_SH, 128 * colSpec.GetAlpha(), 0, 0, 0) ; +} + +//---------------------------------------------------------------------------- +bool +ObjNewGraphics::AddBackMaterial( const Color& colAmbDiff) +{ + return AddMaterial( NgAtom::MAT_B, colAmbDiff.GetRed(), colAmbDiff.GetGreen(), + colAmbDiff.GetBlue(), colAmbDiff.GetAlpha()) ; +} + //---------------------------------------------------------------------------- bool ObjNewGraphics::AddPoint( const Point3d& ptP) @@ -234,15 +255,30 @@ ObjNewGraphics::Draw( int nStat, int nMark) NGALIST::iterator iIter ; for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) { switch ( iIter->m_nType) { - case NewGrAtom::VERTS : + case NgAtom::VERTS : if ( iIter->m_nCount > 0 && iIter->m_nVaoId != 0) { glBindVertexArray( iIter->m_nVaoId) ; glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ; glBindVertexArray( 0) ; } break ; - case NewGrAtom::COLOR : - glColor4f( iIter->m_fRed, iIter->m_fGreen, iIter->m_fBlue, iIter->m_fAlpha) ; + case NgAtom::COLOR : + glColor4fv( iIter->m_fCol) ; + break ; + case NgAtom::MAT_A : + glMaterialfv( GL_FRONT, GL_AMBIENT, iIter->m_fCol) ; + break ; + case NgAtom::MAT_D : + glMaterialfv( GL_FRONT, GL_DIFFUSE, iIter->m_fCol) ; + break ; + case NgAtom::MAT_S : + glMaterialfv( GL_FRONT, GL_SPECULAR, iIter->m_fCol) ; + break ; + case NgAtom::MAT_SH : + glMaterialf( GL_FRONT, GL_SHININESS, iIter->m_fCol[0]) ; + break ; + case NgAtom::MAT_B : + glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, iIter->m_fCol) ; break ; } } @@ -261,16 +297,14 @@ ObjNewGraphics::Draw( int nStat, int nMark) NGALIST::iterator iIter ; for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) { switch ( iIter->m_nType) { - case NewGrAtom::VERTS : + case NgAtom::VERTS : if ( iIter->m_nCount > 0 && iIter->m_nVaoId != 0) { glBindVertexArray( iIter->m_nVaoId) ; glDrawArrays( iIter->m_nMode, 0, iIter->m_nCount) ; glBindVertexArray( 0) ; } break ; - case NewGrAtom::COLOR : - // si usa il colore di marcatura - break ; + // non si impostano i colori, si usa quello di marcatura } } } @@ -294,7 +328,7 @@ ObjNewGraphics::DeleteVaoVbo( void) // ciclo di cancellazione VAO/VBO NGALIST::iterator iIter ; for ( iIter = m_ngaList.begin() ; iIter != m_ngaList.end() ; ++ iIter) { - if ( iIter->m_nType == NewGrAtom::VERTS && iIter->m_nCount > 0) { + if ( iIter->m_nType == NgAtom::VERTS && iIter->m_nCount > 0) { glBindBuffer( GL_ARRAY_BUFFER, 0) ; glDeleteBuffers( 1, &iIter->m_nVboId) ; glBindVertexArray( 0) ; diff --git a/ObjNewGraphics.h b/ObjNewGraphics.h index 19025bf..fd5376e 100644 --- a/ObjNewGraphics.h +++ b/ObjNewGraphics.h @@ -18,37 +18,36 @@ //---------------------------------------------------------------------------- -// Definizione di NewGrAtom -class NewGrAtom { +// Definizione di NgAtom +class NgAtom { public : - NewGrAtom( void) : m_nType( NONE), m_nMode( 0), m_nCount( 0), m_nVaoId( 0), m_nVboId( 0) {} + NgAtom( void) : m_nType( NONE), m_nMode( 0), m_nCount( 0), m_nVaoId( 0), m_nVboId( 0) {} public : - enum GrType { NONE = 0, VERTS = 1, COLOR = 2} ; + enum GrType { NONE = 0, VERTS = 1, COLOR = 2, MAT_A = 3, MAT_D = 4, MAT_S = 5, MAT_SH = 6, MAT_B = 7} ; public : GrType m_nType ; union { - int m_nMode ; - float m_fRed ; - } ; - union { - int m_nCount ; - float m_fGreen ; - } ; - union { - unsigned int m_nVaoId ; - float m_fBlue ; - } ; - union { - unsigned int m_nVboId ; - float m_fAlpha ; + struct { + int m_nMode ; + int m_nCount ; + unsigned int m_nVaoId ; + unsigned int m_nVboId ; + } ; + struct { + float m_fRed ; + float m_fGreen ; + float m_fBlue ; + float m_fAlpha ; + } ; + float m_fCol[4] ; } ; } ; //---------------------------------------------------------------------------- -// Lista di NewGrAtom -typedef std::list NGALIST ; +// Lista di NgAtom +typedef std::list NGALIST ; //---------------------------------------------------------------------------- @@ -67,6 +66,8 @@ class ObjNewGraphics : public ObjEGrGraphics { return m_pScene ; } virtual void Clear( void) ; virtual bool AddColor( const Color& colC) ; + virtual bool AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec) ; + virtual bool AddBackMaterial( const Color& colAmbDiff) ; virtual bool AddPoint( const Point3d& ptP) ; virtual bool AddPolyLine( const PolyLine& PL) ; virtual bool StartTriangles( int nNum) ; @@ -79,21 +80,26 @@ class ObjNewGraphics : public ObjEGrGraphics private : bool DeleteVaoVbo( void) ; - bool AddNewGrAtom( const NewGrAtom& nga) + bool AddNgAtom( const NgAtom& nga) { try { m_ngaList.push_back( nga) ; } catch(...) { return false ; } return true ; } bool AddVerts( int nMode, int nCount, unsigned int nVaoId, unsigned int nVboId) - { NewGrAtom nga ; - nga.m_nType = NewGrAtom::VERTS ; + { NgAtom nga ; + nga.m_nType = NgAtom::VERTS ; nga.m_nMode = nMode ; nga.m_nCount = nCount ; nga.m_nVaoId = nVaoId ; nga.m_nVboId = nVboId ; - return AddNewGrAtom( nga) ; } + return AddNgAtom( nga) ; } bool AddColor( float fRed, float fGreen, float fBlue, float fAlpha = 1) - { NewGrAtom nga ; - nga.m_nType = NewGrAtom::COLOR ; + { NgAtom nga ; + nga.m_nType = NgAtom::COLOR ; nga.m_fRed = fRed ; nga.m_fGreen = fGreen ; nga.m_fBlue = fBlue ; nga.m_fAlpha = fAlpha ; - return AddNewGrAtom( nga) ; } + return AddNgAtom( nga) ; } + bool AddMaterial( NgAtom::GrType nMat, float fRed, float fGreen, float fBlue, float fAlpha = 1) + { NgAtom nga ; + nga.m_nType = nMat ; + nga.m_fRed = fRed ; nga.m_fGreen = fGreen ; nga.m_fBlue = fBlue ; nga.m_fAlpha = fAlpha ; + return AddNgAtom( nga) ; } private : Scene* m_pScene ; // puntatore alla scena diff --git a/ObjOldGraphics.cpp b/ObjOldGraphics.cpp index 03c7581..93842d9 100644 --- a/ObjOldGraphics.cpp +++ b/ObjOldGraphics.cpp @@ -1,13 +1,13 @@ //---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- -// File : ObjOldGraphics.cpp Data : 10.02.14 Versione : 1.5b1 +// File : ObjOldGraphics.cpp Data : 23.04.14 Versione : 1.5d5 // Contenuto : Implementazione della classe grafica di un oggetto geometrico. // // // // Modifiche : 10.02.14 DS Creazione modulo. -// +// 23.04.14 DS Agg. gestione materiali. // //---------------------------------------------------------------------------- @@ -50,6 +50,27 @@ ObjOldGraphics::AddColor( const Color& colC) return AddColor( colC.GetRed(), colC.GetGreen(), colC.GetBlue(), colC.GetAlpha()) ; } +//---------------------------------------------------------------------------- +bool +ObjOldGraphics::AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec) +{ + return AddMaterial( OgAtom::MAT_A, colAmb.GetRed(), colAmb.GetGreen(), + colAmb.GetBlue(), colDiff.GetAlpha()) && + AddMaterial( OgAtom::MAT_D, colDiff.GetRed(), colDiff.GetGreen(), + colDiff.GetBlue(), colDiff.GetAlpha()) && + AddMaterial( OgAtom::MAT_S, colSpec.GetRed(), colSpec.GetGreen(), + colSpec.GetBlue(), colDiff.GetAlpha()) && + AddMaterial( OgAtom::MAT_SH, 128 * colSpec.GetAlpha(), 0, 0, 0) ; +} + +//---------------------------------------------------------------------------- +bool +ObjOldGraphics::AddBackMaterial( const Color& colAmbDiff) +{ + return AddMaterial( OgAtom::MAT_B, colAmbDiff.GetRed(), colAmbDiff.GetGreen(), + colAmbDiff.GetBlue(), colAmbDiff.GetAlpha()) ; +} + //---------------------------------------------------------------------------- bool ObjOldGraphics::AddPoint( const Point3d& ptP) @@ -154,21 +175,36 @@ ObjOldGraphics::Draw( int nStat, int nMark) OGALIST::iterator iIter ; for ( iIter = m_ogaList.begin() ; iIter != m_ogaList.end() ; ++ iIter) { switch ( iIter->m_nType) { - case OldGrAtom::START : + case OgAtom::START : glBegin( iIter->m_nMode) ; break ; - case OldGrAtom::NORMAL : - glNormal3f( iIter->m_fX, iIter->m_fY, iIter->m_fZ) ; - break ; - case OldGrAtom::VERT : - glVertex3f( iIter->m_fX, iIter->m_fY, iIter->m_fZ) ; - break ; - case OldGrAtom::COLOR : - glColor4f( iIter->m_fRed, iIter->m_fGreen, iIter->m_fBlue, iIter->m_fAlpha) ; - break ; - case OldGrAtom::END : + case OgAtom::END : glEnd() ; break ; + case OgAtom::VERT : + glVertex3fv( iIter->m_fVal) ; + break ; + case OgAtom::NORMAL : + glNormal3fv( iIter->m_fVal) ; + break ; + case OgAtom::COLOR : + glColor4fv( iIter->m_fVal) ; + break ; + case OgAtom::MAT_A : + glMaterialfv( GL_FRONT, GL_AMBIENT, iIter->m_fVal) ; + break ; + case OgAtom::MAT_D : + glMaterialfv( GL_FRONT, GL_DIFFUSE, iIter->m_fVal) ; + break ; + case OgAtom::MAT_S : + glMaterialfv( GL_FRONT, GL_SPECULAR, iIter->m_fVal) ; + break ; + case OgAtom::MAT_SH : + glMaterialf( GL_FRONT, GL_SHININESS, iIter->m_fVal[0]) ; + break ; + case OgAtom::MAT_B : + glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, iIter->m_fVal) ; + break ; } } @@ -186,18 +222,17 @@ ObjOldGraphics::Draw( int nStat, int nMark) OGALIST::iterator iIter ; for ( iIter = m_ogaList.begin() ; iIter != m_ogaList.end() ; ++ iIter) { switch ( iIter->m_nType) { - case OldGrAtom::START : + case OgAtom::START : glBegin( iIter->m_nMode) ; break ; - case OldGrAtom::VERT : - glVertex3f( iIter->m_fX, iIter->m_fY, iIter->m_fZ) ; - break ; - case OldGrAtom::COLOR : - // si usa il colore di marcatura - break ; - case OldGrAtom::END : + case OgAtom::END : glEnd() ; break ; + case OgAtom::VERT : + glVertex3fv( iIter->m_fVal) ; + break ; + // non si imposta la normale sono solo curve + // non si impostano i colori, si usa quello di marcatura } } } diff --git a/ObjOldGraphics.h b/ObjOldGraphics.h index fa83f71..3d699fa 100644 --- a/ObjOldGraphics.h +++ b/ObjOldGraphics.h @@ -21,38 +21,38 @@ class Color ; //---------------------------------------------------------------------------- -// Definizione di OldGrAtom -class OldGrAtom { +// Definizione di OgAtom +class OgAtom { public : - OldGrAtom( void) : m_nType( NONE), m_fX( 0), m_fY( 0), m_fZ( 0), m_fW( 1) {} + OgAtom( void) : m_nType( NONE), m_fX( 0), m_fY( 0), m_fZ( 0), m_fW( 1) {} public : - enum GrType { NONE = 0, START = 1, VERT = 2, NORMAL = 3, COLOR = 4, END = 5} ; + enum GrType { NONE = 0, START = 1, END = 2, VERT = 3, NORMAL = 4, + COLOR = 5, MAT_A = 6, MAT_D = 7, MAT_S = 8, MAT_SH = 9, MAT_B = 10} ; public : GrType m_nType ; union { int m_nMode ; - float m_fX ; - float m_fRed ; - } ; - union { - float m_fY ; - float m_fGreen ; - } ; - union { - float m_fZ ; - float m_fBlue ; - } ; - union { - float m_fW ; - float m_fAlpha ; + struct { + float m_fX ; + float m_fY ; + float m_fZ ; + float m_fW ; + } ; + struct { + float m_fRed ; + float m_fGreen ; + float m_fBlue ; + float m_fAlpha ; + } ; + float m_fVal[4] ; } ; } ; //---------------------------------------------------------------------------- -// Lista di OldGrAtom -typedef std::list OGALIST ; +// Lista di OgAtom +typedef std::list OGALIST ; //---------------------------------------------------------------------------- class ObjOldGraphics : public ObjEGrGraphics @@ -70,6 +70,8 @@ class ObjOldGraphics : public ObjEGrGraphics { return m_pScene ; } virtual void Clear( void) ; virtual bool AddColor( const Color& colC) ; + virtual bool AddMaterial( const Color& colAmb, const Color& colDiff, const Color& colSpec) ; + virtual bool AddBackMaterial( const Color& colAmbDiff) ; virtual bool AddPoint( const Point3d& ptP) ; virtual bool AddPolyLine( const PolyLine& PL) ; virtual bool StartTriangles( int nNum) ; @@ -81,34 +83,39 @@ class ObjOldGraphics : public ObjEGrGraphics ObjOldGraphics( void) : m_pScene( nullptr), m_nCurrMode( GL_NONE), m_bValid( false) {} private : - bool AddOldGrAtom( const OldGrAtom& oga) + bool AddOgAtom( const OgAtom& oga) { try { m_ogaList.push_back( oga) ; } catch(...) { return false ; } return true ; } bool AddStart( int nMode) - { OldGrAtom oga ; - oga.m_nType = OldGrAtom::START ; + { OgAtom oga ; + oga.m_nType = OgAtom::START ; oga.m_nMode = nMode ; - return AddOldGrAtom( oga) ; } - bool AddVert3f( const Point3d& ptP) - { OldGrAtom oga ; - oga.m_nType = OldGrAtom::VERT ; + return AddOgAtom( oga) ; } + bool AddEnd( void) + { OgAtom oga ; + oga.m_nType = OgAtom::END ; + return AddOgAtom( oga) ; } + bool AddVert3f( const Point3d& ptP) + { OgAtom oga ; + oga.m_nType = OgAtom::VERT ; oga.m_fX = float( ptP.x) ; oga.m_fY = float( ptP.y) ; oga.m_fZ = float( ptP.z) ; - return AddOldGrAtom( oga) ; } + return AddOgAtom( oga) ; } bool AddNormal3f( const Vector3d& vtN) - { OldGrAtom oga ; - oga.m_nType = OldGrAtom::NORMAL ; + { OgAtom oga ; + oga.m_nType = OgAtom::NORMAL ; oga.m_fX = float( vtN.x) ; oga.m_fY = float( vtN.y) ; oga.m_fZ = float( vtN.z) ; - return AddOldGrAtom( oga) ; } + return AddOgAtom( oga) ; } bool AddColor( float fRed, float fGreen, float fBlue, float fAlpha = 1) - { OldGrAtom oga ; - oga.m_nType = OldGrAtom::COLOR ; + { OgAtom oga ; + oga.m_nType = OgAtom::COLOR ; oga.m_fRed = fRed ; oga.m_fGreen = fGreen ; oga.m_fBlue = fBlue ; oga.m_fAlpha = fAlpha ; - return AddOldGrAtom( oga) ; } - bool AddEnd( void) - { OldGrAtom oga ; - oga.m_nType = OldGrAtom::END ; - return AddOldGrAtom( oga) ; } + return AddOgAtom( oga) ; } + bool AddMaterial( OgAtom::GrType nMat, float fRed, float fGreen, float fBlue, float fAlpha = 1) + { OgAtom nga ; + nga.m_nType = nMat ; + nga.m_fRed = fRed ; nga.m_fGreen = fGreen ; nga.m_fBlue = fBlue ; nga.m_fAlpha = fAlpha ; + return AddOgAtom( nga) ; } private : Scene* m_pScene ; // puntatore alla scena diff --git a/Scene.h b/Scene.h index 0742d1c..c17d982 100644 --- a/Scene.h +++ b/Scene.h @@ -19,6 +19,18 @@ class IGdbIterator ; +//---------------------------------------------------------------------------- +class MdStMk +{ + public : + MdStMk( int nMd, int nSt, int nMk) : nMode( nMd), nStat( nSt), nMark( nMk) {} + + public : + int nMode ; + int nStat ; + int nMark ; +} ; + //---------------------------------------------------------------------------- class Scene : public IEGrScene { @@ -99,9 +111,9 @@ class Scene : public IEGrScene bool CalcDirUp( void) ; bool CalcCameraFrame( Frame3d& frView) ; // Geometry - bool DrawGroup( int nId, int nParentMode, int nParentStat, int nParentMark) ; - bool DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat, int nParentMark) ; - bool DrawGeoObj( const IGdbIterator& iIter, int nObjStat, int nObjMark) ; + bool DrawGroup( int nId, int nPass, MdStMk siParent) ; + bool DrawGroup( const IGdbIterator& iIter, int nPass, MdStMk siParent) ; + bool DrawGeoObj( const IGdbIterator& iIter, int nPass, MdStMk siObj) ; bool DeleteObjGraphicsGroup( int nId) ; // Aux bool DrawWinRect( void) ; diff --git a/SceneBasic.cpp b/SceneBasic.cpp index facb374..1ed269c 100644 --- a/SceneBasic.cpp +++ b/SceneBasic.cpp @@ -640,16 +640,33 @@ Scene::Draw( void) // impostazioni dipendenti dalla modalità di visualizzazione switch ( m_nShowMode) { case SM_WIREFRAME : - // imposto disegno wireframe anche per poligoni - glPolygonMode( GL_FRONT_AND_BACK, GL_LINE) ; // disabilito illuminazione glDisable( GL_LIGHTING) ; + // imposto disegno wireframe anche per poligoni + glPolygonMode( GL_FRONT_AND_BACK, GL_LINE) ; + // disegno le geometrie del DB in una sola passata + DrawGroup( GDB_ID_ROOT, 1, MdStMk( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF)) ; break ; case SM_HIDDENLINE : + // disabilito illuminazione + glDisable( GL_LIGHTING) ; + // disegno le geometrie del DB + // prima passata per superfici solo per aggiornare Zbuffer (poligoni riempiti e offsettati) + glPolygonMode( GL_FRONT_AND_BACK, GL_FILL) ; + glEnable( GL_POLYGON_OFFSET_FILL) ; + glPolygonOffset( 1.0, 1.0) ; + glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE) ; + DrawGroup( GDB_ID_ROOT, 1, MdStMk( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF)) ; + glColorMask( GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE) ; + glDisable( GL_POLYGON_OFFSET_FILL) ; + // seconda passata per tutto in forma 0dim e curve + glPolygonMode( GL_FRONT_AND_BACK, GL_LINE) ; + DrawGroup( GDB_ID_ROOT, 2, MdStMk( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF)) ; break ; case SM_SHADING : - // imposto disegno shading per poligoni + // imposto disegno shading per poligoni con davanti e dietro diversificati glPolygonMode( GL_FRONT_AND_BACK, GL_FILL) ; + glLightModeli( GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE) ; // imposto tipo shading glShadeModel( GL_SMOOTH) ; // imposto illuminazione @@ -667,16 +684,16 @@ Scene::Draw( void) glLightfv( GL_LIGHT1, GL_SPECULAR, LightStd) ; glLightfv( GL_LIGHT1, GL_POSITION, Light1Pos) ; glEnable( GL_LIGHT1) ; + // disegno le geometrie del DB + // prima passata per superfici con illuminazione abilitata glEnable( GL_LIGHTING) ; - // provvisorio - glEnable( GL_COLOR_MATERIAL) ; - glColorMaterial( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) ; + DrawGroup( GDB_ID_ROOT, 1, MdStMk( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF)) ; + // seconda passata per 0dim e curve con illuminazione disabilitata + glDisable( GL_LIGHTING) ; + DrawGroup( GDB_ID_ROOT, 2, MdStMk( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF)) ; break ; } - // disegno le geometrie del DB - DrawGroup( GDB_ID_ROOT, GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF) ; - // aggiungo disegni diretti (senza test Zbuffer e con poligoni riempiti) glDisable( GL_DEPTH_TEST) ; glDisable( GL_LIGHTING) ; diff --git a/SceneGeom.cpp b/SceneGeom.cpp index 6ed9644..2c7ba8b 100644 --- a/SceneGeom.cpp +++ b/SceneGeom.cpp @@ -91,7 +91,7 @@ Scene::SetMark( Color colMark) //---------------------------------------------------------------------------- bool -Scene::DrawGroup( int nId, int nParentMode, int nParentStat, int nParentMark) +Scene::DrawGroup( int nId, int nPass, MdStMk cParent) { // creo un iteratore PtrOwner pIter( CreateGdbIterator( m_pGeomDB)) ; @@ -103,12 +103,12 @@ Scene::DrawGroup( int nId, int nParentMode, int nParentStat, int nParentMark) return false ; // eseguo il disegno - return DrawGroup( *pIter, nParentMode, nParentStat, nParentMark) ; + return DrawGroup( *pIter, nPass, cParent) ; } //---------------------------------------------------------------------------- bool -Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat, int nParentMark) +Scene::DrawGroup( const IGdbIterator& iIter, int nPass, MdStMk cParent) { // recupero il riferimento del gruppo Frame3d frFrame ; @@ -121,34 +121,35 @@ Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat, i double Matrix[OGLMAT_DIM] ; if ( FrameToOpenGlMatrix( frFrame, Matrix)) glMultMatrixd( Matrix) ; - } + } // creo un iteratore PtrOwner pIter( CreateGdbIterator( m_pGeomDB)) ; if ( ! ::IsValid( pIter)) return false ; // scandisco il gruppo - bool bNext = pIter->GoToFirstInGroup( iIter) ; - while ( bNext) { + for ( bool bNext = pIter->GoToFirstInGroup( iIter) ; + bNext ; + bNext = pIter->GoToNext()) { // leggo il tipo di oggetto int nGdbType = pIter->GetGdbType() ; // recupero e aggiorno il modo dell'oggetto int nMode = GDB_MD_STD ; pIter->GetMode( nMode) ; - nMode = ::CalcMode( nMode, nParentMode) ; + nMode = ::CalcMode( nMode, cParent.nMode) ; // recupero e aggiorno lo stato dell'oggetto int nStat = GDB_ST_ON ; pIter->GetStatus( nStat) ; - nStat = ::CalcStatus( nStat, nParentStat) ; + nStat = ::CalcStatus( nStat, cParent.nStat) ; nStat = ::AdjustStatusWithMode( nStat, nMode) ; // recupero e aggiorno la marcatura dell'oggetto int nMark = GDB_MK_OFF ; pIter->GetMark( nMark) ; - nMark = ::CalcMark( nMark, nParentMark) ; + nMark = ::CalcMark( nMark, cParent.nMark) ; // se oggetto geometrico if ( nGdbType == GDB_TY_GEO) { // se non nascosto, lo disegno if ( nStat != GDB_ST_OFF) { - if ( ! DrawGeoObj( *pIter, nStat, nMark)) + if ( ! DrawGeoObj( *pIter, nPass, MdStMk( nMode, nStat, nMark))) return false ; } } @@ -156,12 +157,10 @@ Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat, i else if ( nGdbType == GDB_TY_GROUP) { // se non nascosto, lo disegno if ( nStat != GDB_ST_OFF) { - if ( ! DrawGroup( *pIter, nMode, nStat, nMark)) + if ( ! DrawGroup( *pIter, nPass, MdStMk( nMode, nStat, nMark))) return false ; } } - // passo al successivo - bNext = pIter->GoToNext() ; } // se necessario, ripristino lo stack delle matrici if ( bMatrix) @@ -172,7 +171,7 @@ Scene::DrawGroup( const IGdbIterator& iIter, int nParentMode, int nParentStat, i //---------------------------------------------------------------------------- bool -Scene::DrawGeoObj( const IGdbIterator& iIter, int nObjStat, int nObjMark) +Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, MdStMk siObj) { // recupero l'oggetto geometrico IGeoObj* pGeoObj = (const_cast(&iIter))->GetGeoObj() ; @@ -260,6 +259,14 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nObjStat, int nObjMark) // impostazioni iniziali pGraphics->Clear() ; pGraphics->AddColor( cCol) ; + pGraphics->AddMaterial( cCol, cCol, Color( 192, 192, 192, 50)) ; + Color colBack ; + float fLum = ( cCol.GetRed() + cCol.GetGreen() + cCol.GetBlue()) / 3 ; + colBack.Set( 0.4 * fLum + 0.2 * cCol.GetRed(), + 0.4 * fLum + 0.2 * cCol.GetGreen(), + 0.4 * fLum + 0.2 * cCol.GetBlue(), + cCol.GetAlpha()) ; + pGraphics->AddBackMaterial( colBack) ; pGraphics->StartTriangles( pSTM->GetTriangleNum()) ; // ciclo sui triangoli della superficie Triangle3d Tria ; @@ -274,8 +281,25 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nObjStat, int nObjMark) } } + // se hiddenline + if ( m_nShowMode == SM_HIDDENLINE) { + // in prima passata disegno solo le superfici + if ( nPass == 1 && ( pGeoObj->GetType() & GEO_SURF) == 0) + return true ; + } + + // se shading + if ( m_nShowMode == SM_SHADING) { + // in prima passata disegno solo le superfici + if ( nPass == 1 && ( pGeoObj->GetType() & GEO_SURF) == 0) + return true ; + // in seconda passata disegno solo dimensioni 0 e curve + if ( nPass == 2 && ( pGeoObj->GetType() & GEO_SURF) != 0) + return true ; + } + // visualizzo la grafica associata - return pGraphics->Draw( nObjStat, nObjMark) ; + return pGraphics->Draw( siObj.nStat, siObj.nMark) ; } //----------------------------------------------------------------------------