mirror of https://github.com/vitalif/openscad
add --autocenter option to make it easier to test 2d objects properly
Conflicts: src/Camera.cc tests/CMakeLists.txtmaster
parent
28864037ee
commit
f3a0d5dc64
|
@ -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<double> 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
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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<string> strs;
|
||||
vector<double> cam_parameters;
|
||||
split(strs, vm["camera"].as<string>(), 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<double>(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<string>();
|
||||
if (proj=="o" || proj=="ortho" || proj=="orthogonal")
|
||||
|
@ -614,6 +619,7 @@ int main(int argc, char **argv)
|
|||
("preview", po::value<string>(), "if exporting a png image, do an OpenCSG(default) or ThrownTogether preview")
|
||||
("csglimit", po::value<unsigned int>(), "if exporting a png image, stop rendering at the given number of CSG elements")
|
||||
("camera", po::value<string>(), "parameters for camera when exporting png")
|
||||
("autocenter", "adjust camera to look at object center")
|
||||
("viewall", "adjust camera to fit object")
|
||||
("imgsize", po::value<string>(), "=width,height for exporting png")
|
||||
("projection", po::value<string>(), "(o)rtho or (p)erspective when exporting png")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue