Files
EgtGraphics/ObjNewGraphics.h
DarioS 00a81d6e04 EgtGraphics 2.5g1 :
- aggiunta gestione Stipple per GeoPoint3d, GeoVector3d e GeoCurve.
2023-07-10 11:16:17 +02:00

134 lines
5.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"
//----------------------------------------------------------------------------
// 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, VERTS_A = 2, COLOR = 3,
MAT_A = 4, MAT_D = 5, MAT_S = 6, MAT_SH = 7, MAT_B = 8, LINE_STIPPLE = 9} ;
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] ;
struct {
int m_nFactor ;
int m_nPattern ;
} ;
} ;
} ;
//----------------------------------------------------------------------------
// Vettore di NgAtom
typedef std::vector<NgAtom> NGAVECT ;
//----------------------------------------------------------------------------
class ObjNewGraphics : public ObjEGrGraphics
{
public : // IObjGraphics
~ObjNewGraphics( void) override ;
void Reset( void) override ;
void ResetAll( void) override
{ Reset() ; }
public : // ObjEGrGraphics
bool IsValid( void) override
{ return m_bValid ; }
void SetScene( Scene* pScene) override
{ m_pScene = pScene ; }
Scene* GetScene( void) override
{ return m_pScene ; }
void Clear( void) override ;
bool AddColor( const Color& colC) override ;
bool AddMaterial( const Color& colAmb, const Color& colDiff,
const Color& colSpec, float fShin) override ;
bool AddBackMaterial( const Color& colAmbDiff) override ;
bool AddLineStipple( int nFactor, int nPattern) override ;
bool AddPoint( const Point3d& ptP, bool bAux = false) override ;
bool AddPoints( const PNTVECTOR& vPnt, bool bAux = false) override ;
bool AddLines( const PNTVECTOR& vPnt, bool bAux = false) override ;
bool AddPolyLine( const PolyLine& PL, bool bAux = false) override ;
bool StartTriangles( int nNum, bool bAux = false) override ;
bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) override ;
bool EndTriangles( void) override ;
bool Draw( int nStat, int nMark, bool bSurfSha, bool bSurf, int nAlpha, bool bShowAux) override ;
bool GetLocalBBox( BBox3d& b3Loc) const override
{ b3Loc = m_b3Loc ; return ! m_b3Loc.IsEmpty() ; }
public :
ObjNewGraphics( void) : m_pScene( nullptr), m_bValid( false) {}
private :
bool DeleteVaoVbo( void) ;
bool AddNgAtom( const NgAtom& nga)
{ try { m_ngaVect.push_back( nga) ; }
catch(...) { return false ; }
return true ; }
bool AddNgaVerts( int nMode, int nCount, unsigned int nVaoId, unsigned int nVboId, bool bAux = false)
{ NgAtom nga ;
nga.m_nType = ( bAux ? NgAtom::VERTS_A : NgAtom::VERTS) ;
nga.m_nMode = nMode ; nga.m_nCount = nCount ;
nga.m_nVaoId = nVaoId ; nga.m_nVboId = nVboId ;
return AddNgAtom( nga) ; }
bool AddNgaColor( 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 AddNgaMaterial( 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) ; }
bool AddNgaLineStipple( int nFactor, int nPattern)
{ NgAtom nga ;
nga.m_nType = NgAtom::LINE_STIPPLE ;
nga.m_nFactor = nFactor ;
nga.m_nPattern = nPattern ;
return AddNgAtom( nga) ; }
private :
Scene* m_pScene ; // puntatore alla scena
bool m_bValid ; // flag
int m_nCurrMode ; // modo corrente
NGAVECT m_ngaVect ; // vettore di atomi per nuova grafica
BBox3d m_b3Loc ; // BoundingBox locale
} ;
//----------------------------------------------------------------------------
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())) ; }