summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--glview.cc77
-rw-r--r--mainwin.cc27
-rw-r--r--openscad.h4
3 files changed, 93 insertions, 15 deletions
diff --git a/glview.cc b/glview.cc
index eaf061e..ac9b2e5 100644
--- a/glview.cc
+++ b/glview.cc
@@ -36,6 +36,7 @@ GLView::GLView(QWidget *parent) : QGLWidget(parent)
last_mouse_y = 0;
orthomode = false;
+ showaxis = false;
renderfunc = NULL;
renderfunc_vp = NULL;
@@ -201,22 +202,78 @@ void GLView::paintGL()
glRotated(object_rot_z, 0.0, 0.0, 1.0);
glDepthFunc(GL_LESS);
-
-#if 0
- glLineWidth(1);
- glColor3d(0.0, 0.0, 1.0);
- glBegin(GL_LINES);
- glVertex3d(0, 0, 0); glVertex3d(10, 0, 0);
- glVertex3d(0, 0, 0); glVertex3d(0, 10, 0);
- glVertex3d(0, 0, 0); glVertex3d(0, 0, 10);
- glEnd();
-#endif
+ glCullFace(GL_BACK);
+ glDisable(GL_CULL_FACE);
glLineWidth(2);
glColor3d(1.0, 0.0, 0.0);
if (renderfunc)
renderfunc(renderfunc_vp);
+
+ if (showaxis)
+ {
+ glDepthFunc(GL_ALWAYS);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glTranslated(-0.8, -0.8, 0);
+ glOrtho(-w_h_ratio*1000/10, +w_h_ratio*1000/10,
+ -(1/w_h_ratio)*1000/10, +(1/w_h_ratio)*1000/10,
+ -FAR_FAR_AWAY, +FAR_FAR_AWAY);
+ gluLookAt(0.0, -1000, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+ glMatrixMode(GL_MODELVIEW);
+
+ glLineWidth(1);
+ glColor3d(0.0, 0.0, 1.0);
+ glBegin(GL_LINES);
+ glVertex3d(0, 0, 0); glVertex3d(10, 0, 0);
+ glVertex3d(0, 0, 0); glVertex3d(0, 10, 0);
+ glVertex3d(0, 0, 0); glVertex3d(0, 0, 10);
+ glEnd();
+
+ GLdouble mat_model[16];
+ glGetDoublev(GL_MODELVIEW_MATRIX, mat_model);
+
+ GLdouble mat_proj[16];
+ glGetDoublev(GL_PROJECTION_MATRIX, mat_proj);
+
+ GLint viewport[4];
+ glGetIntegerv(GL_VIEWPORT, viewport);
+
+ GLdouble xlabel_x, xlabel_y, xlabel_z;
+ gluProject(12, 0, 0, mat_model, mat_proj, viewport, &xlabel_x, &xlabel_y, &xlabel_z);
+ xlabel_x = round(xlabel_x); xlabel_y = round(xlabel_y);
+
+ GLdouble ylabel_x, ylabel_y, ylabel_z;
+ gluProject(0, 12, 0, mat_model, mat_proj, viewport, &ylabel_x, &ylabel_y, &ylabel_z);
+ ylabel_x = round(ylabel_x); ylabel_y = round(ylabel_y);
+
+ GLdouble zlabel_x, zlabel_y, zlabel_z;
+ gluProject(0, 0, 12, mat_model, mat_proj, viewport, &zlabel_x, &zlabel_y, &zlabel_z);
+ zlabel_x = round(zlabel_x); zlabel_y = round(zlabel_y);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glTranslated(-1, -1, 0);
+ glScaled(2.0/viewport[2], 2.0/viewport[3], 1);
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity();
+
+ glColor3d(0.0, 0.0, 0.0);
+ glBegin(GL_LINES);
+ // X Label
+ glVertex3d(xlabel_x-3, xlabel_y-3, 0); glVertex3d(xlabel_x+3, xlabel_y+3, 0);
+ glVertex3d(xlabel_x-3, xlabel_y+3, 0); glVertex3d(xlabel_x+3, xlabel_y-3, 0);
+ // Y Label
+ glVertex3d(ylabel_x-3, ylabel_y-3, 0); glVertex3d(ylabel_x+3, ylabel_y+3, 0);
+ glVertex3d(ylabel_x-3, ylabel_y+3, 0); glVertex3d(ylabel_x, ylabel_y, 0);
+ // Z Label
+ glVertex3d(zlabel_x-3, zlabel_y-3, 0); glVertex3d(zlabel_x+3, zlabel_y-3, 0);
+ glVertex3d(zlabel_x-3, zlabel_y+3, 0); glVertex3d(zlabel_x+3, zlabel_y+3, 0);
+ glVertex3d(zlabel_x-3, zlabel_y-3, 0); glVertex3d(zlabel_x+3, zlabel_y+3, 0);
+ glEnd();
+ }
}
void GLView::keyPressEvent(QKeyEvent *event)
diff --git a/mainwin.cc b/mainwin.cc
index 4a79de4..2d110a5 100644
--- a/mainwin.cc
+++ b/mainwin.cc
@@ -161,6 +161,8 @@ MainWindow::MainWindow(const char *filename)
menu->addSeparator();
actViewModeShowEdges = menu->addAction("Show Edges", this, SLOT(viewModeShowEdges()));
actViewModeShowEdges->setCheckable(true);
+ actViewModeShowAxis = menu->addAction("Show Axis", this, SLOT(viewModeShowAxis()));
+ actViewModeShowAxis->setCheckable(true);
actViewModeAnimate = menu->addAction("Animate", this, SLOT(viewModeAnimate()));
actViewModeAnimate->setCheckable(true);
@@ -1049,7 +1051,7 @@ void MainWindow::viewModeCGALGrid()
#endif /* ENABLE_CGAL */
-static void renderGLThrownTogetherChain(MainWindow *m, CSGChain *chain, bool highlight, bool background)
+static void renderGLThrownTogetherChain(MainWindow *m, CSGChain *chain, bool highlight, bool background, bool fberror)
{
glDepthFunc(GL_LEQUAL);
QHash<QPair<PolySet*,double*>,int> polySetVisitMark;
@@ -1073,6 +1075,8 @@ static void renderGLThrownTogetherChain(MainWindow *m, CSGChain *chain, bool hig
chain->polysets[i]->render_edges(PolySet::COLORMODE_BACKGROUND);
glEnable(GL_LIGHTING);
}
+ } else if (fberror) {
+ chain->polysets[i]->render_surface(PolySet::COLORMODE_NONE);
} else if (chain->types[i] == CSGTerm::TYPE_DIFFERENCE) {
chain->polysets[i]->render_surface(PolySet::COLORMODE_CUTOUT);
if (showEdges) {
@@ -1095,12 +1099,19 @@ static void renderGLThrownTogetherChain(MainWindow *m, CSGChain *chain, bool hig
static void renderGLThrownTogether(void *vp)
{
MainWindow *m = (MainWindow*)vp;
- if (m->root_chain)
- renderGLThrownTogetherChain(m, m->root_chain, false, false);
+ if (m->root_chain) {
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+ renderGLThrownTogetherChain(m, m->root_chain, false, false, false);
+ glCullFace(GL_FRONT);
+ glColor3ub(255, 0, 255);
+ renderGLThrownTogetherChain(m, m->root_chain, false, false, true);
+ glDisable(GL_CULL_FACE);
+ }
if (m->background_chain)
- renderGLThrownTogetherChain(m, m->background_chain, false, true);
+ renderGLThrownTogetherChain(m, m->background_chain, false, true, false);
if (m->highlights_chain)
- renderGLThrownTogetherChain(m, m->highlights_chain, true, false);
+ renderGLThrownTogetherChain(m, m->highlights_chain, true, false, false);
}
void MainWindow::viewModeThrownTogether()
@@ -1117,6 +1128,12 @@ void MainWindow::viewModeShowEdges()
screen->updateGL();
}
+void MainWindow::viewModeShowAxis()
+{
+ screen->showaxis = actViewModeShowAxis->isChecked();
+ screen->updateGL();
+}
+
void MainWindow::viewModeAnimate()
{
if (actViewModeAnimate->isChecked()) {
diff --git a/openscad.h b/openscad.h
index b12e901..7eecd98 100644
--- a/openscad.h
+++ b/openscad.h
@@ -645,6 +645,8 @@ public:
void *renderfunc_vp;
bool orthomode;
+ bool showaxis;
+
double viewer_distance;
double object_rot_y;
double object_rot_z;
@@ -751,6 +753,7 @@ public:
#endif
QAction *actViewModeThrownTogether;
QAction *actViewModeShowEdges;
+ QAction *actViewModeShowAxis;
QAction *actViewModeAnimate;
QAction *actViewPerspective;
QAction *actViewOrthogonal;
@@ -766,6 +769,7 @@ private slots:
#endif
void viewModeThrownTogether();
void viewModeShowEdges();
+ void viewModeShowAxis();
void viewModeAnimate();
void viewAngleTop();
void viewAngleBottom();
contact: Jan Huwald // Impressum