//---------------------------------------------------------------------------- // EgalTech 2014-2014 //---------------------------------------------------------------------------- // File : ObjOldGraphics.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 "OpenGL.h" #include "/EgtDev/Include/EGkPoint3d.h" #include class Color ; //---------------------------------------------------------------------------- // Definizione di OgAtom class OgAtom { public : OgAtom( void) : m_nType( NONE), m_fX( 0), m_fY( 0), m_fZ( 0), m_fW( 1) {} public : enum GrType { NONE = 0, START = 1, START_A = 2, END = 3, VERT = 4, BND_FLAG = 5, NORMAL = 6, COLOR = 7, MAT_A = 8, MAT_D = 9, MAT_S = 10, MAT_SH = 11, MAT_B = 12} ; public : GrType m_nType ; union { int m_nMode ; struct { float m_fX ; float m_fY ; float m_fZ ; float m_fW ; } ; int m_nFlag ; struct { float m_fRed ; float m_fGreen ; float m_fBlue ; float m_fAlpha ; } ; float m_fVal[4] ; } ; } ; //---------------------------------------------------------------------------- // Lista e vettore di OgAtom typedef std::list OGALIST ; typedef std::vector OGAVECT ; //---------------------------------------------------------------------------- class ObjOldGraphics : public ObjEGrGraphics { public : // IObjGraphics virtual ~ObjOldGraphics( 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, bool bAux = false) ; virtual bool AddLines( const PNTVECTOR& vPnt, bool bAux = false) ; virtual bool AddPolyLine( const PolyLine& PL, bool bAux = false) ; virtual bool StartTriangles( int nNum, bool bAux = false) ; virtual bool AddTriangle( const Triangle3d& Tria, const TriFlags3d& TFlags, const TriNormals3d& TNrms) ; virtual bool EndTriangles( void) ; virtual bool Draw( int nStat, int nMark, bool bSurfSha, int nAlpha, bool bShowAux) ; virtual bool GetLocalBBox( BBox3d& b3Loc) const { b3Loc = m_b3Loc ; return ! m_b3Loc.IsEmpty() ; } public : ObjOldGraphics( void) : m_pScene( nullptr), m_nCurrMode( GL_NONE), m_bValid( false) {} private : bool AddOgAtom( const OgAtom& oga) { try { m_ogaVect.push_back( oga) ; } catch(...) { return false ; } return true ; } bool AddStart( int nMode, bool bAux = false) { OgAtom oga ; oga.m_nType = ( bAux ? OgAtom::START_A : OgAtom::START) ; oga.m_nMode = nMode ; 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 AddOgAtom( oga) ; } bool AddBndFlag( bool bFlag) { OgAtom oga ; oga.m_nType = OgAtom::BND_FLAG ; oga.m_nFlag = ( bFlag ? TRUE : FALSE) ; return AddOgAtom( oga) ; } bool AddNormal3f( const Vector3d& vtN) { 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 AddOgAtom( oga) ; } bool AddColor( float fRed, float fGreen, float fBlue, float fAlpha = 1) { OgAtom oga ; oga.m_nType = OgAtom::COLOR ; oga.m_fRed = fRed ; oga.m_fGreen = fGreen ; oga.m_fBlue = fBlue ; oga.m_fAlpha = fAlpha ; 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 bool m_bValid ; // flag int m_nCurrMode ; // modo corrente OGAVECT m_ogaVect ; // vettore di atomi per vecchia grafica BBox3d m_b3Loc ; // BoundingBox locale } ; //---------------------------------------------------------------------------- inline const ObjOldGraphics* GetObjOldGraphics( const IGeoObj* pGObj) { return (dynamic_cast(pGObj->GetObjGraphics())) ; } inline ObjOldGraphics* GetObjOldGraphics( IGeoObj* pGObj) { return (dynamic_cast(pGObj->GetObjGraphics())) ; }