|
@@ -125,6 +125,44 @@ IGL_INLINE void igl::ViewerCore::get_scale_and_shift_to_fit_mesh(
|
|
|
zoom = 2.0 / std::max(z_scale,std::max(x_scale,y_scale));
|
|
|
}
|
|
|
|
|
|
+IGL_INLINE void igl::ViewerCore::align_camera_center(
|
|
|
+ const Eigen::MatrixXd& V)
|
|
|
+{
|
|
|
+ if(V.rows() == 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ get_scale_and_shift_to_fit_mesh(V,model_zoom,model_translation);
|
|
|
+ // Rather than crash on empty mesh...
|
|
|
+ if(V.size() > 0)
|
|
|
+ {
|
|
|
+ object_scale = (V.colwise().maxCoeff() - V.colwise().minCoeff()).norm();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+IGL_INLINE void igl::ViewerCore::get_scale_and_shift_to_fit_mesh(
|
|
|
+ const Eigen::MatrixXd& V,
|
|
|
+ float& zoom,
|
|
|
+ Eigen::Vector3f& shift)
|
|
|
+{
|
|
|
+ if (V.rows() == 0)
|
|
|
+ return;
|
|
|
+
|
|
|
+ //Eigen::SparseMatrix<double> M;
|
|
|
+ //igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_VORONOI,M);
|
|
|
+ //const auto & MV = M*V;
|
|
|
+ //Eigen::RowVector3d centroid = MV.colwise().sum()/M.diagonal().sum();
|
|
|
+ Eigen::RowVector3d min_point = V.colwise().minCoeff();
|
|
|
+ Eigen::RowVector3d max_point = V.colwise().maxCoeff();
|
|
|
+ Eigen::RowVector3d centroid = 0.5*(min_point + max_point);
|
|
|
+
|
|
|
+ shift = -centroid.cast<float>();
|
|
|
+ double x_scale = fabs(max_point[0] - min_point[0]);
|
|
|
+ double y_scale = fabs(max_point[1] - min_point[1]);
|
|
|
+ double z_scale = fabs(max_point[2] - min_point[2]);
|
|
|
+ zoom = 2.0 / std::max(z_scale,std::max(x_scale,y_scale));
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
IGL_INLINE void igl::ViewerCore::clear_framebuffers()
|
|
|
{
|
|
|
glClearColor(background_color[0],
|