8f53f1959d
- prevista grafica ausiliaria per curve, visualizzabile da flag.
271 lines
8.1 KiB
C++
271 lines
8.1 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// 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.
|
|
//
|
|
//----------------------------------------------------------------------------
|
|
|
|
//--------------------------- Include ----------------------------------------
|
|
#include "stdafx.h"
|
|
#include "ObjOldGraphics.h"
|
|
#include "Scene.h"
|
|
#include "/EgtDev/Include/EGkColor.h"
|
|
#include "/EgtDev/Include/EGkPolyLine.h"
|
|
#include "/EgtDev/Include/EGkGdbConst.h"
|
|
#include "/EgtDev/Include/EGKTriangle3d.h"
|
|
|
|
//----------------------------------------------------------------------------
|
|
ObjOldGraphics::~ObjOldGraphics( void)
|
|
{
|
|
Clear() ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
ObjOldGraphics::Reset( void)
|
|
{
|
|
m_bValid = false ;
|
|
m_nCurrMode = GL_NONE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
void
|
|
ObjOldGraphics::Clear( void)
|
|
{
|
|
m_ogaList.clear() ;
|
|
m_bValid = false ;
|
|
m_nCurrMode = GL_NONE ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
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, 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) ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
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, bool bAux)
|
|
{
|
|
// modo corrente deve essere nullo
|
|
if ( m_nCurrMode != GL_NONE)
|
|
return false ;
|
|
// start
|
|
AddStart( GL_POINTS, bAux) ;
|
|
// inserisco il nuovo vertice
|
|
AddVert3f( ptP) ;
|
|
// fine
|
|
AddEnd() ;
|
|
// dichiaro valida la grafica
|
|
m_bValid = true ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjOldGraphics::AddPolyLine( const PolyLine& PL, bool bAux)
|
|
{
|
|
// modo corrente deve essere nullo
|
|
if ( m_nCurrMode != GL_NONE)
|
|
return false ;
|
|
// start
|
|
AddStart( GL_LINE_STRIP, bAux) ;
|
|
// inserisco i nuovi vertici
|
|
Point3d ptP ;
|
|
for ( bool bFound = PL.GetFirstPoint( ptP) ; bFound ; bFound = PL.GetNextPoint( ptP))
|
|
AddVert3f( ptP) ;
|
|
// fine
|
|
AddEnd() ;
|
|
// dichiaro valida la grafica
|
|
m_bValid = true ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjOldGraphics::StartTriangles( int nNum, bool bAux)
|
|
{
|
|
// modo corrente deve essere nullo
|
|
if ( m_nCurrMode != GL_NONE)
|
|
return false ;
|
|
// inizio emissione triangoli
|
|
AddStart( GL_TRIANGLES, bAux) ;
|
|
m_nCurrMode = GL_TRIANGLES ;
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjOldGraphics::AddTriangle( const Triangle3d& Tria, const TriNormals3d& TNrms)
|
|
{
|
|
// modo corrente deve essere triangoli
|
|
if ( m_nCurrMode != GL_TRIANGLES)
|
|
return false ;
|
|
// emetto le normali e i vertici del triangolo
|
|
for ( int i = 0 ; i < 3 ; ++ i) {
|
|
AddNormal3f( TNrms.vtN[i]) ;
|
|
AddVert3f( Tria.GetP( i)) ;
|
|
}
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjOldGraphics::EndTriangles( void)
|
|
{
|
|
// modo corrente deve essere triangoli
|
|
if ( m_nCurrMode != GL_TRIANGLES)
|
|
return false ;
|
|
// termino il modo triangoli
|
|
AddEnd() ;
|
|
m_nCurrMode = GL_NONE ;
|
|
// dichiaro valida la grafica
|
|
m_bValid = true ;
|
|
|
|
return true ;
|
|
}
|
|
|
|
//----------------------------------------------------------------------------
|
|
bool
|
|
ObjOldGraphics::Draw( int nStat, int nMark, bool bShowAux)
|
|
{
|
|
// se vuoto non faccio alcunché
|
|
if ( m_ogaList.size() == 0)
|
|
return true ;
|
|
|
|
// gestione stato di visualizzazione
|
|
if ( nStat == GDB_ST_OFF)
|
|
return true ;
|
|
if ( nStat == GDB_ST_SEL) {
|
|
glPointSize( 5) ;
|
|
glLineWidth( 3) ;
|
|
}
|
|
|
|
// ciclo di disegno
|
|
bool bStartA ;
|
|
OGALIST::iterator iIter ;
|
|
for ( iIter = m_ogaList.begin() ; iIter != m_ogaList.end() ; ++ iIter) {
|
|
switch ( iIter->m_nType) {
|
|
case OgAtom::START :
|
|
glBegin( iIter->m_nMode) ;
|
|
break ;
|
|
case OgAtom::START_A :
|
|
bStartA = true ;
|
|
if ( bShowAux)
|
|
glBegin( iIter->m_nMode) ;
|
|
break ;
|
|
case OgAtom::END :
|
|
bStartA = false ;
|
|
glEnd() ;
|
|
break ;
|
|
case OgAtom::VERT :
|
|
if ( ! bStartA || bShowAux)
|
|
glVertex3fv( iIter->m_fVal) ;
|
|
break ;
|
|
case OgAtom::NORMAL :
|
|
if ( ! bStartA || bShowAux)
|
|
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 ;
|
|
}
|
|
}
|
|
|
|
// se marcato, disegno halo
|
|
if ( nMark == GDB_MK_ON) {
|
|
// cambio test di depth per non sovrascrivere il disegno appena fatto
|
|
glDepthFunc( GL_LESS) ;
|
|
|
|
// dimensioni per halo
|
|
glPointSize( 7) ;
|
|
glLineWidth( 5) ;
|
|
|
|
// colore di marcatura
|
|
Color colMark = ( ( GetScene() != nullptr) ? GetScene()->GetMark() : Color( 192, 192, 0)) ;
|
|
glColor4f( colMark.GetRed(), colMark.GetGreen(), colMark.GetBlue(), colMark.GetAlpha()) ;
|
|
|
|
// ciclo di disegno
|
|
bool bStartA ;
|
|
OGALIST::iterator iIter ;
|
|
for ( iIter = m_ogaList.begin() ; iIter != m_ogaList.end() ; ++ iIter) {
|
|
switch ( iIter->m_nType) {
|
|
case OgAtom::START :
|
|
glBegin( iIter->m_nMode) ;
|
|
break ;
|
|
case OgAtom::START_A :
|
|
bStartA = true ;
|
|
if ( bShowAux)
|
|
glBegin( iIter->m_nMode) ;
|
|
break ;
|
|
case OgAtom::END :
|
|
bStartA = false ;
|
|
glEnd() ;
|
|
break ;
|
|
case OgAtom::VERT :
|
|
if ( ! bStartA || bShowAux)
|
|
glVertex3fv( iIter->m_fVal) ;
|
|
break ;
|
|
// non si imposta la normale sono solo curve
|
|
// non si impostano i colori, si usa quello di marcatura
|
|
}
|
|
}
|
|
// ripristino test di depth
|
|
glDepthFunc( GL_LEQUAL) ;
|
|
}
|
|
|
|
// se necessario, ripristino la normale visualizzazione
|
|
if ( nStat == GDB_ST_SEL || nMark == GDB_MK_ON) {
|
|
glPointSize( 3) ;
|
|
glLineWidth( 1) ;
|
|
}
|
|
|
|
return true ;
|
|
}
|