summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-03-03 19:48:23 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-03-03 19:48:23 (GMT)
commit58de93af95d6fdd1c7434e771f126f34c4c43bd3 (patch)
tree0b0388bbb79da5741a401b35fb305583213afd9d /src
parent3f345b936192d02b821b6d297ce60203f116ad4d (diff)
add --projection=ortho|perspective option to cmdline
Diffstat (limited to 'src')
-rw-r--r--src/Camera.h5
-rw-r--r--src/GLView.cc13
-rw-r--r--src/QGLView.h7
-rw-r--r--src/openscad.cc26
4 files changed, 34 insertions, 17 deletions
diff --git a/src/Camera.h b/src/Camera.h
index f7cd257..87b5e83 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 <vector>
@@ -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<double> params ) {
diff --git a/src/GLView.cc b/src/GLView.cc
index 8d55712..e7878ea 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 4192a06..f3e3681 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 37d27fa..c2aab3d 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<string>();
+ 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<int,int> 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<int,int> get_imgsize( po::variables_map vm )
h = lexical_cast<int>( strs[1] );
}
}
- return std::pair<int,int>(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<string>(), "parameters for camera when exporting png")
("imgsize", po::value<string>(), "=width,height for exporting png")
+ ("projection", po::value<string>(), "(o)rtho or (p)erspective when exporting png")
("o,o", po::value<string>(), "out-file")
("s,s", po::value<string>(), "stl-file")
("x,x", po::value<string>(), "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<int,int> imgsize = get_imgsize( vm );
- camera.pixel_width = imgsize.first;
- camera.pixel_height = imgsize.second;
QDir exdir(QApplication::instance()->applicationDirPath());
#ifdef Q_WS_MAC
contact: Jan Huwald // Impressum