diff options
author | don bright <hugh.m.bright@gmail.com> | 2013-02-26 04:32:57 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2013-02-26 04:32:57 (GMT) |
commit | 50489c4287d5eabf636c4cc5c558f56ab210bc27 (patch) | |
tree | f5e084bd57ea38b26d8f556c81e5b66839d15ded | |
parent | 86e017ee9a0104dd428abc7ca4c799e34482d003 (diff) |
begin to implement --viewport option, by adding Camera class + children
-rw-r--r-- | src/GLView.cc | 59 | ||||
-rw-r--r-- | src/GLView.h | 36 | ||||
-rw-r--r-- | src/OffscreenView.cc | 13 | ||||
-rw-r--r-- | src/QGLView.cc | 56 | ||||
-rw-r--r-- | src/export.h | 5 | ||||
-rw-r--r-- | src/export_png.cc | 44 | ||||
-rw-r--r-- | src/linalg.h | 53 | ||||
-rw-r--r-- | src/mainwin.cc | 48 | ||||
-rw-r--r-- | src/openscad.cc | 19 |
9 files changed, 206 insertions, 127 deletions
diff --git a/src/GLView.cc b/src/GLView.cc index bec3a31..b01af98 100644 --- a/src/GLView.cc +++ b/src/GLView.cc @@ -14,10 +14,6 @@ GLView::GLView() { - viewer_distance = 500; - object_trans << 0, 0, 0; - camera_eye << 0, 0, 0; - camera_center << 0, 0, 0; showedges = false; showfaces = true; orthomode = false; @@ -56,15 +52,15 @@ void GLView::setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d & PRINT("set gimbal camera not implemented"); } -void GLView::setupGimbalPerspective() +void GLView::setupGimbalCamPerspective() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustum(-w_h_ratio, +w_h_ratio, -(1/w_h_ratio), +(1/w_h_ratio), +10.0, +FAR_FAR_AWAY); - gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); + gluLookAt(0.0, -gcam.viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); } -void GLView::setupGimbalOrtho(double distance, bool offset) +void GLView::setupGimbalCamOrtho(double distance, bool offset) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -74,35 +70,50 @@ void GLView::setupGimbalOrtho(double distance, bool offset) glOrtho(-w_h_ratio*l, +w_h_ratio*l, -(1/w_h_ratio)*l, +(1/w_h_ratio)*l, -FAR_FAR_AWAY, +FAR_FAR_AWAY); - gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); + gluLookAt(0.0, -gcam.viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); } -void GLView::setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d ¢er) +void GLView::setVectorCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d ¢er) { - this->camera_eye = pos; - this->camera_center = center; - viewer_distance = 10*3*(this->camera_center - this->camera_eye).norm(); + vcam.eye = pos; + vcam.center = center; + // FIXME kludge for showAxes to work in VectorCamera mode + gcam.viewer_distance = 10*3*(vcam.center - vcam.eye).norm(); } -void GLView::setupPerspective() +void GLView::setupVectorCamPerspective() { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - double dist = (this->camera_center - this->camera_eye).norm(); + double dist = (vcam.center - vcam.eye).norm(); gluPerspective(45, w_h_ratio, 0.1*dist, 100*dist); } -void GLView::setupOrtho(bool offset) +void GLView::setupVectorCamOrtho(bool offset) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (offset) glTranslated(-0.8, -0.8, 0); - double l = (this->camera_center - this->camera_eye).norm() / 10; + double l = (vcam.center - vcam.eye).norm() / 10; glOrtho(-w_h_ratio*l, +w_h_ratio*l, -(1/w_h_ratio)*l, +(1/w_h_ratio)*l, -FAR_FAR_AWAY, +FAR_FAR_AWAY); } +void GLView::setCamera( Camera &cam ) +{ + // FIXME : use boost::variant, like value.cc does + if (cam.camtype == Camera::NULL_CAMERA) { + return; + } else if (cam.camtype == Camera::GIMBAL_CAMERA) { + GimbalCamera *gc = dynamic_cast<GimbalCamera *>( &cam ); + setGimbalCamera( gc->object_trans, gc->object_rot, gc->viewer_distance ); + } else if (cam.camtype == Camera::VECTOR_CAMERA) { + VectorCamera *vc = dynamic_cast<VectorCamera *>( &cam ); + setVectorCamera( vc->eye, vc->center ); + } +} + #ifdef ENABLE_OPENCSG void GLView::enable_opencsg_shaders() { @@ -286,13 +297,13 @@ void GLView::showSmallaxes() // Small axis cross in the lower left corner glDepthFunc(GL_ALWAYS); - GLView::setupGimbalOrtho(1000,true); + GLView::setupGimbalCamOrtho(1000,true); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glRotated(object_rot.x(), 1.0, 0.0, 0.0); - glRotated(object_rot.y(), 0.0, 1.0, 0.0); - glRotated(object_rot.z(), 0.0, 0.0, 1.0); + glRotated(gcam.object_rot.x(), 1.0, 0.0, 0.0); + glRotated(gcam.object_rot.y(), 0.0, 1.0, 0.0); + glRotated(gcam.object_rot.z(), 0.0, 0.0, 1.0); glLineWidth(1); glBegin(GL_LINES); @@ -355,17 +366,19 @@ void GLView::showSmallaxes() //Restore perspective for next paint if(!orthomode) - GLView::setupGimbalPerspective(); + GLView::setupGimbalCamPerspective(); } void GLView::showAxes() { // Large gray axis cross inline with the model // FIXME: This is always gray - adjust color to keep contrast with background + // FIXME - depends on gimbal camera 'viewer distance'.. how to fix this + // for VectorCamera? glLineWidth(1); glColor3d(0.5, 0.5, 0.5); glBegin(GL_LINES); - double l = viewer_distance/10; + double l = gcam.viewer_distance/10; glVertex3d(-l, 0, 0); glVertex3d(+l, 0, 0); glVertex3d(0, -l, 0); @@ -386,7 +399,7 @@ void GLView::showCrosshairs() glBegin(GL_LINES); for (double xf = -1; xf <= +1; xf += 2) for (double yf = -1; yf <= +1; yf += 2) { - double vd = viewer_distance/20; + double vd = gcam.viewer_distance/20; glVertex3d(-xf*vd, -yf*vd, -vd); glVertex3d(+xf*vd, +yf*vd, +vd); } diff --git a/src/GLView.h b/src/GLView.h index de8f65b..c7803c9 100644 --- a/src/GLView.h +++ b/src/GLView.h @@ -3,15 +3,19 @@ /* GLView: A basic OpenGL rectangle for rendering images. -Inherited by +This class is inherited by *QGLview (for Qt GUI) *OffscreenView (used in tests and for offscreen command-line rendering). -There are two different types of cameras. A 'gimbal' based camera set -using translation & euler-angles (object_trans/object_rot/distance) and a -'plain' camera set using eye-position, 'look at' center point, and 'up' -The camera systems are not totally integrated or interchangable (yet) +There are two different types of cameras (in linalg.h) + +*Gimbal camera - uses Euler Angles, object translation, and viewer distance +*Vector camera - uses 'eye', 'center', and 'up' vectors + +Currently, the two cameras are not kept in sync and there is no way +to switch between them at runtime. QGLView uses GimbalCamera and +OffscreenView uses VectorCamera. */ @@ -24,6 +28,7 @@ The camera systems are not totally integrated or interchangable (yet) #include "system-gl.h" #include <iostream> #include "renderer.h" +#include "linalg.h" #define FAR_FAR_AWAY 100000.0 @@ -39,12 +44,14 @@ public: virtual void paintGL() = 0; void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance); - void setupGimbalPerspective(); - void setupGimbalOrtho(double distance, bool offset=false); + void setupGimbalCamPerspective(); + void setupGimbalCamOrtho(double distance, bool offset=false); - void setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d ¢er); - void setupPerspective(); - void setupOrtho(bool offset=false); + void setVectorCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d ¢er); + void setupVectorCamPerspective(); + void setupVectorCamOrtho(bool offset=false); + + void setCamera( Camera &cam ); void showCrosshairs(); void showAxes(); @@ -55,17 +62,16 @@ public: size_t width; size_t height; - double viewer_distance; double w_h_ratio; bool orthomode; bool showaxes; bool showfaces; bool showedges; bool showcrosshairs; - Eigen::Vector3d object_trans; - Eigen::Vector3d object_rot; - Eigen::Vector3d camera_eye; - Eigen::Vector3d camera_center; + + // fixme -- use boost::variant like in value.cc ?? + VectorCamera vcam; + GimbalCamera gcam; #ifdef ENABLE_OPENCSG GLint shaderinfo[11]; diff --git a/src/OffscreenView.cc b/src/OffscreenView.cc index b074910..9d7584e 100644 --- a/src/OffscreenView.cc +++ b/src/OffscreenView.cc @@ -9,7 +9,6 @@ OffscreenView::OffscreenView(size_t width, size_t height) { - object_rot << 35, 0, 25; this->ctx = create_offscreen_context(width, height); if ( this->ctx == NULL ) throw -1; GLView::initializeGL(); @@ -32,8 +31,8 @@ void OffscreenView::paintGL() { glEnable(GL_LIGHTING); - if (orthomode) setupOrtho(); - else setupPerspective(); + if (orthomode) setupVectorCamOrtho(); + else setupVectorCamPerspective(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -42,11 +41,11 @@ void OffscreenView::paintGL() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - gluLookAt(this->camera_eye[0], this->camera_eye[1], this->camera_eye[2], - this->camera_center[0], this->camera_center[1], this->camera_center[2], + gluLookAt(vcam.eye[0], vcam.eye[1], vcam.eye[2], + vcam.center[0], vcam.center[1], vcam.center[2], 0.0, 0.0, 1.0); - // fixme - showcrosshairs doesnt work with non-gimbal camera + // fixme - showcrosshairs doesnt work with vector camera // if (showcrosshairs) GLView::showCrosshairs(); if (showaxes) GLView::showAxes(); @@ -58,7 +57,7 @@ void OffscreenView::paintGL() glLineWidth(2); glColor3d(1.0, 0.0, 0.0); - //FIXME showSmallAxes wont work with non-gimbal camera + //FIXME showSmallAxes wont work with vector camera //if (showaxes) GLView::showSmallaxes(); if (this->renderer) { diff --git a/src/QGLView.cc b/src/QGLView.cc index 86dd78a..01c6ff0 100644 --- a/src/QGLView.cc +++ b/src/QGLView.cc @@ -65,7 +65,7 @@ static bool running_under_wine = false; void QGLView::init() { - this->object_rot << 35, 0, -25; + gcam.object_rot << 35, 0, -25; this->mouse_drag_active = false; this->statusLabel = NULL; @@ -141,15 +141,15 @@ void QGLView::display_opencsg_warning_dialog() void QGLView::resizeGL(int w, int h) { GLView::resizeGL(w,h); - GLView::setupGimbalPerspective(); + GLView::setupGimbalCamPerspective(); } void QGLView::paintGL() { glEnable(GL_LIGHTING); - if (orthomode) GLView::setupGimbalOrtho(viewer_distance); - else GLView::setupGimbalPerspective(); + if (orthomode) GLView::setupGimbalCamOrtho(gcam.viewer_distance); + else GLView::setupGimbalCamPerspective(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -159,13 +159,13 @@ void QGLView::paintGL() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - glRotated(object_rot.x(), 1.0, 0.0, 0.0); - glRotated(object_rot.y(), 0.0, 1.0, 0.0); - glRotated(object_rot.z(), 0.0, 0.0, 1.0); + glRotated(gcam.object_rot.x(), 1.0, 0.0, 0.0); + glRotated(gcam.object_rot.y(), 0.0, 1.0, 0.0); + glRotated(gcam.object_rot.z(), 0.0, 0.0, 1.0); if (showcrosshairs) GLView::showCrosshairs(); - glTranslated(object_trans.x(), object_trans.y(), object_trans.z()); + glTranslated(gcam.object_trans.x(), gcam.object_trans.y(), gcam.object_trans.z()); if (showaxes) GLView::showAxes(); @@ -190,8 +190,8 @@ void QGLView::paintGL() if (statusLabel) { QString msg; msg.sprintf("Viewport: translate = [ %.2f %.2f %.2f ], rotate = [ %.2f %.2f %.2f ], distance = %.2f", - -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); + -gcam.object_trans.x(), -gcam.object_trans.y(), -gcam.object_trans.z(), + fmodf(360 - gcam.object_rot.x() + 90, 360), fmodf(360 - gcam.object_rot.y(), 360), fmodf(360 - gcam.object_rot.z(), 360), gcam.viewer_distance); statusLabel->setText(msg); } @@ -201,12 +201,12 @@ void QGLView::paintGL() void QGLView::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Plus) { - viewer_distance *= 0.9; + gcam.viewer_distance *= 0.9; updateGL(); return; } if (event->key() == Qt::Key_Minus) { - viewer_distance /= 0.9; + gcam.viewer_distance /= 0.9; updateGL(); return; } @@ -214,7 +214,7 @@ void QGLView::keyPressEvent(QKeyEvent *event) void QGLView::wheelEvent(QWheelEvent *event) { - viewer_distance *= pow(0.9, event->delta() / 120.0); + gcam.viewer_distance *= pow(0.9, event->delta() / 120.0); updateGL(); } @@ -245,25 +245,25 @@ void QGLView::mouseMoveEvent(QMouseEvent *event) ) { // Left button rotates in xz, Shift-left rotates in xy // On Mac, Ctrl-Left is handled as right button on other platforms - object_rot.x() += dy; + gcam.object_rot.x() += dy; if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0) - object_rot.y() += dx; + gcam.object_rot.y() += dx; else - object_rot.z() += dx; + gcam.object_rot.z() += dx; - normalizeAngle(object_rot.x()); - normalizeAngle(object_rot.y()); - normalizeAngle(object_rot.z()); + normalizeAngle(gcam.object_rot.x()); + normalizeAngle(gcam.object_rot.y()); + normalizeAngle(gcam.object_rot.z()); } else { // Right button pans in the xz plane // Middle button pans in the xy plane // Shift-right and Shift-middle zooms if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0) { - viewer_distance += (GLdouble)dy; + gcam.viewer_distance += (GLdouble)dy; } else { - double mx = +(dx) * viewer_distance/1000; - double mz = -(dy) * viewer_distance/1000; + double mx = +(dx) * gcam.viewer_distance/1000; + double mz = -(dy) * gcam.viewer_distance/1000; double my = 0; #if (QT_VERSION < QT_VERSION_CHECK(4, 7, 0)) @@ -279,9 +279,9 @@ void QGLView::mouseMoveEvent(QMouseEvent *event) } Matrix3d aax, aay, aaz, tm3; - aax = Eigen::AngleAxisd(-(object_rot.x()/180) * M_PI, Vector3d::UnitX()); - aay = Eigen::AngleAxisd(-(object_rot.y()/180) * M_PI, Vector3d::UnitY()); - aaz = Eigen::AngleAxisd(-(object_rot.z()/180) * M_PI, Vector3d::UnitZ()); + aax = Eigen::AngleAxisd(-(gcam.object_rot.x()/180) * M_PI, Vector3d::UnitX()); + aay = Eigen::AngleAxisd(-(gcam.object_rot.y()/180) * M_PI, Vector3d::UnitY()); + aaz = Eigen::AngleAxisd(-(gcam.object_rot.z()/180) * M_PI, Vector3d::UnitZ()); tm3 = Matrix3d::Identity(); tm3 = aaz * (aay * (aax * tm3)); @@ -297,9 +297,9 @@ void QGLView::mouseMoveEvent(QMouseEvent *event) 0, 0, 0, 1 ; tm = tm * vec; - object_trans.x() += tm(0,3); - object_trans.y() += tm(1,3); - object_trans.z() += tm(2,3); + gcam.object_trans.x() += tm(0,3); + gcam.object_trans.y() += tm(1,3); + gcam.object_trans.z() += tm(2,3); } } updateGL(); diff --git a/src/export.h b/src/export.h index 77359c1..243d897 100644 --- a/src/export.h +++ b/src/export.h @@ -3,14 +3,15 @@ #include <iostream> #include "Tree.h" +#include "linalg.h" #ifdef ENABLE_CGAL void export_stl(class CGAL_Nef_polyhedron *root_N, std::ostream &output); void export_off(CGAL_Nef_polyhedron *root_N, std::ostream &output); void export_dxf(CGAL_Nef_polyhedron *root_N, std::ostream &output); -void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output); -void export_png_with_opencsg(Tree &tree, std::ostream &output); +void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, Camera &c, std::ostream &output); +void export_png_with_opencsg(Tree &tree, Camera &c, std::ostream &output); #endif diff --git a/src/export_png.cc b/src/export_png.cc index 0626c71..1382693 100644 --- a/src/export_png.cc +++ b/src/export_png.cc @@ -10,7 +10,7 @@ #include "CGAL_renderer.h" #include "cgal.h" -void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output) +void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, Camera &cam, std::ostream &output) { CsgInfo csgInfo; try { @@ -32,15 +32,20 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output) bbox = cgalRenderer.polyset->getBoundingBox(); } - Vector3d center = getBoundingCenter(bbox); - double radius = getBoundingRadius(bbox); + if (cam.camtype == Camera::NULL_CAMERA) { + csgInfo.glview->setCamera( cam ); + } else { + VectorCamera vcam; + vcam.center = getBoundingCenter(bbox); + double radius = getBoundingRadius(bbox); + Vector3d cameradir(1, 1, -0.5); + vcam.eye = vcam.center - radius*2*cameradir; + csgInfo.glview->setCamera( vcam ); + } - Vector3d cameradir(1, 1, -0.5); - Vector3d camerapos = center - radius*2*cameradir; //std::cerr << center << "\n"; //std::cerr << radius << "\n"; - csgInfo.glview->setCamera(camerapos, center); csgInfo.glview->setRenderer(&cgalRenderer); csgInfo.glview->paintGL(); csgInfo.glview->save(output); @@ -51,7 +56,7 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output) #include <opencsg.h> #endif -void export_png_with_opencsg(Tree &tree, std::ostream &output) +void export_png_with_opencsg(Tree &tree, Camera &cam, std::ostream &output) { #ifdef ENABLE_OPENCSG CsgInfo_OpenCSG csgInfo = CsgInfo_OpenCSG(); @@ -71,17 +76,22 @@ void export_png_with_opencsg(Tree &tree, std::ostream &output) OpenCSGRenderer opencsgRenderer(csgInfo.root_chain, csgInfo.highlights_chain, csgInfo.background_chain, csgInfo.glview->shaderinfo); - Vector3d center(0,0,0); - double radius = 1.0; - if (csgInfo.root_chain) { - BoundingBox bbox = csgInfo.root_chain->getBoundingBox(); - center = (bbox.min() + bbox.max()) / 2; - radius = (bbox.max() - bbox.min()).norm() / 2; - } + if (cam.camtype == Camera::NULL_CAMERA) { + csgInfo.glview->setCamera( cam ); + } else { + VectorCamera vcam; + vcam.center << 0,0,0; + double radius = 1.0; + if (csgInfo.root_chain) { + BoundingBox bbox = csgInfo.root_chain->getBoundingBox(); + vcam.center = (bbox.min() + bbox.max()) / 2; + radius = (bbox.max() - bbox.min()).norm() / 2; + } + Vector3d cameradir(1, 1, -0.5); + vcam.eye = vcam.center - radius*1.8*cameradir; + csgInfo.glview->setCamera( vcam ); + } - Vector3d cameradir(1, 1, -0.5); - Vector3d camerapos = center - radius*1.8*cameradir; - csgInfo.glview->setCamera(camerapos, center); csgInfo.glview->setRenderer(&opencsgRenderer); OpenCSG::setContext(0); OpenCSG::setOption(OpenCSG::OffscreenSetting, OpenCSG::FrameBufferObject); diff --git a/src/linalg.h b/src/linalg.h index 1f9ed30..31cd922 100644 --- a/src/linalg.h +++ b/src/linalg.h @@ -40,4 +40,57 @@ public: bool isValid() const { return this->minCoeff() >= 0.0f; } }; + + +// FIXME - for camera, use boost::variant like in value.cc + +#include <vector> + + +class Camera +{ +public: + enum camera_type_e { GIMBAL_CAMERA, VECTOR_CAMERA, NULL_CAMERA } camtype; + Camera() { camtype = NULL_CAMERA; } + virtual ~Camera() {} // only prevent 'not polymorphic' compile error +}; + +class GimbalCamera : public Camera +{ +public: + GimbalCamera() + { + camtype = GIMBAL_CAMERA; + object_trans << 0,0,0; + object_rot << 35,0,25; + viewer_distance = 500; + } + void setup( std::vector<double> d ) + { + assert( d.size() == 7 ); + object_trans << d[0], d[1], d[2]; + object_rot << d[3], d[4], d[5]; + viewer_distance = d[6]; + } + Eigen::Vector3d object_trans; + Eigen::Vector3d object_rot; + double viewer_distance; +}; + +class VectorCamera : public Camera +{ +public: + VectorCamera() + { + camtype = VECTOR_CAMERA; + center << 0,0,0; + Eigen::Vector3d cameradir(1, 1, -0.5); + eye = center - 500 * cameradir; + // "up" not currently used + } + Eigen::Vector3d eye; + Eigen::Vector3d center; // (aka 'target') + Eigen::Vector3d up; +}; + #endif diff --git a/src/mainwin.cc b/src/mainwin.cc index 0280bbe..da6149c 100644 --- a/src/mainwin.cc +++ b/src/mainwin.cc @@ -964,7 +964,7 @@ void MainWindow::pasteViewportTranslation() { QTextCursor cursor = editor->textCursor(); QString txt; - txt.sprintf("[ %.2f, %.2f, %.2f ]", -this->qglview->object_trans.x(), -this->qglview->object_trans.y(), -this->qglview->object_trans.z()); + txt.sprintf("[ %.2f, %.2f, %.2f ]", -qglview->gcam.object_trans.x(), -qglview->gcam.object_trans.y(), -qglview->gcam.object_trans.z()); cursor.insertText(txt); } @@ -973,7 +973,7 @@ void MainWindow::pasteViewportRotation() QTextCursor cursor = editor->textCursor(); QString txt; txt.sprintf("[ %.2f, %.2f, %.2f ]", - fmodf(360 - this->qglview->object_rot.x() + 90, 360), fmodf(360 - this->qglview->object_rot.y(), 360), fmodf(360 - this->qglview->object_rot.z(), 360)); + fmodf(360 - qglview->gcam.object_rot.x() + 90, 360), fmodf(360 - qglview->gcam.object_rot.y(), 360), fmodf(360 - qglview->gcam.object_rot.z(), 360)); cursor.insertText(txt); } @@ -982,15 +982,15 @@ void MainWindow::updateTemporalVariables() this->root_ctx.set_variable("$t", Value(this->e_tval->text().toDouble())); Value::VectorType vpt; - vpt.push_back(Value(-this->qglview->object_trans.x())); - vpt.push_back(Value(-this->qglview->object_trans.y())); - vpt.push_back(Value(-this->qglview->object_trans.z())); + vpt.push_back(Value(-qglview->gcam.object_trans.x())); + vpt.push_back(Value(-qglview->gcam.object_trans.y())); + vpt.push_back(Value(-qglview->gcam.object_trans.z())); this->root_ctx.set_variable("$vpt", Value(vpt)); Value::VectorType vpr; - vpr.push_back(Value(fmodf(360 - this->qglview->object_rot.x() + 90, 360))); - vpr.push_back(Value(fmodf(360 - this->qglview->object_rot.y(), 360))); - vpr.push_back(Value(fmodf(360 - this->qglview->object_rot.z(), 360))); + vpr.push_back(Value(fmodf(360 - qglview->gcam.object_rot.x() + 90, 360))); + vpr.push_back(Value(fmodf(360 - qglview->gcam.object_rot.y(), 360))); + vpr.push_back(Value(fmodf(360 - qglview->gcam.object_rot.z(), 360))); root_ctx.set_variable("$vpr", Value(vpr)); } @@ -1617,65 +1617,49 @@ void MainWindow::animateUpdate() void MainWindow::viewAngleTop() { - this->qglview->object_rot.x() = 90; - this->qglview->object_rot.y() = 0; - this->qglview->object_rot.z() = 0; + qglview->gcam.object_rot << 90,0,0; this->qglview->updateGL(); } void MainWindow::viewAngleBottom() { - this->qglview->object_rot.x() = 270; - this->qglview->object_rot.y() = 0; - this->qglview->object_rot.z() = 0; + qglview->gcam.object_rot << 270,0,0; this->qglview->updateGL(); } void MainWindow::viewAngleLeft() { - this->qglview->object_rot.x() = 0; - this->qglview->object_rot.y() = 0; - this->qglview->object_rot.z() = 90; + qglview->gcam.object_rot << 0,0,90; this->qglview->updateGL(); } void MainWindow::viewAngleRight() { - this->qglview->object_rot.x() = 0; - this->qglview->object_rot.y() = 0; - this->qglview->object_rot.z() = 270; + qglview->gcam.object_rot << 0,0,270; this->qglview->updateGL(); } void MainWindow::viewAngleFront() { - this->qglview->object_rot.x() = 0; - this->qglview->object_rot.y() = 0; - this->qglview->object_rot.z() = 0; + qglview->gcam.object_rot << 0,0,0; this->qglview->updateGL(); } void MainWindow::viewAngleBack() { - this->qglview->object_rot.x() = 0; - this->qglview->object_rot.y() = 0; - this->qglview->object_rot.z() = 180; + qglview->gcam.object_rot << 0,0,180; this->qglview->updateGL(); } void MainWindow::viewAngleDiagonal() { - this->qglview->object_rot.x() = 35; - this->qglview->object_rot.y() = 0; - this->qglview->object_rot.z() = -25; + qglview->gcam.object_rot << 35,0,-25; this->qglview->updateGL(); } void MainWindow::viewCenter() { - this->qglview->object_trans.x() = 0; - this->qglview->object_trans.y() = 0; - this->qglview->object_trans.z() = 0; + qglview->gcam.object_trans << 0,0,0; this->qglview->updateGL(); } diff --git a/src/openscad.cc b/src/openscad.cc index 1bbe049..a63bac0 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -72,7 +72,8 @@ namespace fs = boost::filesystem; static void help(const char *progname) { fprintf(stderr, "Usage: %s [ -o output_file [ -d deps_file ] ]\\\n" - "%*s[ -m make_command ] [ -D var=val [..] ] [ --render ] filename\n", + "%*s[ -m make_command ] [ -D var=val [..] ] [ --render ] \\\n" + "[ --viewport=x,y,z,xrot,yrot,zrot,dist ] filename\n", progname, int(strlen(progname))+8, ""); exit(1); } @@ -128,12 +129,15 @@ int main(int argc, char **argv) const char *filename = NULL; const char *output_file = NULL; const char *deps_output_file = NULL; + GimbalCamera gimbalCamera; + gimbalCamera.camtype = Camera::NULL_CAMERA; po::options_description desc("Allowed options"); desc.add_options() ("help,h", "help message") ("version,v", "print the version") ("render", "if exporting a png image, do a full CGAL render") + ("viewport", "=x,y,z,xrot,yrot,zrot,dist for exporting png") ("o,o", po::value<string>(), "out-file") ("s,s", po::value<string>(), "stl-file") ("x,x", po::value<string>(), "dxf-file") @@ -208,6 +212,15 @@ int main(int argc, char **argv) currentdir = boosty::stringy(fs::current_path()); + if (vm.count("viewport")) { + vector<double> camnums = vm["viewport"].as< vector<double> >(); + if ( camnums.size() != 7 ) { + fprintf(stderr,"Need 7 numbers for viewport"); + } else { + gimbalCamera.setup( camnums ); + } + } + QDir exdir(QApplication::instance()->applicationDirPath()); #ifdef Q_WS_MAC exdir.cd("../Resources"); // Examples can be bundled @@ -398,9 +411,9 @@ int main(int argc, char **argv) } else { if (vm.count("render")) { - export_png_with_cgal(&root_N, fstream); + export_png_with_cgal(&root_N, gimbalCamera, fstream); } else { - export_png_with_opencsg(tree, fstream); + export_png_with_opencsg(tree, gimbalCamera, fstream); } fstream.close(); } |