Files
EgtGraphics/ObjNewGraphics.h
T
Dario Sassi a6a888791a EgtGraphics 1.5d6 :
- introdotto utilizzo materiali.
2014-04-27 20:10:48 +00:00

117 lines
4.5 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : ObjNewGraphics.h Data : 13.02.14 Versione : 1.5b1
// Contenuto : Dichiarazione della classe grafica di un oggetto geometrico.
//
//
//
// Modifiche : 13.02.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "ObjEGrGraphics.h"
#include <list>
//----------------------------------------------------------------------------
// Definizione di NgAtom
class NgAtom {
public :
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, MAT_A = 3, MAT_D = 4, MAT_S = 5, MAT_SH = 6, MAT_B = 7} ;
public :
GrType m_nType ;
union {
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 NgAtom
typedef std::list<NgAtom> NGALIST ;
//----------------------------------------------------------------------------
class ObjNewGraphics : public ObjEGrGraphics
{
public : // IObjGraphics
virtual ~ObjNewGraphics( void) ;
virtual void Reset( void) ;
public : // ObjEGrGraphics
virtual bool IsValid( void)
{ return m_bValid ; }
virtual void SetScene( Scene* pScene)
{ m_pScene = pScene ; }
virtual Scene* GetScene( void)
{ 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, float fShin) ;
virtual bool AddBackMaterial( const Color& colAmbDiff) ;
virtual bool AddPoint( const Point3d& ptP) ;
virtual bool AddPolyLine( const PolyLine& PL) ;
virtual bool StartTriangles( int nNum) ;
virtual bool AddTriangle( const Triangle3d& Tria, const TriNormals3d& TNrms) ;
virtual bool EndTriangles( void) ;
virtual bool Draw( int nStat, int nMark) ;
public :
ObjNewGraphics( void) : m_pScene( nullptr), m_bValid( false) {}
private :
bool DeleteVaoVbo( void) ;
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)
{ NgAtom nga ;
nga.m_nType = NgAtom::VERTS ;
nga.m_nMode = nMode ; nga.m_nCount = nCount ;
nga.m_nVaoId = nVaoId ; nga.m_nVboId = nVboId ;
return AddNgAtom( nga) ; }
bool AddColor( float fRed, float fGreen, float fBlue, float fAlpha = 1)
{ NgAtom nga ;
nga.m_nType = NgAtom::COLOR ;
nga.m_fRed = fRed ; nga.m_fGreen = fGreen ; nga.m_fBlue = fBlue ; nga.m_fAlpha = fAlpha ;
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
bool m_bValid ; // flag
int m_nCurrMode ; // modo corrente
NGALIST m_ngaList ; // lista di atomi per nuova grafica
} ;
//----------------------------------------------------------------------------
inline const ObjNewGraphics* GetObjNewGraphics( const IGeoObj* pGObj)
{ return (dynamic_cast<const ObjNewGraphics*>(pGObj->GetObjGraphics())) ; }
inline ObjNewGraphics* GetObjNewGraphics( IGeoObj* pGObj)
{ return (dynamic_cast<ObjNewGraphics*>(pGObj->GetObjGraphics())) ; }