EgtGraphics 2.5g1 :

- aggiunta gestione Stipple per GeoPoint3d, GeoVector3d e GeoCurve.
This commit is contained in:
DarioS
2023-07-10 11:16:17 +02:00
parent 1704b40c17
commit 00a81d6e04
9 changed files with 244 additions and 124 deletions
+91 -51
View File
@@ -1,7 +1,7 @@
//----------------------------------------------------------------------------
// EgalTech 2014-2014
// EgalTech 2014-2023
//----------------------------------------------------------------------------
// File : ObjOldGraphics.cpp Data : 23.04.14 Versione : 1.5d5
// File : ObjOldGraphics.cpp Data : 08.07.23 Versione : 2.5g1
// Contenuto : Implementazione della classe grafica di un oggetto geometrico.
//
//
@@ -19,8 +19,9 @@
#include "/EgtDev/Include/EGkPolyLine.h"
#include "/EgtDev/Include/EGkGdbConst.h"
#include "/EgtDev/Include/EGkTriangle3d.h"
#include "/EgtDev/Include/EgtNumUtils.h"
//----------------------------------------------------------------------------
//--------------------------- Macro e Costanti -------------------------------
const int VECT_HEAP = 20 ;
@@ -51,7 +52,7 @@ ObjOldGraphics::Clear( void)
bool
ObjOldGraphics::AddColor( const Color& colC)
{
return AddColor( colC.GetRed(), colC.GetGreen(), colC.GetBlue(), colC.GetAlpha()) ;
return AddOgaColor( colC.GetRed(), colC.GetGreen(), colC.GetBlue(), colC.GetAlpha()) ;
}
//----------------------------------------------------------------------------
@@ -59,21 +60,28 @@ bool
ObjOldGraphics::AddMaterial( const Color& colAmb, const Color& colDiff,
const Color& colSpec, float fShin)
{
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, fShin, 0, 0, 0) ;
return AddOgaMaterial( OgAtom::MAT_A, colAmb.GetRed(), colAmb.GetGreen(),
colAmb.GetBlue(), colDiff.GetAlpha()) &&
AddOgaMaterial( OgAtom::MAT_D, colDiff.GetRed(), colDiff.GetGreen(),
colDiff.GetBlue(), colDiff.GetAlpha()) &&
AddOgaMaterial( OgAtom::MAT_S, colSpec.GetRed(), colSpec.GetGreen(),
colSpec.GetBlue(), colDiff.GetAlpha()) &&
AddOgaMaterial( OgAtom::MAT_SH, fShin, 0, 0, 0) ;
}
//----------------------------------------------------------------------------
bool
ObjOldGraphics::AddBackMaterial( const Color& colAmbDiff)
{
return AddMaterial( OgAtom::MAT_B, colAmbDiff.GetRed(), colAmbDiff.GetGreen(),
colAmbDiff.GetBlue(), colAmbDiff.GetAlpha()) ;
return AddOgaMaterial( OgAtom::MAT_B, colAmbDiff.GetRed(), colAmbDiff.GetGreen(),
colAmbDiff.GetBlue(), colAmbDiff.GetAlpha()) ;
}
//----------------------------------------------------------------------------
bool
ObjOldGraphics::AddLineStipple( int nFactor, int nPattern)
{
return AddOgaLineStipple( nFactor, nPattern) ;
}
//----------------------------------------------------------------------------
@@ -84,13 +92,13 @@ ObjOldGraphics::AddPoint( const Point3d& ptP, bool bAux)
if ( m_nCurrMode != GL_NONE)
return false ;
// start
AddStart( GL_POINTS, bAux) ;
AddOgaStart( GL_POINTS, bAux) ;
// inserisco il nuovo vertice
AddVert3f( ptP) ;
AddOgaVert3f( ptP) ;
// aggiorno bbox
m_b3Loc.Add( ptP) ;
// fine
AddEnd() ;
AddOgaEnd() ;
// dichiaro valida la grafica
m_bValid = true ;
@@ -105,14 +113,14 @@ ObjOldGraphics::AddPoints( const PNTVECTOR& vPnt, bool bAux)
if ( m_nCurrMode != GL_NONE)
return false ;
// start
AddStart( GL_POINTS, bAux) ;
AddOgaStart( GL_POINTS, bAux) ;
// inserisco i vertici + aggiorno bbox
for ( int i = 0 ; i < int( vPnt.size()) ; ++ i) {
AddVert3f( vPnt[i]) ;
AddOgaVert3f( vPnt[i]) ;
m_b3Loc.Add( vPnt[i]) ;
}
// fine
AddEnd() ;
AddOgaEnd() ;
// dichiaro valida la grafica
m_bValid = true ;
@@ -129,14 +137,14 @@ ObjOldGraphics::AddLines( const PNTVECTOR& vPnt, bool bAux)
// riservo memoria per vettore
m_ogaVect.reserve( VECT_HEAP + vPnt.size()) ;
// start
AddStart( GL_LINES, bAux) ;
AddOgaStart( GL_LINES, bAux) ;
// inserisco i vertici + aggiorno bbox
for ( int i = 0 ; i < int( vPnt.size()) ; ++ i) {
AddVert3f( vPnt[i]) ;
AddOgaVert3f( vPnt[i]) ;
m_b3Loc.Add( vPnt[i]) ;
}
// fine
AddEnd() ;
AddOgaEnd() ;
// dichiaro valida la grafica
m_bValid = true ;
@@ -153,15 +161,15 @@ ObjOldGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
// riservo memoria per vettore
m_ogaVect.reserve( VECT_HEAP + PL.GetPointNbr()) ;
// start
AddStart( GL_LINE_STRIP, bAux) ;
AddOgaStart( GL_LINE_STRIP, bAux) ;
// inserisco i nuovi vertici + aggiorno bbox
Point3d ptP ;
for ( bool bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP)) {
AddVert3f( ptP) ;
AddOgaVert3f( ptP) ;
m_b3Loc.Add( ptP) ;
}
// fine
AddEnd() ;
AddOgaEnd() ;
// dichiaro valida la grafica
m_bValid = true ;
@@ -178,7 +186,7 @@ ObjOldGraphics::StartTriangles( int nNum, bool bAux)
// riservo memoria per vettore
m_ogaVect.reserve( VECT_HEAP + 3 * nNum) ;
// inizio emissione triangoli
AddStart( GL_TRIANGLES, bAux) ;
AddOgaStart( GL_TRIANGLES, bAux) ;
m_nCurrMode = GL_TRIANGLES ;
return true ;
}
@@ -192,9 +200,9 @@ ObjOldGraphics::AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, c
return false ;
// emetto i flag, le normali e i vertici del triangolo + aggiorno bbox
for ( int i = 0 ; i < 3 ; ++ i) {
AddBndFlag( TFlags.bFlag[i]) ;
AddNormal3f( TNrms.vtN[i]) ;
AddVert3f( Tria.GetP( i)) ;
AddOgaBndFlag( TFlags.bFlag[i]) ;
AddOgaNormal3f( TNrms.vtN[i]) ;
AddOgaVert3f( Tria.GetP( i)) ;
m_b3Loc.Add( Tria.GetP( i)) ;
}
return true ;
@@ -208,7 +216,7 @@ ObjOldGraphics::EndTriangles( void)
if ( m_nCurrMode != GL_TRIANGLES)
return false ;
// termino il modo triangoli
AddEnd() ;
AddOgaEnd() ;
m_nCurrMode = GL_NONE ;
// dichiaro valida la grafica
m_bValid = true ;
@@ -217,8 +225,8 @@ ObjOldGraphics::EndTriangles( void)
}
//----------------------------------------------------------------------------
static float*
AdjustColor( float fCol[4], bool bDark)
static const float*
AdjustColor( const float fCol[4], bool bDark)
{
if ( ! bDark) {
return fCol ;
@@ -285,15 +293,16 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
// ciclo di disegno
bool bStartA = false ;
for ( auto iIter = m_ogaVect.begin() ; iIter != m_ogaVect.end() ; ++ iIter) {
switch ( iIter->m_nType) {
bool bLineStipple = false ;
for ( const auto& Oga : m_ogaVect) {
switch ( Oga.m_nType) {
case OgAtom::START :
glBegin( iIter->m_nMode) ;
glBegin( Oga.m_nMode) ;
bStartA = false ;
break ;
case OgAtom::START_A :
if ( bShowAux)
glBegin( iIter->m_nMode) ;
glBegin( Oga.m_nMode) ;
bStartA = true ;
break ;
case OgAtom::END :
@@ -303,36 +312,51 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
break ;
case OgAtom::VERT :
if ( ! bStartA || bShowAux)
glVertex3fv( iIter->m_fVal) ;
glVertex3fv( Oga.m_fVal) ;
break ;
case OgAtom::BND_FLAG :
if ( ! bStartA || bShowAux)
glEdgeFlag( iIter->m_nFlag) ;
glEdgeFlag( Oga.m_nFlag) ;
break ;
case OgAtom::NORMAL :
if ( ! bStartA || bShowAux)
glNormal3fv( iIter->m_fVal) ;
glNormal3fv( Oga.m_fVal) ;
break ;
case OgAtom::COLOR :
glColor4fv( ( bStdCol ? AdjustColor( iIter->m_fVal, bDark) : fSelMarkCol)) ;
glColor4fv( ( bStdCol ? AdjustColor( Oga.m_fVal, bDark) : fSelMarkCol)) ;
break ;
case OgAtom::MAT_A :
glMaterialfv( GL_FRONT, GL_AMBIENT, ( bStdCol ? iIter->m_fVal : fSelMarkCol)) ;
glMaterialfv( GL_FRONT, GL_AMBIENT, ( bStdCol ? Oga.m_fVal : fSelMarkCol)) ;
break ;
case OgAtom::MAT_D :
glMaterialfv( GL_FRONT, GL_DIFFUSE, ( bStdCol ? iIter->m_fVal : fSelMarkCol)) ;
glMaterialfv( GL_FRONT, GL_DIFFUSE, ( bStdCol ? Oga.m_fVal : fSelMarkCol)) ;
break ;
case OgAtom::MAT_S :
glMaterialfv( GL_FRONT, GL_SPECULAR, ( bStdCol ? iIter->m_fVal : fSelMarkCol)) ;
glMaterialfv( GL_FRONT, GL_SPECULAR, ( bStdCol ? Oga.m_fVal : fSelMarkCol)) ;
break ;
case OgAtom::MAT_SH :
glMaterialf( GL_FRONT, GL_SHININESS, iIter->m_fVal[0]) ;
glMaterialf( GL_FRONT, GL_SHININESS, Oga.m_fVal[0]) ;
break ;
case OgAtom::MAT_B :
glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, ( bStdCol ? iIter->m_fVal : fSelMarkBackCol)) ;
glMaterialfv( GL_BACK, GL_AMBIENT_AND_DIFFUSE, ( bStdCol ? Oga.m_fVal : fSelMarkBackCol)) ;
break ;
case OgAtom::LINE_STIPPLE :
if ( Oga.m_nMode > 0) {
bLineStipple = true ;
glLineStipple( Clamp( Oga.m_nFactor, 1, 256), Clamp( Oga.m_nPattern, 0, 65535)) ;
glEnable( GL_LINE_STIPPLE) ;
}
else {
bLineStipple = false ;
glDisable( GL_LINE_STIPPLE) ;
}
break ;
}
}
if ( bLineStipple) {
bLineStipple = false ;
glDisable( GL_LINE_STIPPLE) ;
}
// se marcato e non superficie in shading, disegno halo
if ( nMark == GDB_MK_ON && ! bSurfSha) {
@@ -349,15 +373,16 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
// ciclo di disegno
bool bStartA = false ;
for ( auto iIter = m_ogaVect.begin() ; iIter != m_ogaVect.end() ; ++ iIter) {
switch ( iIter->m_nType) {
bool bLineStipple = false ;
for ( const auto& Oga : m_ogaVect) {
switch ( Oga.m_nType) {
case OgAtom::START :
glBegin( iIter->m_nMode) ;
glBegin( Oga.m_nMode) ;
bStartA = false ;
break ;
case OgAtom::START_A :
if ( bShowAux)
glBegin( iIter->m_nMode) ;
glBegin( Oga.m_nMode) ;
bStartA = true ;
break ;
case OgAtom::END :
@@ -367,16 +392,31 @@ ObjOldGraphics::Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlph
break ;
case OgAtom::VERT :
if ( ! bStartA || bShowAux)
glVertex3fv( iIter->m_fVal) ;
glVertex3fv( Oga.m_fVal) ;
break ;
case OgAtom::BND_FLAG :
if ( ! bStartA || bShowAux)
glEdgeFlag( iIter->m_nFlag) ;
glEdgeFlag( Oga.m_nFlag) ;
break ;
// non si imposta la normale sono solo curve
// non si impostano i colori, si usa quello di marcatura
case OgAtom::LINE_STIPPLE :
if ( Oga.m_nMode > 0) {
bLineStipple = true ;
glLineStipple( Clamp( Oga.m_nFactor, 1, 256), Clamp( Oga.m_nPattern, 0, 65535)) ;
glEnable( GL_LINE_STIPPLE) ;
}
else {
bLineStipple = false ;
glDisable( GL_LINE_STIPPLE) ;
}
break ;
}
}
if ( bLineStipple) {
bLineStipple = false ;
glDisable( GL_LINE_STIPPLE) ;
}
// ripristino test di depth
glDepthFunc( GL_LEQUAL) ;
}