Commit 6df7a863 authored by Dirk Wilden's avatar Dirk Wilden
Browse files

added stuff to show a grid in all viewers

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@6795 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 3ec79dfe
......@@ -56,7 +56,7 @@
#include "SceneGraph.hh"
#include "../GL/gl.hh"
#include <stdio.h>
#include <math.h>
//== NAMESPACES ===============================================================
......@@ -71,9 +71,15 @@ namespace SceneGraph {
GridNode::
GridNode(BaseNode* _parent, const std::string& _name)
: MaterialNode(_parent, _name),
horizontalLines_(10),
verticalLines_(10)
horizontalLines_(7),
verticalLines_(7),
width_(1500.0),
height_(1500.0)
{
baseLineColor_ = Vec3f(0.5, 0.5, 0.5);
midLineColor_ = Vec3f(0.3, 0.3, 0.3);
bb_min_ = Vec3f(-0.5*width_, 0.0, -0.5*height_);
bb_max_ = Vec3f( 0.5*width_, 0.0, 0.5*height_);
}
......@@ -92,10 +98,10 @@ GridNode::availableDrawModes() const
void
GridNode::boundingBox(Vec3f& /*_bbMin*/, Vec3f& /*_bbMax*/)
GridNode::boundingBox(Vec3f& _bbMin, Vec3f& _bbMax)
{
// _bbMin.minimize(bb_min_);
// _bbMax.maximize(bb_max_);
_bbMin.minimize(bb_min_);
_bbMax.maximize(bb_max_);
}
......@@ -110,37 +116,126 @@ GridNode::draw(GLState& _state , unsigned int /* _drawMode */ )
glDisable(GL_LIGHTING);
glPushAttrib( GL_DEPTH_TEST );
glDisable( GL_DEPTH_TEST );
glEnable( GL_DEPTH_TEST );
glLineWidth(0.1);
_state.push_modelview_matrix();
_state.reset_modelview();
_state.push_projection_matrix();
_state.reset_projection();
_state.ortho( 0.0, _state.viewport_width() ,0.0,_state.viewport_height(), -1.0 , 1.0 );
//first we calculate the hitpoint of the camera direction with the grid
GLMatrixd modelview = _state.modelview();
Vec3d viewDirection;
viewDirection[0] = -modelview(0,2);
viewDirection[1] = -modelview(1,2);
viewDirection[2] = -modelview(2,2);
Vec3f eye = (Vec3f) _state.inverse_modelview().transform_point(ACG::Vec3d(0.0, 0.0, 0.0));
double lambda = - (eye[1] / viewDirection[1]);
Vec3f hitPoint;
hitPoint[0] = eye[0] + lambda * viewDirection[0];
hitPoint[1] = 0;
hitPoint[2] = eye[2] + lambda * viewDirection[2];
// _state.translate(hitPoint[0], hitPoint[1], hitPoint[2]);
// glutSolidSphere(10.0, 10, 10 );
// _state.translate(-hitPoint[0], -hitPoint[1], -hitPoint[2]);
//the distance between camera and hitpoint defines a factor that controls
//how many lines are drawn
double distance = _state.modelview().transform_point( hitPoint ).norm();
int factor = floor(2000.0 / distance) - 1;
int vertical = verticalLines_;
int horizontal = horizontalLines_;
if (factor > 0){
// 'factor' times split the grid (split every cell into 4 new cells)
int rest = 0;
for (int i=0; i < factor; i++)
rest -= floor( pow(2, i));
vertical = vertical * floor( pow(2,factor)) + rest;
horizontal = horizontal * floor( pow(2,factor)) + rest;
vertical = std::min(vertical, 65 );
horizontal = std::min(vertical, 65 );
}
//now start drawing
_state.translate(-0.5*width_, 0, -0.5*height_);
glBegin(GL_LINES);
for ( int i = 1 ; i < verticalLines_ ; ++i ) {
glVertex3f(_state.viewport_width() / verticalLines_ * i ,0.0,0.0);
glVertex3f(_state.viewport_width() / verticalLines_ * i ,_state.viewport_height(),0.0);
}
for ( int i = 1 ; i < horizontalLines_ ; ++i ) {
glVertex3f(0.0,0.0 + _state.viewport_height() / horizontalLines_ * i ,0.0);
glVertex3f(_state.viewport_width(),0.0 + _state.viewport_height() / horizontalLines_ * i,0.0);
//red line (x-axis)
glColor3f( 0.7, 0.0, 0.0 );
glVertex3f( 0.0, 0.0, height_*0.5);
glVertex3f(width_, 0.0, height_*0.5);
//blue line (z-axis)
glColor3f( 0.0, 0.0, 0.7 );
glVertex3f(width_*0.5, 0.0, 0.0);
glVertex3f(width_*0.5, 0.0, height_);
//remaining vertical lines
for ( int i = 0 ; i < vertical ; ++i ) {
//first draw a baseLine
glColor3fv( &baseLineColor_[0] );
double big = width_ / (vertical-1) * i;
double next = width_ / (vertical-1) * (i+1);
glVertex3f( big, 0.0, 0.0);
glVertex3f( big, 0.0, height_);
if ( i+1 < vertical)
for (int j=1; j < 10; j++){
//then draw 9 darker lines in between
glColor3fv( &midLineColor_[0] );
double small = big + (next - big) / 10.0 * j;
glVertex3f( small, 0.0, 0.0);
glVertex3f( small, 0.0, height_);
}
}
//remaining horizontal lines
for ( int i = 0 ; i < horizontal; ++i ) {
//first draw a baseline
glColor3fv( &baseLineColor_[0] );
double big = width_ / (vertical-1) * i;
double next = width_ / (vertical-1) * (i+1);
glVertex3f( 0.0, 0.0, height_ / (horizontal-1) * i);
glVertex3f(width_, 0.0, height_ / (horizontal-1) * i);
if ( i+1 < vertical)
for (int j=1; j < 10; j++){
//then draw 9 darker lines in between
glColor3fv( &midLineColor_[0] );
double small = big + (next - big) / 10.0 * j;
glVertex3f( 0.0, 0.0, small);
glVertex3f(width_, 0.0, small);
}
}
glEnd();
_state.pop_projection_matrix();
_state.pop_modelview_matrix();
glPopAttrib( ); // ->Depth test
glPopAttrib( ); // ->Lighting
glLineWidth(1.0);
glPopAttrib( ); // ->Depth test
glPopAttrib( ); // ->Lighting
}
......
......@@ -89,7 +89,6 @@ public:
/// Destructor
~GridNode() {}
/// implement className()
ACG_CLASSNAME(GridNode);
/// return available draw modes
......@@ -102,9 +101,22 @@ public:
private:
/// initial number of baseLines
int horizontalLines_;
int verticalLines_;
/// dimensions of the grid
float width_;
float height_;
/// bounding box
Vec3f bb_min_;
Vec3f bb_max_;
/// colors for the grid
Vec3f baseLineColor_;
Vec3f midLineColor_;
bool ok_;
};
......
......@@ -132,6 +132,8 @@ Core() :
coordsysMaterialNode_ = new ACG::SceneGraph::MaterialNode(root_node_scenegraph_,"Coordsys Material Node");
coordsysNode_ = new ACG::SceneGraph::CoordsysNode(coordsysMaterialNode_,"Core Coordsys Node");
coordsysNode_->setTraverseMode (BaseNode::NodeFirst | BaseNode::SecondPass);
gridNode_ = new ACG::SceneGraph::GridNode(root_node_scenegraph_,"Grid Node");
gridNode_->hide();
// Add ViewMode All
ViewMode* vm = new ViewMode();
......
......@@ -103,6 +103,7 @@
#include <OpenFlipper/Core/PluginInfo.hh>
#include <ACG/Scenegraph/CoordsysNode.hh>
#include <ACG/Scenegraph/GridNode.hh>
//== CLASS DEFINITION =========================================================
......@@ -579,6 +580,9 @@ private:
/// Node for the coordinate system
ACG::SceneGraph::CoordsysNode* coordsysNode_;
/// Node for the grid
ACG::SceneGraph::GridNode* gridNode_;
/** @} */
//===========================================================================
......
......@@ -253,6 +253,13 @@ void Core::readApplicationOptions(INIFile& _ini) {
if ( _ini.get_entry( translation, "Options" , "Translation") )
OpenFlipper::Options::translation(translation);
//============================================================================
// Load the setting for the gridVisibility
//============================================================================
bool visible = false;
if ( _ini.get_entry( visible, "Options" , "GridVisible") )
OpenFlipper::Options::gridVisible(visible);
//============================================================================
// Load the setting for the viewer layout
//============================================================================
......@@ -570,6 +577,7 @@ void Core::writeApplicationOptions(INIFile& _ini) {
_ini.add_entry("Options","DefaultViewerLayout", OpenFlipper::Options::defaultViewerLayout() );
_ini.add_entry("Options","Translation", OpenFlipper::Options::translation() );
_ini.add_entry("Options","GridVisible", OpenFlipper::Options::gridVisible() );
_ini.add_entry("Options","MultiView", OpenFlipper::Options::multiView() );
_ini.add_entry("Options","ViewerCount", OpenFlipper::Options::examinerWidgets() );
......
......@@ -119,6 +119,11 @@ void Core::applyOptions(){
if ( OpenFlipper::Options::multiView() )
coreWidget_->setViewerLayout( OpenFlipper::Options::defaultViewerLayout() );
if ( OpenFlipper::Options::gridVisible() )
gridNode_->show();
else
gridNode_->hide();
//set defaultBackgroundColor
QColor c = OpenFlipper::Options::defaultBackgroundColor() ;
......
......@@ -172,6 +172,9 @@ static int redrawDisabled_ = 0;
/// Set if a drawMode Menu should always be in the context menu
static bool drawModesInContextMenu_ = true;
/// Set if a grid should be drawn in every viewer
static bool gridVisible_ = false;
/// Store the toolbox gui Mode mode
static bool hideToolbox_ = false;
......@@ -729,6 +732,13 @@ void drawModesInContextMenu(bool _show) {
drawModesInContextMenu_ = _show;
}
bool gridVisible() {
return gridVisible_;
}
void gridVisible(bool _visible) {
gridVisible_ = _visible;
}
void multiView( bool _multiView) {
multiView_ = _multiView;
......
......@@ -583,6 +583,14 @@ bool dataDir(QString _dir);
DLLEXPORT
void drawModesInContextMenu(bool _show);
/// Get the flag if a grid should be drawn in every viewer
DLLEXPORT
bool gridVisible();
/// Set the flag if a grid should be drawn in every viewer
DLLEXPORT
void gridVisible(bool _visible);
/** @} */
//===========================================================================
......
......@@ -295,6 +295,8 @@ void OptionsWidget::showEvent ( QShowEvent * /*event*/ ) {
viewerLayout->setCurrentIndex( OpenFlipper::Options::defaultViewerLayout() );
gridVisible->setChecked (OpenFlipper::Options::gridVisible());
if (OpenFlipper::Options::translation() == "en_US")
translation->setCurrentIndex(0);
else if (OpenFlipper::Options::translation() == "de_DE")
......@@ -544,6 +546,7 @@ void OptionsWidget::slotApply() {
}
OpenFlipper::Options::defaultViewerLayout( viewerLayout->currentIndex() );
OpenFlipper::Options::gridVisible( gridVisible->isChecked() );
switch ( translation->currentIndex() ){
case 0 : OpenFlipper::Options::translation("en_US"); break;
......
......@@ -23,7 +23,7 @@
<string/>
</property>
<property name="currentIndex">
<number>0</number>
<number>2</number>
</property>
<property name="usesScrollButtons">
<bool>true</bool>
......@@ -385,6 +385,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="gridVisible">
<property name="toolTip">
<string>show a grid in the back of every viewer</string>
</property>
<property name="text">
<string>Show grid</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_18">
<item>
......
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