30ad5bec5c
- aggiornamento a VS2013 - curve marcate ora hanno spessore 2 e evidenziate 4. - gestione riferimento griglia (CPlane) spostata in EgtGeomKernel - aggiunta possibilità di visualizzare piccolo riferimento globale in basso a sinistra. - migliorato snap a intersezione di curve.
157 lines
5.1 KiB
C++
157 lines
5.1 KiB
C++
//----------------------------------------------------------------------------
|
|
// EgalTech 2014-2014
|
|
//----------------------------------------------------------------------------
|
|
// File : SceneGrid.cpp Data : 25.10.14 Versione : 1.5j6
|
|
// Contenuto : Implementazione gestione e disegno griglia.
|
|
//
|
|
//
|
|
//
|
|
// 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::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( GetGridFrame(), 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 ;
|
|
} |