diff --git a/src/Camera.h b/src/Camera.h index f7cd257d..87b5e83a 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -12,6 +12,8 @@ There are two different types of cameras represented in this class: *Gimbal camera - uses Euler Angles, object translation, and viewer distance *Vector camera - uses 'eye', 'center', and 'up' vectors ('lookat' style) +There are two modes of projection, Perspective and Orthogonal. + */ #include @@ -21,8 +23,10 @@ class Camera { public: enum CameraType { NONE, GIMBAL, VECTOR } type; + enum ProjectionType { ORTHOGONAL, PERSPECTIVE } projection; Camera() { type = Camera::NONE; + projection = Camera::PERSPECTIVE; } Camera( enum CameraType e ) { @@ -38,6 +42,7 @@ public: } pixel_width = 512; pixel_height = 512; + projection = Camera::PERSPECTIVE; } void setup( std::vector params ) { diff --git a/src/GLView.cc b/src/GLView.cc index 8d557127..e7878ea7 100644 --- a/src/GLView.cc +++ b/src/GLView.cc @@ -13,11 +13,10 @@ GLView::GLView() { showedges = false; showfaces = true; - orthomode = false; showaxes = false; showcrosshairs = false; renderer = NULL; - cam.type = Camera::NONE; + cam = Camera(); #ifdef ENABLE_OPENCSG is_opencsg_capable = false; has_shaders = false; @@ -281,7 +280,7 @@ void GLView::vectorCamPaintGL() { glEnable(GL_LIGHTING); - if (orthomode) setupVectorCamOrtho(); + if (cam.projection==Camera::ORTHOGONAL) setupVectorCamOrtho(); else setupVectorCamPerspective(); glMatrixMode(GL_MODELVIEW); @@ -318,8 +317,10 @@ void GLView::gimbalCamPaintGL() { glEnable(GL_LIGHTING); - if (orthomode) GLView::setupGimbalCamOrtho(cam.viewer_distance); - else GLView::setupGimbalCamPerspective(); + if (cam.projection == Camera::ORTHOGONAL) + GLView::setupGimbalCamOrtho(cam.viewer_distance); + else + GLView::setupGimbalCamPerspective(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -430,7 +431,7 @@ void GLView::showSmallaxes() glEnd(); //Restore perspective for next paint - if(!orthomode) + if(cam.projection==Camera::PERSPECTIVE) GLView::setupGimbalCamPerspective(); } diff --git a/src/QGLView.h b/src/QGLView.h index 4192a06f..f3e3681f 100644 --- a/src/QGLView.h +++ b/src/QGLView.h @@ -34,8 +34,11 @@ public: void setShowAxes(bool enabled) { this->showaxes = enabled; } bool showCrosshairs() const { return this->showcrosshairs; } void setShowCrosshairs(bool enabled) { this->showcrosshairs = enabled; } - bool orthoMode() const { return this->orthomode; } - void setOrthoMode(bool enabled) { this->orthomode = enabled; } + bool orthoMode() const { return (this->cam.projection == Camera::ORTHOGONAL); } + void setOrthoMode(bool enabled) { + if (enabled) this->cam.projection = Camera::ORTHOGONAL; + else this->cam.projection = Camera::PERSPECTIVE; + } std::string getRendererInfo() const; bool save(const char *filename); diff --git a/src/openscad.cc b/src/openscad.cc index 37d27fa8..c2aab3d1 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -78,7 +78,7 @@ 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 ] \\\n" "%*s[ --camera= [x,y,z,rotx,y,z,dist] | [eyex,y,z,centerx,y,z] ] \\\n" - "%*s[ --imgsize=width,height ] \\\n" + "%*s[ --imgsize=width,height ] [ --projection=o|p] \\\n" "%*sfilename\n", progname, tab, "", tab, "", tab, "", tab, ""); exit(1); @@ -120,11 +120,18 @@ Camera get_camera( po::variables_map vm ) } } - return camera; -} + if (vm.count("projection")) { + string proj = vm["projection"].as(); + if (proj=="o" || proj=="ortho" || proj=="orthogonal") + camera.projection = Camera::ORTHOGONAL; + else if (proj=="p" || proj == "perspective") + camera.projection = Camera::PERSPECTIVE; + else { + fprintf(stderr,"projection needs to be 'o' or 'p' for ortho or perspective"); + exit(1); + } + } -std::pair get_imgsize( po::variables_map vm ) -{ int w = RenderSettings::inst()->img_width; int h = RenderSettings::inst()->img_height; if (vm.count("imgsize")) { @@ -138,7 +145,10 @@ std::pair get_imgsize( po::variables_map vm ) h = lexical_cast( strs[1] ); } } - return std::pair(w,h); + camera.pixel_width = w; + camera.pixel_height = h; + + return camera; } int main(int argc, char **argv) @@ -185,6 +195,7 @@ int main(int argc, char **argv) ("render", "if exporting a png image, do a full CGAL render") ("camera", po::value(), "parameters for camera when exporting png") ("imgsize", po::value(), "=width,height for exporting png") + ("projection", po::value(), "(o)rtho or (p)erspective when exporting png") ("o,o", po::value(), "out-file") ("s,s", po::value(), "stl-file") ("x,x", po::value(), "dxf-file") @@ -260,9 +271,6 @@ int main(int argc, char **argv) currentdir = boosty::stringy(fs::current_path()); Camera camera = get_camera( vm ); - std::pair imgsize = get_imgsize( vm ); - camera.pixel_width = imgsize.first; - camera.pixel_height = imgsize.second; QDir exdir(QApplication::instance()->applicationDirPath()); #ifdef Q_WS_MAC