diff options
-rw-r--r-- | glview.cc | 25 | ||||
-rw-r--r-- | mainwin.cc | 49 | ||||
-rw-r--r-- | openscad.h | 4 | ||||
-rw-r--r-- | transform.cc | 80 |
4 files changed, 121 insertions, 37 deletions
@@ -23,6 +23,7 @@ #include <QApplication> #include <QWheelEvent> #include <QMouseEvent> +#include <QStatusBar> #define FAR_FAR_AWAY 100000.0 @@ -50,6 +51,8 @@ GLView::GLView(QWidget *parent) : QGLWidget(parent) for (int i = 0; i < 10; i++) shaderinfo[i] = 0; + statusBar = NULL; + setMouseTracking(true); } @@ -317,6 +320,14 @@ void GLView::paintGL() glVertex3d(zlabel_x-3, zlabel_y-3, 0); glVertex3d(zlabel_x+3, zlabel_y+3, 0); glEnd(); } + + if (statusBar) { + QString msg; + msg.sprintf("Viewport: translate = [ %.2f %.2f %.2f ], rotate = [ %.2f %.2f %.2f ], distance = %f", + -object_trans_x, -object_trans_y, -object_trans_z, + fmodf(360 - object_rot_x + 90, 360), fmodf(360 - object_rot_y, 360), fmodf(360 - object_rot_z, 360), viewer_distance); + statusBar->showMessage(msg, 0); + } } void GLView::keyPressEvent(QKeyEvent *event) @@ -346,7 +357,6 @@ void GLView::mousePressEvent(QMouseEvent *event) last_mouse_y = event->globalY(); grabMouse(); setFocus(); - updateGL(); } static void mat_id(double *trg) @@ -394,6 +404,18 @@ void GLView::mouseMoveEvent(QMouseEvent *event) object_rot_y += (this_mouse_x-last_mouse_x) * 0.7; else object_rot_z += (this_mouse_x-last_mouse_x) * 0.7; + while (object_rot_x < 0) + object_rot_x += 360; + while (object_rot_x >= 360) + object_rot_x -= 360; + while (object_rot_y < 0) + object_rot_y += 360; + while (object_rot_y >= 360) + object_rot_y -= 360; + while (object_rot_z < 0) + object_rot_z += 360; + while (object_rot_z >= 360) + object_rot_z -= 360; } else { double mx = +(this_mouse_x-last_mouse_x) * viewer_distance/1000; double my = -(this_mouse_y-last_mouse_y) * viewer_distance/1000; @@ -431,6 +453,5 @@ void GLView::mouseReleaseEvent(QMouseEvent*) { mouse_drag_active = false; releaseMouse(); - updateGL(); } @@ -77,6 +77,7 @@ MainWindow::MainWindow(const char *filename) s2 = new QSplitter(Qt::Vertical, w1); l1->addWidget(s2); screen = new GLView(s2); + screen->statusBar = statusBar(); console = new QTextEdit(s2); QWidget *w2 = new QWidget(w1); @@ -125,6 +126,9 @@ MainWindow::MainWindow(const char *filename) menu->addAction("C&omment", this, SLOT(editComment()), QKeySequence(Qt::CTRL + Qt::Key_D)); menu->addAction("&Uncomment", this, SLOT(editUncomment()), QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D)); menu->addSeparator(); + menu->addAction("Paste viewport translation", this, SLOT(pasteViewportTranslation()), QKeySequence(Qt::CTRL + Qt::Key_T)); + menu->addAction("Paste viewport rotation", this, SLOT(pasteViewportRotation()), QKeySequence(Qt::CTRL + Qt::Key_R)); + menu->addSeparator(); menu->addAction("Zoom In", editor, SLOT(zoomIn()), QKeySequence(Qt::CTRL + Qt::Key_Plus)); menu->addAction("Zoom Out", editor, SLOT(zoomOut()), QKeySequence(Qt::CTRL + Qt::Key_Minus)); } @@ -146,36 +150,36 @@ MainWindow::MainWindow(const char *filename) { QMenu *menu = menuBar()->addMenu("&View"); #ifdef ENABLE_OPENCSG - actViewModeOpenCSG = menu->addAction("OpenCSG", this, SLOT(viewModeOpenCSG())); + actViewModeOpenCSG = menu->addAction("OpenCSG", this, SLOT(viewModeOpenCSG()), QKeySequence(Qt::Key_F9)); actViewModeOpenCSG->setCheckable(true); #endif #ifdef ENABLE_CGAL - actViewModeCGALSurface = menu->addAction("CGAL Surfaces", this, SLOT(viewModeCGALSurface())); - actViewModeCGALGrid = menu->addAction("CGAL Grid Only", this, SLOT(viewModeCGALGrid())); + actViewModeCGALSurface = menu->addAction("CGAL Surfaces", this, SLOT(viewModeCGALSurface()), QKeySequence(Qt::Key_F10)); + actViewModeCGALGrid = menu->addAction("CGAL Grid Only", this, SLOT(viewModeCGALGrid()), QKeySequence(Qt::Key_F11)); actViewModeCGALSurface->setCheckable(true); actViewModeCGALGrid->setCheckable(true); #endif - actViewModeThrownTogether = menu->addAction("Thrown Together", this, SLOT(viewModeThrownTogether())); + actViewModeThrownTogether = menu->addAction("Thrown Together", this, SLOT(viewModeThrownTogether()), QKeySequence(Qt::Key_F12)); actViewModeThrownTogether->setCheckable(true); menu->addSeparator(); - actViewModeShowEdges = menu->addAction("Show Edges", this, SLOT(viewModeShowEdges())); + actViewModeShowEdges = menu->addAction("Show Edges", this, SLOT(viewModeShowEdges()), QKeySequence(Qt::CTRL + Qt::Key_1)); actViewModeShowEdges->setCheckable(true); - actViewModeShowAxis = menu->addAction("Show Axis", this, SLOT(viewModeShowAxis())); + actViewModeShowAxis = menu->addAction("Show Axis", this, SLOT(viewModeShowAxis()), QKeySequence(Qt::CTRL + Qt::Key_2)); actViewModeShowAxis->setCheckable(true); - actViewModeShowCrosshairs = menu->addAction("Show Crosshairs", this, SLOT(viewModeShowCrosshairs())); + actViewModeShowCrosshairs = menu->addAction("Show Crosshairs", this, SLOT(viewModeShowCrosshairs()), QKeySequence(Qt::CTRL + Qt::Key_3)); actViewModeShowCrosshairs->setCheckable(true); actViewModeAnimate = menu->addAction("Animate", this, SLOT(viewModeAnimate())); actViewModeAnimate->setCheckable(true); menu->addSeparator(); - menu->addAction("Top", this, SLOT(viewAngleTop())); - menu->addAction("Bottom", this, SLOT(viewAngleBottom())); - menu->addAction("Left", this, SLOT(viewAngleLeft())); - menu->addAction("Right", this, SLOT(viewAngleRight())); - menu->addAction("Front", this, SLOT(viewAngleFront())); - menu->addAction("Back", this, SLOT(viewAngleBack())); - menu->addAction("Diagonal", this, SLOT(viewAngleDiagonal())); + menu->addAction("Top", this, SLOT(viewAngleTop()), QKeySequence(Qt::CTRL + Qt::Key_4)); + menu->addAction("Bottom", this, SLOT(viewAngleBottom()), QKeySequence(Qt::CTRL + Qt::Key_5)); + menu->addAction("Left", this, SLOT(viewAngleLeft()), QKeySequence(Qt::CTRL + Qt::Key_6)); + menu->addAction("Right", this, SLOT(viewAngleRight()), QKeySequence(Qt::CTRL + Qt::Key_7)); + menu->addAction("Front", this, SLOT(viewAngleFront()), QKeySequence(Qt::CTRL + Qt::Key_8)); + menu->addAction("Back", this, SLOT(viewAngleBack()), QKeySequence(Qt::CTRL + Qt::Key_9)); + menu->addAction("Diagonal", this, SLOT(viewAngleDiagonal()), QKeySequence(Qt::CTRL + Qt::Key_0)); menu->addSeparator(); actViewPerspective = menu->addAction("Perspective", this, SLOT(viewPerspective())); @@ -597,6 +601,23 @@ void MainWindow::editUncomment() editor->setTextCursor(cursor); } +void MainWindow::pasteViewportTranslation() +{ + QTextCursor cursor = editor->textCursor(); + QString txt; + txt.sprintf("[ %.2f %.2f %.2f ]", -screen->object_trans_x, -screen->object_trans_y, -screen->object_trans_z); + cursor.insertText(txt); +} + +void MainWindow::pasteViewportRotation() +{ + QTextCursor cursor = editor->textCursor(); + QString txt; + txt.sprintf("[ %.2f %.2f %.2f ]", + fmodf(360 - screen->object_rot_x + 90, 360), fmodf(360 - screen->object_rot_y, 360), fmodf(360 - screen->object_rot_z, 360)); + cursor.insertText(txt); +} + void MainWindow::actionReloadCompile() { current_win = this; @@ -659,6 +659,8 @@ public: double w_h_ratio; GLint shaderinfo[11]; + QStatusBar *statusBar; + GLView(QWidget *parent = NULL); protected: @@ -735,6 +737,8 @@ private slots: void editUnindent(); void editComment(); void editUncomment(); + void pasteViewportTranslation(); + void pasteViewportRotation(); private slots: void actionReloadCompile(); diff --git a/transform.cc b/transform.cc index 879a026..bc2e426 100644 --- a/transform.cc +++ b/transform.cc @@ -87,34 +87,72 @@ AbstractNode *TransformModule::evaluate(const Context *ctx, const ModuleInstanci if (type == ROTATE) { Value val_a = c.lookup_variable("a"); - Value val_v = c.lookup_variable("v"); - double a = 0, x = 0, y = 0, z = 1; + if (val_a.type == Value::VECTOR) + { + for (int i = 0; i < 3; i++) { + double a; + val_a.vec[i]->getnum(a); + double c = cos(a*M_PI/180.0); + double s = sin(a*M_PI/180.0); + double x = i == 0, y = i == 1, z = i == 2; + double mr[16] = { + x*x*(1-c)+c, + y*x*(1-c)+z*s, + z*x*(1-c)-y*s, + 0, + x*y*(1-c)-z*s, + y*y*(1-c)+c, + z*y*(1-c)+x*s, + 0, + x*z*(1-c)+y*s, + y*z*(1-c)-x*s, + z*z*(1-c)+c, + 0, + 0, 0, 0, 1 + }; + double m[16]; + for (int x = 0; x < 4; x++) + for (int y = 0; y < 4; y++) + { + m[x+y*4] = 0; + for (int i = 0; i < 4; i++) + m[x+y*4] += node->m[i+y*4] * mr[x+i*4]; + } + for (int i = 0; i < 16; i++) + node->m[i] = m[i]; + } + } + else + { + Value val_v = c.lookup_variable("v"); + double a = 0, x = 0, y = 0, z = 1; - val_a.getnum(a); + val_a.getnum(a); - if (val_v.getv3(x, y, z)) { - if (x != 0.0 || y != 0.0 || z != 0.0) { - double sn = 1.0 / sqrt(x*x + y*y + z*z); - x *= sn, y *= sn, z *= sn; - } else { - x = 0, y = 0, z = 1; + if (val_v.getv3(x, y, z)) { + if (x != 0.0 || y != 0.0 || z != 0.0) { + double sn = 1.0 / sqrt(x*x + y*y + z*z); + x *= sn, y *= sn, z *= sn; + } else { + x = 0, y = 0, z = 1; + } } - } - double c = cos(a*M_PI/180.0); - double s = sin(a*M_PI/180.0); + double c = cos(a*M_PI/180.0); + double s = sin(a*M_PI/180.0); - node->m[ 0] = x*x*(1-c)+c; - node->m[ 1] = y*x*(1-c)+z*s; - node->m[ 2] = z*x*(1-c)-y*s; + node->m[ 0] = x*x*(1-c)+c; + node->m[ 1] = y*x*(1-c)+z*s; + node->m[ 2] = z*x*(1-c)-y*s; - node->m[ 4] = x*y*(1-c)-z*s; - node->m[ 5] = y*y*(1-c)+c; - node->m[ 6] = z*y*(1-c)+x*s; + node->m[ 4] = x*y*(1-c)-z*s; + node->m[ 5] = y*y*(1-c)+c; + node->m[ 6] = z*y*(1-c)+x*s; - node->m[ 8] = x*z*(1-c)+y*s; - node->m[ 9] = y*z*(1-c)-x*s; - node->m[10] = z*z*(1-c)+c; + node->m[ 8] = x*z*(1-c)+y*s; + node->m[ 9] = y*z*(1-c)-x*s; + node->m[10] = z*z*(1-c)+c; + } } if (type == TRANSLATE) { |