浏览代码

Also keep base translation separate.

Former-commit-id: 532d94c99295fed8d66120dcbd730796ac9eccb6
Jérémie Dumas 7 年之前
父节点
当前提交
a137df845b
共有 3 个文件被更改,包括 14 次插入3 次删除
  1. 4 3
      include/igl/opengl/ViewerCore.cpp
  2. 2 0
      include/igl/opengl/ViewerCore.h
  3. 8 0
      python/modules/py_igl_opengl_glfw.cpp

+ 4 - 3
include/igl/opengl/ViewerCore.cpp

@@ -26,7 +26,7 @@ IGL_INLINE void igl::opengl::ViewerCore::align_camera_center(
   if(V.rows() == 0)
     return;
 
-  get_scale_and_shift_to_fit_mesh(V,F,camera_base_zoom,camera_translation);
+  get_scale_and_shift_to_fit_mesh(V,F,camera_base_zoom,camera_base_translation);
   // Rather than crash on empty mesh...
   if(V.size() > 0)
   {
@@ -60,7 +60,7 @@ IGL_INLINE void igl::opengl::ViewerCore::align_camera_center(
   if(V.rows() == 0)
     return;
 
-  get_scale_and_shift_to_fit_mesh(V,camera_base_zoom,camera_translation);
+  get_scale_and_shift_to_fit_mesh(V,camera_base_zoom,camera_base_translation);
   // Rather than crash on empty mesh...
   if(V.size() > 0)
   {
@@ -132,7 +132,7 @@ IGL_INLINE void igl::opengl::ViewerCore::draw(
     look_at( camera_eye, camera_center, camera_up, view);
     view = view
       * (trackball_angle * Eigen::Scaling(camera_zoom * camera_base_zoom)
-      * Eigen::Translation3f(camera_translation)).matrix();
+      * Eigen::Translation3f(camera_translation + camera_base_translation)).matrix();
 
     // Set projection
     if (orthographic)
@@ -352,6 +352,7 @@ IGL_INLINE igl::opengl::ViewerCore::ViewerCore()
   camera_view_angle = 45.0;
   camera_dnear = 1.0;
   camera_dfar = 100.0;
+  camera_base_translation << 0,0,0;
   camera_translation << 0,0,0;
   camera_eye << 0, 0, 5;
   camera_center << 0, 0, 0;

+ 2 - 0
include/igl/opengl/ViewerCore.h

@@ -107,6 +107,7 @@ public:
   float camera_base_zoom;
   float camera_zoom;
   bool orthographic;
+  Eigen::Vector3f camera_base_translation;
   Eigen::Vector3f camera_translation;
   Eigen::Vector3f camera_eye;
   Eigen::Vector3f camera_up;
@@ -155,6 +156,7 @@ namespace igl {
       SERIALIZE_MEMBER(camera_base_zoom);
       SERIALIZE_MEMBER(camera_zoom);
       SERIALIZE_MEMBER(orthographic);
+      SERIALIZE_MEMBER(camera_base_translation);
       SERIALIZE_MEMBER(camera_translation);
       SERIALIZE_MEMBER(camera_view_angle);
       SERIALIZE_MEMBER(camera_dnear);

+ 8 - 0
python/modules/py_igl_opengl_glfw.cpp

@@ -258,6 +258,14 @@ py::class_<igl::opengl::ViewerCore> viewercore_class(me, "ViewerCore");
       core.camera_translation = Eigen::Vector3f(v.cast<float>());
     })
 
+    .def_property("camera_base_translation",
+    [](const igl::opengl::ViewerCore& core) {return Eigen::MatrixXd(core.camera_base_translation.cast<double>());},
+    [](igl::opengl::ViewerCore& core, const Eigen::MatrixXd& v)
+    {
+      assert_is_Vector3("camera_base_translation",v);
+      core.camera_base_translation = Eigen::Vector3f(v.cast<float>());
+    })
+
     .def_readwrite("camera_zoom",&igl::opengl::ViewerCore::camera_zoom)
     .def_readwrite("orthographic",&igl::opengl::ViewerCore::orthographic)