Merge commit '5fe0c3e3768b481137a3f90f5ad342d039130c6a' into ThreeJS
This commit is contained in:
+52
-26
@@ -15,6 +15,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "Scene.h"
|
||||
#include "EGrUtils.h"
|
||||
#include "/EgtDev/Include/EgtNumUtils.h"
|
||||
#include <algorithm>
|
||||
|
||||
using namespace std ;
|
||||
@@ -35,8 +36,8 @@ Scene::SetGridGeo( double dSnapStep, int nMinLineSstep, int nMajLineSstep, int n
|
||||
const double MIN_SNAP_STEP = 0.1 ;
|
||||
m_dSnapStep = max( abs( dSnapStep), MIN_SNAP_STEP) ;
|
||||
m_nMinLineSstep = abs( nMinLineSstep) ;
|
||||
m_nMajLineSstep = abs( nMajLineSstep) ;
|
||||
m_nExtSstep = abs( nExtSstep) ;
|
||||
m_nMajLineSstep = max( abs( nMajLineSstep), m_nMinLineSstep) ;
|
||||
m_nExtSstep = max( abs( nExtSstep), m_nMajLineSstep) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
@@ -49,6 +50,26 @@ Scene::SetGridColor( Color colMinLine, Color colMajLine)
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static int
|
||||
GetSpecialCoeff( double dVal)
|
||||
{
|
||||
if ( dVal < 1.99)
|
||||
return 1 ;
|
||||
else if ( dVal < 4.99)
|
||||
return 2 ;
|
||||
else if ( dVal < 9.99)
|
||||
return 5 ;
|
||||
else if ( dVal < 24.99)
|
||||
return 10 ;
|
||||
else if ( dVal < 49.99)
|
||||
return 25 ;
|
||||
else if ( dVal < 99.99)
|
||||
return 50 ;
|
||||
else
|
||||
return 100 ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
bool
|
||||
Scene::DrawGrid( void)
|
||||
@@ -73,35 +94,40 @@ Scene::DrawGrid( void)
|
||||
|
||||
// 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) ;
|
||||
// disegno linee minori (a trattini), se non troppe
|
||||
double dMinRapp = min( m_dHalfWidth, m_dHalfHeight) / ( m_dSnapStep * m_nMinLineSstep) ;
|
||||
if ( dMinRapp < 60) {
|
||||
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) ;
|
||||
}
|
||||
glEnd() ;
|
||||
glDisable( GL_LINE_STIPPLE) ;
|
||||
// disegno linee maggiori
|
||||
double dMaxRapp = min( m_dHalfWidth, m_dHalfHeight) / ( m_dSnapStep * m_nMajLineSstep) ;
|
||||
int nCoeff = GetSpecialCoeff( 0.06 * dMaxRapp) ;
|
||||
glBegin( GL_LINES) ;
|
||||
glColor3f( m_colMajLine.GetRed(), m_colMajLine.GetGreen(), m_colMajLine.GetBlue()) ;
|
||||
for ( int i = m_nMajLineSstep ; i <= m_nExtSstep ; i += m_nMajLineSstep) {
|
||||
for ( int i = min( nCoeff * m_nMajLineSstep, m_nExtSstep) ; i <= m_nExtSstep ; i += nCoeff * m_nMajLineSstep) {
|
||||
float dPos = float( i * m_dSnapStep) ;
|
||||
// X +
|
||||
glVertex3f( dPos, - dExt, Z_DOWN) ;
|
||||
|
||||
Reference in New Issue
Block a user