浏览代码

handle 2d centering

Alec Jacobson 4 年之前
父节点
当前提交
f0657f96bc
共有 1 个文件被更改,包括 4 次插入6 次删除
  1. 4 6
      include/igl/opengl/glfw/Viewer.cpp

+ 4 - 6
include/igl/opengl/glfw/Viewer.cpp

@@ -667,13 +667,11 @@ namespace glfw
 
 
 
 
     // Initialization code for the trackball
     // Initialization code for the trackball
-    Eigen::RowVector3d center;
-    if (data().V.rows() == 0)
+    Eigen::RowVector3d center = Eigen::RowVector3d(0,0,0);
+    if(data().V.rows() > 0)
     {
     {
-      center << 0,0,0;
-    }else
-    {
-      center = data().V.colwise().sum()/data().V.rows();
+      // be careful that V may be 2D
+      center.head(data().V.cols()) = data().V.colwise().sum()/data().V.rows();
     }
     }
 
 
     Eigen::Vector3f coord =
     Eigen::Vector3f coord =