From f3a0d5dc647470cef30a177d9a915ab60f3a996e Mon Sep 17 00:00:00 2001 From: Don Bright Date: Mon, 30 Jun 2014 21:53:06 -0500 Subject: [PATCH] add --autocenter option to make it easier to test 2d objects properly Conflicts: src/Camera.cc tests/CMakeLists.txt --- src/Camera.cc | 17 ++++++++++++++++- src/Camera.h | 6 ++++++ src/openscad.cc | 8 +++++++- tests/CMakeLists.txt | 17 +++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/Camera.cc b/src/Camera.cc index 5ac27f49..d022ab60 100644 --- a/src/Camera.cc +++ b/src/Camera.cc @@ -4,6 +4,7 @@ Camera::Camera(enum CameraType camtype) : type(camtype), projection(Camera::PERSPECTIVE), fov(45), height(60), viewall(false) { + PRINTD("Camera()"); if (this->type == Camera::GIMBAL) { object_trans << 0,0,0; object_rot << 35,0,25; @@ -15,6 +16,7 @@ Camera::Camera(enum CameraType camtype) : } pixel_width = RenderSettings::inst()->img_width; pixel_height = RenderSettings::inst()->img_height; + autocenter = false; } void Camera::setup(std::vector params) @@ -48,15 +50,22 @@ void Camera::gimbalDefaultTranslate() Moves camera so that the given bbox is fully visible. FIXME: The scalefactor is a temporary hack to be compatible with earlier ways of showing the whole scene. + autocenter = point camera at the center of the bounding box. + (only works with vector camera) */ void Camera::viewAll(const BoundingBox &bbox, float scalefactor) { if (this->type == Camera::NONE) { this->type = Camera::VECTOR; - this->center = bbox.center(); + this->autocenter = true; this->eye = this->center - Vector3d(1,1,-0.5); } + if (this->autocenter) { + this->object_trans = -bbox.center(); // for Gimbal cam + this->center = bbox.center(); // for Vector cam + } + switch (this->projection) { case Camera::ORTHOGONAL: this->height = bbox.diagonal().norm(); @@ -103,4 +112,10 @@ void Camera::setProjection(ProjectionType type) } this->projection = type; } +======= + PRINTDB("modified center x y z %f %f %f",center.x() % center.y() % center.z()); + PRINTDB("modified eye x y z %f %f %f",eye.x() % eye.y() % eye.z()); + PRINTDB("modified obj trans x y z %f %f %f",object_trans.x() % object_trans.y() % object_trans.z()); + PRINTDB("modified obj rot x y z %f %f %f",object_rot.x() % object_rot.y() % object_rot.z()); +>>>>>>> e6609ed... add --autocenter option to make it easier to test 2d objects properly } diff --git a/src/Camera.h b/src/Camera.h index cf4e7ee3..d4b444f0 100644 --- a/src/Camera.h +++ b/src/Camera.h @@ -48,8 +48,14 @@ public: // Orthographic settings double height; // world-space height of viewport + // true if camera should try to view everything in a given + // bounding box. bool viewall; + // true if camera should point at center of bounding box + // (normally it points at 0,0,0 or at given coordinates) + bool autocenter; + unsigned int pixel_width; unsigned int pixel_height; }; diff --git a/src/openscad.cc b/src/openscad.cc index f73f6aa9..9c0fc6b6 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -110,6 +110,7 @@ static void help(const char *progname) "%2%[ --version ] [ --info ] \\\n" "%2%[ --camera=translatex,y,z,rotx,y,z,dist | \\\n" "%2% --camera=eyex,y,z,centerx,y,z ] \\\n" + "%2%[ --autocenter ] \\\n" "%2%[ --viewall ] \\\n" "%2%[ --imgsize=width,height ] [ --projection=(o)rtho|(p)ersp] \\\n" "%2%[ --render | --preview[=throwntogether] ] \\\n" @@ -159,7 +160,7 @@ Camera get_camera( po::variables_map vm ) vector strs; vector cam_parameters; split(strs, vm["camera"].as(), is_any_of(",")); - if ( strs.size() == 6 || strs.size() == 7 ) { + if ( strs.size()==6 || strs.size()==7 ) { BOOST_FOREACH(string &s, strs) cam_parameters.push_back(lexical_cast(s)); camera.setup( cam_parameters ); @@ -178,6 +179,10 @@ Camera get_camera( po::variables_map vm ) camera.viewall = true; } + if (vm.count("autocenter")) { + camera.autocenter = true; + } + if (vm.count("projection")) { string proj = vm["projection"].as(); if (proj=="o" || proj=="ortho" || proj=="orthogonal") @@ -614,6 +619,7 @@ int main(int argc, char **argv) ("preview", po::value(), "if exporting a png image, do an OpenCSG(default) or ThrownTogether preview") ("csglimit", po::value(), "if exporting a png image, stop rendering at the given number of CSG elements") ("camera", po::value(), "parameters for camera when exporting png") + ("autocenter", "adjust camera to look at object center") ("viewall", "adjust camera to fit object") ("imgsize", po::value(), "=width,height for exporting png") ("projection", po::value(), "(o)rtho or (p)erspective when exporting png") diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b6e0bf17..ac5a89a6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -868,6 +868,23 @@ function(add_cmdline_test TESTCMD_BASENAME) string(REPLACE " " "_" FILE_BASENAME ${FILE_BASENAME}) # Test names cannot include spaces set(TEST_FULLNAME "${TESTCMD_BASENAME}_${FILE_BASENAME}") list(FIND DISABLED_TESTS ${TEST_FULLNAME} DISABLED) + + # 2d tests should be viewed from the top, not an angle. + set(test_is_2d 0) + foreach(test2d IN LISTS TESTS_2D) + string(REGEX MATCH "${test2d}" match_result ${TEST_FULLNAME}) + if( NOT "${match_result}" STREQUAL "" ) + #message(STATUS "2d test found: ${TEST_FULLNAME}, ${match_result}") + set(test_is_2d 1) + endif() + endforeach() + set(CAMERA_OPTION "") + if(${test_is_2d} EQUAL 1) + #message(STATUS "${TESTCMD_ARGS}") + set(CAMERA_OPTION "--camera=0,0,100,0,0,0" "--viewall" "--autocenter" "--projection=ortho" "--debug=Camera") + set_test_config(Dimension2 ${TEST_FULLNAME}) + endif() + if (${DISABLED} EQUAL -1) # Handle configurations