|
@@ -23,20 +23,35 @@ IGL_INLINE void igl::unproject(
|
|
|
const Eigen::PlainObjectBase<Derivedviewport>& viewport,
|
|
|
Eigen::PlainObjectBase<Derivedscene> & scene)
|
|
|
{
|
|
|
- typedef typename Derivedscene::Scalar Scalar;
|
|
|
- Eigen::Matrix<Scalar,4,4> Inverse =
|
|
|
- (proj.template cast<Scalar>() * model.template cast<Scalar>()).inverse();
|
|
|
+ if(win.cols() != 3)
|
|
|
+ {
|
|
|
+ assert(win.rows() == 3);
|
|
|
+ // needless transposes
|
|
|
+ Eigen::Matrix<typename Derivedscene::Scalar,1,3> sceneT;
|
|
|
+ unproject(win.transpose().eval(),model,proj,viewport,sceneT);
|
|
|
+ scene = sceneT.head(3);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ assert(win.cols() == 3);
|
|
|
+ const int n = win.rows();
|
|
|
+ scene.resize(n,3);
|
|
|
+ for(int i = 0;i<n;i++)
|
|
|
+ {
|
|
|
+ typedef typename Derivedscene::Scalar Scalar;
|
|
|
+ Eigen::Matrix<Scalar,4,4> Inverse =
|
|
|
+ (proj.template cast<Scalar>() * model.template cast<Scalar>()).inverse();
|
|
|
|
|
|
- Eigen::Matrix<Scalar,4,1> tmp;
|
|
|
- tmp << win, 1;
|
|
|
- tmp(0) = (tmp(0) - viewport(0)) / viewport(2);
|
|
|
- tmp(1) = (tmp(1) - viewport(1)) / viewport(3);
|
|
|
- tmp = tmp.array() * 2.0f - 1.0f;
|
|
|
+ Eigen::Matrix<Scalar,4,1> tmp;
|
|
|
+ tmp << win.row(i).head(3).transpose(), 1;
|
|
|
+ tmp(0) = (tmp(0) - viewport(0)) / viewport(2);
|
|
|
+ tmp(1) = (tmp(1) - viewport(1)) / viewport(3);
|
|
|
+ tmp = tmp.array() * 2.0f - 1.0f;
|
|
|
|
|
|
- Eigen::Matrix<Scalar,4,1> obj = Inverse * tmp;
|
|
|
- obj /= obj(3);
|
|
|
+ Eigen::Matrix<Scalar,4,1> obj = Inverse * tmp;
|
|
|
+ obj /= obj(3);
|
|
|
|
|
|
- scene = obj.head(3);
|
|
|
+ scene.row(i).head(3) = obj.head(3);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
template <typename Scalar>
|
|
@@ -54,4 +69,6 @@ IGL_INLINE Eigen::Matrix<Scalar,3,1> igl::unproject(
|
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
|
template Eigen::Matrix<float, 3, 1, 0, 3, 1> igl::unproject<float>(Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&);
|
|
|
template Eigen::Matrix<double, 3, 1, 0, 3, 1> igl::unproject<double>(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 1, 0, 4, 1> const&);
|
|
|
+template void igl::unproject<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
|
+template void igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 4, 0, 4, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 4, 1, 0, 4, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
|
|
|
#endif
|