add --projection=ortho|perspective option to cmdline

felipesanches-svg
don bright 2013-03-03 13:48:23 -06:00
parent 3f345b9361
commit 58de93af95
4 changed files with 34 additions and 17 deletions

View File

@ -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 ) {

View File

@ -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();
}

View File

@ -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);

View File

@ -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