Wed, 20 Mar 2013 23:46:37 +0200
Make line thickness user-configurable, draw conditional lines dashed, use the bounding box to offset the model so that it is centered properly.
cfgdef.h | file | annotate | diff | comparison | revisions | |
gldraw.cpp | file | annotate | diff | comparison | revisions | |
zz_configDialog.cpp | file | annotate | diff | comparison | revisions | |
zz_configDialog.h | file | annotate | diff | comparison | revisions |
--- a/cfgdef.h Wed Mar 20 23:06:30 2013 +0200 +++ b/cfgdef.h Wed Mar 20 23:46:37 2013 +0200 @@ -26,6 +26,7 @@ SECT (gl, GLRenderer) CFG (str, gl, bgcolor, "Background color", "#CCCCD9") CFG (str, gl, maincolor, "Main color", "#707078") +CFG (int, gl, linethickness, "Line thickness", 1) SECT (lv, ListView) CFG (bool, lv, colorize, "Show colorized polygons in their color in the list view", true) \ No newline at end of file
--- a/gldraw.cpp Wed Mar 20 23:06:30 2013 +0200 +++ b/gldraw.cpp Wed Mar 20 23:46:37 2013 +0200 @@ -25,7 +25,10 @@ #include "bbox.h" #include "colors.h" -#define GL_VERTEX(V) glVertex3d (V.x, V.y, V.z); +#define GL_VERTEX(V) glVertex3d (V.x + g_faObjectOffset[0], \ + V.y + g_faObjectOffset[1], V.z + g_faObjectOffset[2]); + +double g_faObjectOffset[3]; // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * @@ -58,7 +61,9 @@ glEnable (GL_LINE_SMOOTH); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); - glLineWidth (4 * 2.0f); + glLineWidth (gl_linethickness); + + setMouseTracking (true); compileObjects (); } @@ -104,6 +109,8 @@ compileObjects (); paintGL (); swapBuffers (); + + glLineWidth (gl_linethickness); } // ============================================================================= @@ -121,27 +128,23 @@ // ============================================================================= void renderer::paintGL () { glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - printf ("painting..\n"); glMatrixMode (GL_MODELVIEW); glPushMatrix (); glLoadIdentity (); - /* glTranslatef ( (g_BBox.v0.x + g_BBox.v1.x) / -2.0, (g_BBox.v0.y + g_BBox.v1.y) / -2.0, (g_BBox.v0.z + g_BBox.v1.z) / -2.0 ); - */ glTranslatef (0.0f, 0.0f, -5.0f); glTranslatef (0.0f, 0.0f, -fZoom); - // glScalef (0.75f, 1.15f, 0.0f); glRotatef (fRotX, 1.0f, 0.0f, 0.0f); glRotatef (fRotY, 0.0f, 1.0f, 0.0f); - // glRotatef (fRotZ, 0.0f, 0.0f, 1.0f); + glRotatef (fRotZ, 0.0f, 0.0f, 1.0f); glCallList (uObjList); glPopMatrix (); @@ -151,11 +154,13 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void renderer::compileObjects () { - printf ("compile all objects\n"); - uObjList = glGenLists (1); glNewList (uObjList, GL_COMPILE); + g_faObjectOffset[0] = -(g_BBox.v0.x + g_BBox.v1.x) / 2; + g_faObjectOffset[1] = -(g_BBox.v0.y + g_BBox.v1.y) / 2; + g_faObjectOffset[2] = -(g_BBox.v0.z + g_BBox.v1.z) / 2; + if (!g_CurrentFile) { printf ("renderer: no files loaded, cannot compile anything\n"); return; @@ -175,10 +180,10 @@ return; switch (obj->getType ()) { - case OBJ_CondLine: // For now, treat condlines like normal lines. case OBJ_Line: { - glColor3f (0.0f, 0.0f, 0.0f); // Draw all lines black for now + setObjectColor (obj); + // draw lines LDLine* line = static_cast<LDLine*> (obj); glBegin (GL_LINES); @@ -188,6 +193,23 @@ } break; + case OBJ_CondLine: + { + glLineStipple (1, 0x6666); + glEnable (GL_LINE_STIPPLE); + + setObjectColor (obj); + LDCondLine* line = static_cast<LDCondLine*> (obj); + + glBegin (GL_LINES); + for (short i = 0; i < 2; ++i) + GL_VERTEX (line->vaCoords[i]) + glEnd (); + + glDisable (GL_LINE_STIPPLE); + } + break; + case OBJ_Triangle: { LDTriangle* tri = static_cast<LDTriangle*> (obj); @@ -251,8 +273,6 @@ fZoom = clamp (fZoom, 0.01, 100.0); } - printf ("%.3f %.3f %.3f %.3f\n", - fRotX, fRotY, fRotZ, fZoom); lastPos = event->pos(); updateGL (); } \ No newline at end of file
--- a/zz_configDialog.cpp Wed Mar 20 23:06:30 2013 +0200 +++ b/zz_configDialog.cpp Wed Mar 20 23:46:37 2013 +0200 @@ -53,6 +53,13 @@ connect (qGLForegroundButton, SIGNAL (clicked ()), this, SLOT (slot_setGLForeground ())); + qGLLineThicknessLabel = new QLabel ("Line thickness:"); + qGLLineThickness = new QSlider (Qt::Horizontal); + qGLLineThickness->setRange (1, 8); + qGLLineThickness->setSliderPosition (gl_linethickness); + qGLLineThickness->setTickPosition (QSlider::TicksBothSides); + qGLLineThickness->setTickInterval (1); + qLVColorize = new QCheckBox ("Colorize polygons in list view"); qLVColorize->setCheckState (lv_colorize ? Qt::Checked : Qt::Unchecked); @@ -68,9 +75,12 @@ layout->addWidget (qGLForegroundLabel, 1, 2); layout->addWidget (qGLForegroundButton, 1, 3); - layout->addWidget (qLVColorize, 2, 0, 1, 2); + layout->addWidget (qGLLineThicknessLabel, 2, 0); + layout->addWidget (qGLLineThickness, 2, 1); - layout->addWidget (qButtons, 3, 2, 1, 2); + layout->addWidget (qLVColorize, 3, 0, 1, 2); + + layout->addWidget (qButtons, 4, 2, 1, 2); setLayout (layout); setWindowTitle (APPNAME_DISPLAY " - editing settings"); @@ -140,6 +150,8 @@ io_ldpath = dlg.qLDrawPath->text(); lv_colorize = dlg.qLVColorize->checkState() == Qt::Checked; + gl_linethickness = dlg.qGLLineThickness->value (); + // Save the config config::save ();
--- a/zz_configDialog.h Wed Mar 20 23:06:30 2013 +0200 +++ b/zz_configDialog.h Wed Mar 20 23:46:37 2013 +0200 @@ -29,11 +29,12 @@ public: QLabel* qLDrawPathLabel; - QLabel* qGLBackgroundLabel, *qGLForegroundLabel; + QLabel* qGLBackgroundLabel, *qGLForegroundLabel, *qGLLineThicknessLabel; QLineEdit* qLDrawPath; QPushButton* qLDrawPathFindButton; QPushButton* qGLBackgroundButton, *qGLForegroundButton; QCheckBox* qLVColorize; + QSlider* qGLLineThickness; QDialogButtonBox* qButtons;