Commit e7e9b102 authored by Frédéric Larue's avatar Frédéric Larue

More control added to the display of the metric grid.

parent 47448b77
...@@ -33,8 +33,10 @@ void MetricGrid::displayGrid( GLViewer *viewer, ...@@ -33,8 +33,10 @@ void MetricGrid::displayGrid( GLViewer *viewer,
alphaZ = std::max( 0.0f, std::min( 1.0f, (alphaZ-0.025f)*10.0f ) ); alphaZ = std::max( 0.0f, std::min( 1.0f, (alphaZ-0.025f)*10.0f ) );
// Display the points representing the current grid scale. // Display the points representing the current grid scale.
glPointSize( 5.0f ); if( m_EnableLabels )
glBegin( GL_POINTS ); {
glPointSize( 5.0f );
glBegin( GL_POINTS );
if( isAxisEnabled(X) ) if( isAxisEnabled(X) )
{ {
glColor4ub( 255, 100, 100, alpha*alphaX ); glColor4ub( 255, 100, 100, alpha*alphaX );
...@@ -53,7 +55,8 @@ void MetricGrid::displayGrid( GLViewer *viewer, ...@@ -53,7 +55,8 @@ void MetricGrid::displayGrid( GLViewer *viewer,
glVertex3d( 0, 0, spacing ); glVertex3d( 0, 0, spacing );
glVertex3d( 0, 0, -spacing ); glVertex3d( 0, 0, -spacing );
} }
glEnd(); glEnd();
}
// display the lines corresponding to the colored axis. // display the lines corresponding to the colored axis.
glLineWidth( 1.5f ); glLineWidth( 1.5f );
...@@ -172,24 +175,27 @@ void MetricGrid::displayGrid( GLViewer *viewer, ...@@ -172,24 +175,27 @@ void MetricGrid::displayGrid( GLViewer *viewer,
glEnd(); glEnd();
// Display labels representing the current grid scale. // Display labels representing the current grid scale.
std::stringstream strStream; if( m_EnableLabels )
strStream << spacing;
QString spacingStr = QString::fromStdString( strStream.str() );
if( isAxisEnabled(X) && QVector3D::dotProduct( QVector3D(spacing,0,0)-camCenter, camFront ) < 0.0f )
{
glColor4ub( 255, 130, 130, alpha*alphaX );
viewer->renderText( spacing, spacing/40.0, spacing/40.0, "X = "+spacingStr, QApplication::font() );
}
if( isAxisEnabled(Y) && QVector3D::dotProduct( QVector3D(0,spacing,0)-camCenter, camFront ) < 0.0f )
{
glColor4ub( 200, 255, 200, alpha*alphaY );
viewer->renderText( spacing/40.0, spacing, spacing/40.0, "Y = "+spacingStr, QApplication::font() );
}
if( isAxisEnabled(Z) && QVector3D::dotProduct( QVector3D(0,0,spacing)-camCenter, camFront ) < 0.0f )
{ {
glColor4ub( 130, 130, 255, alpha*alphaZ ); std::stringstream strStream;
viewer->renderText( spacing/40.0, spacing/40.0, spacing, "Z = "+spacingStr, QApplication::font() ); strStream << spacing;
QString spacingStr = QString::fromStdString( strStream.str() );
if( isAxisEnabled(X) && QVector3D::dotProduct( QVector3D(spacing,0,0)-camCenter, camFront ) < 0.0f )
{
glColor4ub( 255, 130, 130, alpha*alphaX );
viewer->renderText( spacing, spacing/40.0, spacing/40.0, "X = "+spacingStr, QApplication::font() );
}
if( isAxisEnabled(Y) && QVector3D::dotProduct( QVector3D(0,spacing,0)-camCenter, camFront ) < 0.0f )
{
glColor4ub( 200, 255, 200, alpha*alphaY );
viewer->renderText( spacing/40.0, spacing, spacing/40.0, "Y = "+spacingStr, QApplication::font() );
}
if( isAxisEnabled(Z) && QVector3D::dotProduct( QVector3D(0,0,spacing)-camCenter, camFront ) < 0.0f )
{
glColor4ub( 130, 130, 255, alpha*alphaZ );
viewer->renderText( spacing/40.0, spacing/40.0, spacing, "Z = "+spacingStr, QApplication::font() );
}
} }
} }
...@@ -234,18 +240,18 @@ void MetricGrid::display( GLViewer *viewer ) ...@@ -234,18 +240,18 @@ void MetricGrid::display( GLViewer *viewer )
QVector3D front = viewer->frontAxis(); QVector3D front = viewer->frontAxis();
if( std::abs(front.x()) == 1.0f ) if( std::abs(front.x()) == 1.0f )
{ {
m_EnabledGrids = YZ; m_EnabledGrids = m_EnableGridsOnAlignedOrtho? YZ : NONE;
m_EnabledAxis = Y | Z; m_EnabledAxis = m_EnableAxisOnAlignedOrtho? Y|Z : NONE;
} }
else if( std::abs(front.y()) == 1.0f ) else if( std::abs(front.y()) == 1.0f )
{ {
m_EnabledGrids = ZX; m_EnabledGrids = m_EnableGridsOnAlignedOrtho? ZX : NONE;
m_EnabledAxis = Z | X; m_EnabledAxis = m_EnableAxisOnAlignedOrtho? Z|X : NONE;
} }
else if( std::abs(front.z()) == 1.0f ) else if( std::abs(front.z()) == 1.0f )
{ {
m_EnabledGrids = XY; m_EnabledGrids = m_EnableGridsOnAlignedOrtho? XY : NONE;
m_EnabledAxis = X | Y; m_EnabledAxis = m_EnableAxisOnAlignedOrtho? X|Y : NONE;
} }
} }
......
...@@ -12,15 +12,9 @@ ...@@ -12,15 +12,9 @@
//#if _WIN32
//#include <windows.h>
//#endif
//#include <GL/gl.h>
class GLViewer; class GLViewer;
class MetricGrid class MetricGrid
{ {
/******************\ /******************\
...@@ -49,6 +43,9 @@ public: ...@@ -49,6 +43,9 @@ public:
private: private:
int m_EnabledGrids; int m_EnabledGrids;
int m_EnabledAxis; int m_EnabledAxis;
bool m_EnableLabels;
bool m_EnableAxisOnAlignedOrtho;
bool m_EnableGridsOnAlignedOrtho;
/*****************************\ /*****************************\
| Constructor(s) / destructor | | Constructor(s) / destructor |
...@@ -56,13 +53,19 @@ private: ...@@ -56,13 +53,19 @@ private:
public: public:
inline MetricGrid() : inline MetricGrid() :
m_EnabledGrids(NONE), m_EnabledGrids(NONE),
m_EnabledAxis(ALL) m_EnabledAxis(ALL),
{} m_EnableLabels(true),
m_EnableAxisOnAlignedOrtho(true),
m_EnableGridsOnAlignedOrtho(true)
{}
inline MetricGrid( int enabledGrids, inline MetricGrid( int enabledGrids,
int enabledAxis ) : int enabledAxis ) :
m_EnabledGrids(enabledGrids), m_EnabledGrids(enabledGrids),
m_EnabledAxis(enabledAxis) m_EnabledAxis(enabledAxis),
{} m_EnableLabels(true),
m_EnableAxisOnAlignedOrtho(true),
m_EnableGridsOnAlignedOrtho(true)
{}
/********************\ /********************\
| Member function(s) | | Member function(s) |
...@@ -73,13 +76,25 @@ private: ...@@ -73,13 +76,25 @@ private:
const GLubyte alpha ); const GLubyte alpha );
public: public:
inline void enableGrid( int gridsToEnable ) { m_EnabledGrids |= gridsToEnable; } inline void enableGrid( int gridsToEnable ) { m_EnabledGrids |= gridsToEnable; }
inline void disableGrid( int gridsToDisable ) { m_EnabledGrids &= ~gridsToDisable; } inline void disableGrid( int gridsToDisable ) { m_EnabledGrids &= ~gridsToDisable; }
inline bool isGridEnabled( GridPlane g ) const { return (m_EnabledGrids & g) != 0; } inline bool isGridEnabled( GridPlane g ) const { return (m_EnabledGrids & g) != 0; }
inline void enableAxis( int axisToEnable ) { m_EnabledAxis |= axisToEnable; }
inline void disableAxis( int axisToDisable ) { m_EnabledAxis &= ~axisToDisable; }
inline bool isAxisEnabled( Axis a ) const { return (m_EnabledAxis & a) != 0; }
inline void enableLabels() { m_EnableLabels = true; }
inline void disableLabels() { m_EnableLabels = false; }
inline bool areLabelsEnabled() const { return m_EnableLabels; }
inline void enableAxisOnAlignedOrtho() { m_EnableAxisOnAlignedOrtho = true; }
inline void disableAxisOnAlignedOrtho() { m_EnableAxisOnAlignedOrtho = false; }
inline bool areAxisOnAlignedOrthoEnabled() const { return m_EnableAxisOnAlignedOrtho; }
inline void enableAxis( int axisToEnable ) { m_EnabledAxis |= axisToEnable; } inline void enableGridsOnAlignedOrtho() { m_EnableGridsOnAlignedOrtho = true; }
inline void disableAxis( int axisToDisable ) { m_EnabledAxis &= ~axisToDisable; } inline void disableGridsOnAlignedOrtho() { m_EnableGridsOnAlignedOrtho = false; }
inline bool isAxisEnabled( Axis a ) const { return (m_EnabledAxis & a) != 0; } inline bool areGridsOnAlignedOrthoEnabled() const { return m_EnableGridsOnAlignedOrtho; }
void display( GLViewer *viewer ); void display( GLViewer *viewer );
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment