EgtGraphics 1.5j1 :

- aggiunta gestione selezione con mouse
- aggiunta gestione selezione punti notevoli (snap points).
This commit is contained in:
Dario Sassi
2014-10-10 06:36:30 +00:00
parent 13bf590449
commit 3c0d573c46
8 changed files with 386 additions and 32 deletions
+131 -5
View File
@@ -56,6 +56,9 @@ Scene::Scene( void)
m_colBackBottom.Set( 128, 128, 128) ;
// Modalità di visualizzazione
m_nShowMode = SM_WIREFRAME ;
// Selezione
m_bSelect = false ;
m_nSelCurr = - 1 ;
// GeomData
m_pGeomDB = nullptr ;
m_colDef.Set( 0, 0, 0) ;
@@ -63,7 +66,9 @@ Scene::Scene( void)
// Extension
SetExtension( BBox3d( -MIN_EXTENSION, -MIN_EXTENSION, -MIN_EXTENSION,
MIN_EXTENSION, MIN_EXTENSION, MIN_EXTENSION)) ;
// WinRect
// Direct
m_colorGL.Set( 0, 0, 0) ;
m_bGeoLine = false ;
m_bOutlineWR = true ;
m_colorWR.Set( 0, 0, 0) ;
m_bWinRect = false ;
@@ -600,6 +605,13 @@ Scene::Prepare( void)
// imposto matrice di proiezione
glMatrixMode( GL_PROJECTION) ;
glLoadIdentity() ;
if ( m_bSelect) {
// recupero viewport
GLint Viewport[4] ;
glGetIntegerv( GL_VIEWPORT, Viewport) ;
// imposto area di pick
gluPickMatrix( m_ptSelCent.x, ( Viewport[3] - m_ptSelCent.y), m_nSelW, m_nSelH, Viewport) ;
}
glOrtho( - m_dHalfWidth, m_dHalfWidth, - m_dHalfHeight, m_dHalfHeight, m_dZNear, m_dZFar) ;
// imposto matrice modello/vista
@@ -704,7 +716,7 @@ Scene::Draw( void)
glDisable( GL_DEPTH_TEST) ;
glDisable( GL_LIGHTING) ;
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL) ;
DrawWinRect() ;
DrawDirect() ;
// aggiorno
glFlush() ;
@@ -723,6 +735,120 @@ Scene::Draw( void)
return true ;
}
//----------------------------------------------------------------------------
int
CompareSelRec( const void* pSr1, const void* pSr2)
{
if ( ((SelRec*)pSr1)->nZmin > ((SelRec*)pSr2)->nZmin)
return 1 ;
else if ( ((SelRec*)pSr1)->nZmin < ((SelRec*)pSr2)->nZmin)
return - 1 ;
else {
if ( ((SelRec*)pSr1)->nId > ((SelRec*)pSr2)->nId)
return 1 ;
else if ( ((SelRec*)pSr1)->nId < ((SelRec*)pSr2)->nId)
return - 1 ;
else
return 0 ;
}
}
//----------------------------------------------------------------------------
bool
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_nSelNbr = 0 ;
// sfondo e Zbuffer non interessano
// imposto la camera, riducendo la viewport all'area di selezione
if ( ! Prepare()) {
m_bSelect = false ;
nSel = m_nSelNbr ;
return false ;
}
// imposto modalità di selezione
glSelectBuffer( DIM_SEL_BUF, (GLuint*)m_nSelBuff) ;
glRenderMode( GL_SELECT) ;
// inizializzo stack dei nomi
glInitNames() ;
glPushName( 0) ;
// eseguo disegno
// disabilito illuminazione
glDisable( GL_LIGHTING) ;
// non imposto glPolygonMode secondo il tipo di rendering perchè ignorato in selezione
// disegno le geometrie del DB in una sola passata
DrawGroup( GDB_ID_ROOT, 1, MdStMk( GDB_MD_STD, GDB_ST_ON, GDB_MK_OFF)) ;
// pulisco stack nomi
glPopName() ;
// chiudo modalità selezione, recupero buffer ripristino le matrici di OpenGL
m_nSelNbr = glRenderMode( GL_RENDER) ;
if ( m_nSelNbr < 0)
m_nSelNbr = DIM_SEL_BUF ;
m_bSelect = false ;
Prepare() ;
// riordino il buffer di selezione secondo la Zdepth minima crescente
qsort( m_nSelBuff, m_nSelNbr, sizeof( SelRec), CompareSelRec) ;
nSel = m_nSelNbr ;
return true ;
}
//----------------------------------------------------------------------------
bool
Scene::GetSelectedObjs( INTVECTOR& nIds)
{
// inizializzo vettore Id
nIds.clear() ;
try { nIds.reserve( m_nSelNbr) ; }
catch(...) { return false ; }
// inserisco l'Id degli oggetti selezionati
for ( int i = 0 ; i < m_nSelNbr ; ++ i)
nIds.push_back( m_nSelBuff[i].nId) ;
return true ;
}
//----------------------------------------------------------------------------
int
Scene::GetFirstSelectedObj( void)
{
m_nSelCurr = - 1 ;
return GetNextSelectedObj() ;
}
//----------------------------------------------------------------------------
int
Scene::GetNextSelectedObj( void)
{
// fuori dal range
m_nSelCurr ++ ;
if ( m_nSelCurr < 0 || m_nSelCurr >= m_nSelNbr)
return GDB_ID_NULL ;
return m_nSelBuff[m_nSelCurr].nId ;
}
//----------------------------------------------------------------------------
double
Scene::GetSelectedObjWinZ( int nSel)
{
if ( nSel < 0)
nSel = m_nSelCurr ;
if ( nSel < 0 || nSel >= m_nSelNbr)
return 0.5 ;
return 0.5 * ( double( m_nSelBuff[nSel].nZmin) + double( m_nSelBuff[nSel].nZmax)) / UINT_MAX ;
}
/*------------------------------------------------------------------------------------------*/
bool
Scene::Project( const Point3d& ptWorld, Point3d& ptView)
@@ -741,9 +867,9 @@ Scene::Project( const Point3d& ptWorld, Point3d& ptView)
// eseguo la proiezione
// l'asse y della vista OpenGL va in alto con l'origine in basso,
// quello di Windows va in basso con l'origine in alto
int nRes =gluProject( ptWorld.x, ptWorld.y, ptWorld.z,
ModelView, Projection, Viewport,
&ptView.x, &ptView.y, &ptView.z) ;
int nRes = gluProject( ptWorld.x, ptWorld.y, ptWorld.z,
ModelView, Projection, Viewport,
&ptView.x, &ptView.y, &ptView.z) ;
ptView.y = (double) Viewport[3] - ptView.y ;
return ( nRes == GL_TRUE) ;