diff --git a/EGrUtils.h b/EGrUtils.h new file mode 100644 index 0000000..b333ca5 --- /dev/null +++ b/EGrUtils.h @@ -0,0 +1,48 @@ +//---------------------------------------------------------------------------- +// EgalTech 2013-2014 +//---------------------------------------------------------------------------- +// File : EGrUtils.h Data : 24.10.14 Versione : 1.5j6 +// Contenuto : Funzioni di utilità. +// +// +// +// Modifiche : 24.10.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +#pragma once + +#include "/EgtDev/Include/EGkFrame3d.h" + + +//------------------------------ Constants ----------------------------------- +const int OGLMAT_DIM = 16 ; // dimensione matrice di trasformazione per OpenGL + + +//---------------------------------------------------------------------------- +inline bool +FrameToOpenGlMatrix( const Frame3d& frFrame, double Matrix[OGLMAT_DIM]) +{ + if ( frFrame.GetType() == Frame3d::ERR) + return false ; + + Matrix[0] = frFrame.VersX().x ; + Matrix[1] = frFrame.VersX().y ; + Matrix[2] = frFrame.VersX().z ; + Matrix[3] = 0 ; + Matrix[4] = frFrame.VersY().x ; + Matrix[5] = frFrame.VersY().y ; + Matrix[6] = frFrame.VersY().z ; + Matrix[7] = 0 ; + Matrix[8] = frFrame.VersZ().x ; + Matrix[9] = frFrame.VersZ().y ; + Matrix[10] = frFrame.VersZ().z ; + Matrix[11] = 0 ; + Matrix[12] = frFrame.Orig().x ; + Matrix[13] = frFrame.Orig().y ; + Matrix[14] = frFrame.Orig().z ; + Matrix[15] = 1 ; + + return true ; +} diff --git a/EgtGraphics.rc b/EgtGraphics.rc index b2c3c51..29a1242 100644 Binary files a/EgtGraphics.rc and b/EgtGraphics.rc differ diff --git a/EgtGraphics.vcxproj b/EgtGraphics.vcxproj index abe6f86..547432f 100644 --- a/EgtGraphics.vcxproj +++ b/EgtGraphics.vcxproj @@ -231,6 +231,7 @@ copy $(TargetPath) \EgtProg\Dll64 + Create diff --git a/EgtGraphics.vcxproj.filters b/EgtGraphics.vcxproj.filters index 99e683f..5f51ea5 100644 --- a/EgtGraphics.vcxproj.filters +++ b/EgtGraphics.vcxproj.filters @@ -104,6 +104,9 @@ File di origine + + File di origine + diff --git a/Scene.h b/Scene.h index 84dd11b..65d7b72 100644 --- a/Scene.h +++ b/Scene.h @@ -15,6 +15,7 @@ //---------------------------------------------------------------------------- #include "/EgtDev/Include/EGrScene.h" +#include "/EgtDev/Include/EGkFrame3d.h" #include "OpenGL.h" class IGdbIterator ; @@ -104,6 +105,13 @@ class Scene : public IEGrScene virtual bool SetExtension( const BBox3d& b3Ext) ; virtual bool UpdateExtension( void) ; virtual bool SetMark( Color colMark) ; + // Grid + virtual bool SetGridShow( bool bShowGrid, bool bShowFrame) ; + virtual bool SetGridFrame( const Frame3d& frFrame) ; + virtual bool SetGridGeo( double dSnapStep, int nMinLineSstep, int nMajLineSstep, int nExtSstep) ; + virtual bool SetGridColor( Color colMinLine, Color colMajLine) ; + virtual const Frame3d& GetGridFrame( void) + { return m_frGrid ; } // Direct virtual bool SetGeoLineAttribs( Color GLcol) ; virtual bool SetGeoLine( const Point3d& ptP1, const Point3d& ptP2) ; @@ -112,7 +120,7 @@ class Scene : public IEGrScene virtual bool SetWinRect( const Point3d& ptWinRectP1, const Point3d& ptWinRectP2) ; virtual bool ResetWinRect( void) ; // Snap - virtual bool GetSelectedSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH, Point3d& ptSel) ; + virtual bool GetGraphicSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH, Point3d& ptSel) ; public : // Basic @@ -144,11 +152,15 @@ class Scene : public IEGrScene bool DrawGroup( const IGdbIterator& iIter, int nPass, MdStMk siParent) ; bool DrawGeoObj( const IGdbIterator& iIter, int nPass, MdStMk siObj) ; bool DeleteObjGraphicsGroup( int nId) ; + // Grid + bool DrawGrid( void) ; // Direct bool DrawDirect( void) ; bool DrawGeoLine( void) ; bool DrawWinRect( void) ; // Snap + bool GetGridSnapPoint( int nSnap, const Point3d& ptWin, Point3d& ptSel) ; + bool GetSelectedSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH, Point3d& ptSel) ; bool VerifySnapPoint( const Point3d& ptP, const Point3d& ptWin, double& dMinSqDist) ; @@ -180,7 +192,7 @@ class Scene : public IEGrScene int m_nSelH ; // altezza finestra di selezione int m_nSelNbr ; // numero di selezioni registrate int m_nSelCurr ; // indice oggetto selezionato corrente - static const int DIM_SEL_BUF = 4096 ; + static const int DIM_SEL_BUF = 32768 ; SelRec m_nSelBuff[DIM_SEL_BUF] ; // buffer per selezione con OpenGL IGeomDB* m_pGeomDB ; // puntatore al DB geometrico @@ -195,6 +207,16 @@ class Scene : public IEGrScene double m_dZNear ; // distanza del piano di clipping vicino double m_dZFar ; // distanza del piano di clipping lontano + bool m_bShowGrid ; // flag di visualizzazione della griglia + bool m_bShowFrame ; // flag di visualizzazione del frame della griglia + Frame3d m_frGrid ; // riferimento della griglia + double m_dSnapStep ; // passo di snap + int m_nMinLineSstep ; // interasse tra due linee minori come numero di passi di snap + int m_nMajLineSstep ; // interasse tra due linee maggiori come numero di passi di snap + int m_nExtSstep ; // estensione della griglia come numero di passi di snap + Color m_colMinLine ; // colore delle linee minori + Color m_colMajLine ; // colore delle linee maggiori + Color m_colorGL ; // colore per GeoLine bool m_bGeoLine ; // flag esistenza linea diretta in finestra Point3d m_ptGeoLineP1 ; // primo estremo della linea diretta diff --git a/SceneBasic.cpp b/SceneBasic.cpp index da7ed11..f60f604 100644 --- a/SceneBasic.cpp +++ b/SceneBasic.cpp @@ -52,8 +52,8 @@ Scene::Scene( void) m_nViewportW = 0 ; m_nViewportH = 0 ; // Sfondo - m_colBackTop.Set( 128, 128, 128) ; - m_colBackBottom.Set( 128, 128, 128) ; + m_colBackTop.Set( 176, 176, 176) ; + m_colBackBottom.Set( 176, 176, 176) ; // Modalità di visualizzazione m_nShowMode = SM_WIREFRAME ; // Selezione @@ -67,6 +67,16 @@ Scene::Scene( void) // Extension SetExtension( BBox3d( -MIN_EXTENSION, -MIN_EXTENSION, -MIN_EXTENSION, MIN_EXTENSION, MIN_EXTENSION, MIN_EXTENSION)) ; + // Grid + m_bShowGrid = false ; + m_bShowFrame = false ; + m_frGrid = GLOB_FRM ; + m_dSnapStep = 1 ; + m_nMinLineSstep = 10 ; + m_nMajLineSstep = 100 ; + m_nExtSstep = 500 ; + m_colMinLine.Set( 160, 160, 160) ; + m_colMajLine.Set( 160, 160, 160) ; // Direct m_colorGL.Set( 255, 0, 0) ; m_bGeoLine = false ; @@ -649,6 +659,10 @@ Scene::Draw( void) glDepthFunc( GL_LEQUAL) ; glEnable( GL_DEPTH_TEST) ; + // disegno griglia + glDisable( GL_LIGHTING) ; + DrawGrid() ; + // aggiorno il colore di default if ( m_pGeomDB != nullptr) m_pGeomDB->GetDefaultMaterial( m_colDef) ; @@ -761,10 +775,17 @@ Scene::Select( const Point3d& ptSelCenter, int nW, int nH, int& nSel) // inizializzo selezione m_bSelect = true ; m_ptSelCent = ptSelCenter ; - m_nSelW = nW ; - m_nSelH = nH ; + m_nSelW = abs( nW) ; + m_nSelH = abs( nH) ; m_nSelNbr = 0 ; + // se una delle due dimensioni è nulla, non posso selezionare alcunché + if ( m_nSelW == 0 || m_nSelH == 0) { + m_bSelect = false ; + nSel = m_nSelNbr ; + return true ; + } + // sfondo e Zbuffer non interessano // imposto la camera, riducendo la viewport all'area di selezione diff --git a/SceneGeom.cpp b/SceneGeom.cpp index 1b3802e..08ed5be 100644 --- a/SceneGeom.cpp +++ b/SceneGeom.cpp @@ -16,6 +16,7 @@ #include "Scene.h" #include "ObjOldGraphics.h" #include "ObjNewGraphics.h" +#include "EGrUtils.h" #include "/EgtDev/Include/EgtILogger.h" #include "/EgtDev/Include/EGnStringUtils.h" #include "/EgtDev/Include/EGkFrame3d.h" @@ -31,11 +32,7 @@ using namespace std ; -//------------------------------ Constants ----------------------------------- -const int OGLMAT_DIM = 16 ; - //------------------------------ Local functions ----------------------------- -static bool FrameToOpenGlMatrix( const Frame3d& frFrame, double Matrix[OGLMAT_DIM]) ; static ObjEGrGraphics* CreateObjEGrGraphics( bool bNewWay) ; static bool CalcCurveTipArrow( const PolyLine& plCrv, PolyLine& plArr) ; static bool CalcConnectingLines( const PolyLine& plCrv, const Vector3d& vtTh, bool bDense, PNTVECTOR& vPnt) ; @@ -214,7 +211,7 @@ Scene::DrawGeoObj( const IGdbIterator& iIter, int nPass, MdStMk siObj) pGraphics->Clear() ; pGraphics->AddColor( RED) ; pGraphics->AddPolyLine( plX) ; - pGraphics->AddColor( GREEN) ; + pGraphics->AddColor( LIME) ; pGraphics->AddPolyLine( plY) ; pGraphics->AddColor( BLUE) ; pGraphics->AddPolyLine( plZ) ; @@ -364,33 +361,6 @@ Scene::DeleteObjGraphicsGroup( int nId) } //------------------------------ Local functions ----------------------------- -//---------------------------------------------------------------------------- -static bool -FrameToOpenGlMatrix( const Frame3d& frFrame, double Matrix[OGLMAT_DIM]) -{ - if ( frFrame.GetType() == Frame3d::ERR) - return false ; - - Matrix[0] = frFrame.VersX().x ; - Matrix[1] = frFrame.VersX().y ; - Matrix[2] = frFrame.VersX().z ; - Matrix[3] = 0 ; - Matrix[4] = frFrame.VersY().x ; - Matrix[5] = frFrame.VersY().y ; - Matrix[6] = frFrame.VersY().z ; - Matrix[7] = 0 ; - Matrix[8] = frFrame.VersZ().x ; - Matrix[9] = frFrame.VersZ().y ; - Matrix[10] = frFrame.VersZ().z ; - Matrix[11] = 0 ; - Matrix[12] = frFrame.Orig().x ; - Matrix[13] = frFrame.Orig().y ; - Matrix[14] = frFrame.Orig().z ; - Matrix[15] = 1 ; - - return true ; -} - //---------------------------------------------------------------------------- static ObjEGrGraphics* CreateObjEGrGraphics( bool bNewWay) diff --git a/SceneGrid.cpp b/SceneGrid.cpp new file mode 100644 index 0000000..7470db5 --- /dev/null +++ b/SceneGrid.cpp @@ -0,0 +1,167 @@ +//---------------------------------------------------------------------------- +// EgalTech 2014-2014 +//---------------------------------------------------------------------------- +// File : SceneGrid.cpp Data : 25.10.14 Versione : 1.5j6 +// Contenuto : Implementazione snap di punti trmite selezione. +// +// +// +// Modifiche : 25.10.14 DS Creazione modulo. +// +// +//---------------------------------------------------------------------------- + +//--------------------------- Include ---------------------------------------- +#include "stdafx.h" +#include "Scene.h" +#include "EGrUtils.h" + + +using namespace std ; + +//---------------------------------------------------------------------------- +bool +Scene::SetGridShow( bool bShowGrid, bool bShowFrame) +{ + m_bShowGrid = bShowGrid ; + m_bShowFrame = bShowFrame ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Scene::SetGridFrame( const Frame3d& frFrame) +{ + if ( ! frFrame.IsValid()) + return false ; + m_frGrid = frFrame ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Scene::SetGridGeo( double dSnapStep, int nMinLineSstep, int nMajLineSstep, int nExtSstep) +{ + const double MIN_SNAP_STEP = 0.1 ; + m_dSnapStep = max( fabs( dSnapStep), MIN_SNAP_STEP) ; + m_nMinLineSstep = abs( nMinLineSstep) ; + m_nMajLineSstep = abs( nMajLineSstep) ; + m_nExtSstep = abs( nExtSstep) ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Scene::SetGridColor( Color colMinLine, Color colMajLine) +{ + m_colMinLine = colMinLine ; + m_colMajLine = colMajLine ; + return true ; +} + +//---------------------------------------------------------------------------- +bool +Scene::DrawGrid( void) +{ + // se non devo disegnare, esco subito + if ( ! m_bShowGrid && ! m_bShowFrame) + return true ; + + // imposto il riferimento + glPushMatrix() ; + double Matrix[OGLMAT_DIM] ; + if ( FrameToOpenGlMatrix( m_frGrid, Matrix)) + glMultMatrixd( Matrix) ; + + // semi-estensione della griglia + float dExt = float( m_nExtSstep * m_dSnapStep) ; + // abbassamento in Z per evitare sovrapposizioni con geometria + const float Z_DOWN = float( - 0.01) ; + + // se richiesto, disegno la griglia + if ( m_bShowGrid) { + // disegno linee minori (a trattini) + glLineStipple( 2, 0xAAAA) ; + glEnable( GL_LINE_STIPPLE) ; + glBegin( GL_LINES) ; + glColor3f( m_colMinLine.GetRed(), m_colMinLine.GetGreen(), m_colMinLine.GetBlue()) ; + for ( int i = m_nMinLineSstep ; i <= m_nExtSstep ; i += m_nMinLineSstep) { + // se non si sovrappongono alle maggiori + if ( ( i % m_nMajLineSstep) != 0) { + float dPos = float( i * m_dSnapStep) ; + // X + + glVertex3f( dPos, - dExt, Z_DOWN) ; + glVertex3f( dPos, dExt, Z_DOWN) ; + // X - + glVertex3f( - dPos, - dExt, Z_DOWN) ; + glVertex3f( - dPos, dExt, Z_DOWN) ; + // Y + + glVertex3f( - dExt, dPos, Z_DOWN) ; + glVertex3f( dExt, dPos, Z_DOWN) ; + // Y - + glVertex3f( - dExt, - dPos, Z_DOWN) ; + glVertex3f( dExt, - dPos, Z_DOWN) ; + } + } + glEnd() ; + glDisable( GL_LINE_STIPPLE) ; + // disegno linee maggiori + glBegin( GL_LINES) ; + glColor3f( m_colMajLine.GetRed(), m_colMajLine.GetGreen(), m_colMajLine.GetBlue()) ; + for ( int i = m_nMajLineSstep ; i <= m_nExtSstep ; i += m_nMajLineSstep) { + float dPos = float( i * m_dSnapStep) ; + // X + + glVertex3f( dPos, - dExt, Z_DOWN) ; + glVertex3f( dPos, dExt, Z_DOWN) ; + // X - + glVertex3f( - dPos, - dExt, Z_DOWN) ; + glVertex3f( - dPos, dExt, Z_DOWN) ; + // Y + + glVertex3f( - dExt, dPos, Z_DOWN) ; + glVertex3f( dExt, dPos, Z_DOWN) ; + // Y - + glVertex3f( - dExt, - dPos, Z_DOWN) ; + glVertex3f( dExt, - dPos, Z_DOWN) ; + } + glEnd() ; + } + + // se richiesto, disegno assi del frame + if ( m_bShowFrame) { + glBegin( GL_LINES) ; + // asse X+ + glColor3f( RED.GetRed(), RED.GetGreen(), RED.GetBlue()) ; + glVertex3f( 0, 0, Z_DOWN) ; + glVertex3f( dExt, 0, Z_DOWN) ; + // asse Y+ + glColor3f( LIME.GetRed(), LIME.GetGreen(), LIME.GetBlue()) ; + glVertex3f( 0, 0, Z_DOWN) ; + glVertex3f( 0, dExt, Z_DOWN) ; + // se richiesta griglia, assi X- e Y- + if ( m_bShowGrid) { + glColor3f( m_colMajLine.GetRed(), m_colMajLine.GetGreen(), m_colMajLine.GetBlue()) ; + glVertex3f( 0, 0, Z_DOWN) ; + glVertex3f( -dExt, 0, Z_DOWN) ; + glVertex3f( 0, 0, Z_DOWN) ; + glVertex3f( 0, -dExt, Z_DOWN) ; + } + glEnd() ; + } + // altrimenti, se richiesta sola griglia li disegno come linee principali + else if ( m_bShowGrid) { + glBegin( GL_LINES) ; + glColor3f( m_colMajLine.GetRed(), m_colMajLine.GetGreen(), m_colMajLine.GetBlue()) ; + // asse X + glVertex3f( - dExt, 0, Z_DOWN) ; + glVertex3f( dExt, 0, Z_DOWN) ; + // asse Y + glVertex3f( 0, - dExt, Z_DOWN) ; + glVertex3f( 0, dExt, Z_DOWN) ; + glEnd() ; + } + + // ripristino lo stack delle matrici + glPopMatrix() ; + + return true ; +} \ No newline at end of file diff --git a/SceneSnap.cpp b/SceneSnap.cpp index cd0d821..fc5d316 100644 --- a/SceneSnap.cpp +++ b/SceneSnap.cpp @@ -25,10 +25,56 @@ using namespace std ; +//---------------------------------------------------------------------------- +bool +Scene::GetGraphicSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH, Point3d& ptSel) +{ + // se Snap Sketch o Grid, devo trovare il punto sulla griglia + if ( nSnap == SP_SKETCH || nSnap == SP_GRID) + return GetGridSnapPoint( nSnap, ptWin, ptSel) ; + // altrimenti devo trovare il punto dall'entità inquadrata + else + return GetSelectedSnapPoint( nSnap, ptWin, nW, nH, ptSel) ; +} + +//---------------------------------------------------------------------------- +bool +Scene::GetGridSnapPoint( int nSnap, const Point3d& ptWin, Point3d& ptSel) +{ + // calcolo un punto e la direzione della linea di mira + Point3d ptLine ; + if ( ! UnProject( ptWin, ptLine)) + return false ; + Vector3d vtLine = - m_vtDirCamera ; + + // determino l'intersezione di questa linea con il piano della griglia + double dDenom = vtLine * m_frGrid.VersZ() ; + if ( fabs( dDenom) < COS_ORTO_ANG_SMALL) + return false ; + double dU = ( ( m_frGrid.Orig() - ptLine) * m_frGrid.VersZ()) / dDenom ; + ptSel = ptLine + dU * vtLine ; + + // porto il punto sul piano di griglia + ptSel.ToLoc( m_frGrid) ; + // se punto grid, devo arrotondare al nodo di griglia più vicino + if ( nSnap == SP_GRID) { + ptSel.x = floor( ptSel.x / m_dSnapStep + 0.5) * m_dSnapStep ; + ptSel.y = floor( ptSel.y / m_dSnapStep + 0.5) * m_dSnapStep ; + } + // il punto deve stare sulla griglia + ptSel.z = 0 ; + // lo riporto in globale + ptSel.ToGlob( m_frGrid) ; + return true ; +} + //---------------------------------------------------------------------------- bool Scene::GetSelectedSnapPoint( int nSnap, const Point3d& ptWin, int nW, int nH, Point3d& ptSel) { + // se Snap Sketch o Grid, devo trovare il punto sulla griglia + if ( nSnap == SP_SKETCH || nSnap == SP_GRID) + return GetGridSnapPoint( nSnap, ptWin, ptSel) ; // verifico siano state selezionate delle entità int nSel ; Select( ptWin, nW, nH, nSel) ; @@ -230,4 +276,4 @@ Scene::VerifySnapPoint( const Point3d& ptP, const Point3d& ptWin, double& dMinSq return true ; } return false ; -} \ No newline at end of file +}