|
@@ -13,7 +13,7 @@
|
|
|
#include <Eigen/LU>
|
|
|
#include "OpenGL_convenience.h"
|
|
|
|
|
|
-IGL_INLINE int igl::unproject(
|
|
|
+IGL_INLINE void igl::unproject(
|
|
|
const double winX,
|
|
|
const double winY,
|
|
|
const double winZ,
|
|
@@ -21,61 +21,59 @@ IGL_INLINE int igl::unproject(
|
|
|
double* objY,
|
|
|
double* objZ)
|
|
|
{
|
|
|
- // Put model, projection, and viewport matrices into double arrays
|
|
|
- double MV[16];
|
|
|
- double P[16];
|
|
|
- int VP[4];
|
|
|
- glGetDoublev(GL_MODELVIEW_MATRIX, MV);
|
|
|
- glGetDoublev(GL_PROJECTION_MATRIX, P);
|
|
|
- glGetIntegerv(GL_VIEWPORT, VP);
|
|
|
- return gluUnProject(winX,winY,winZ,MV,P,VP,objX,objY,objZ);
|
|
|
+ Eigen::Vector3d obj;
|
|
|
+ igl::unproject(Eigen::Vector3d(winX,winY,winZ),obj);
|
|
|
+ *objX = obj(0);
|
|
|
+ *objY = obj(1);
|
|
|
+ *objZ = obj(2);
|
|
|
}
|
|
|
|
|
|
template <typename Derivedwin, typename Derivedobj>
|
|
|
-IGL_INLINE int igl::unproject(
|
|
|
+IGL_INLINE void igl::unproject(
|
|
|
const Eigen::PlainObjectBase<Derivedwin> & win,
|
|
|
Eigen::PlainObjectBase<Derivedobj> & obj)
|
|
|
{
|
|
|
- Eigen::Vector3d dwin(win(0),win(1),win(2));
|
|
|
- Eigen::Vector3d dobj;
|
|
|
- int ret = unproject(dwin(0),dwin(1),dwin(2),
|
|
|
- &dobj.data()[0],
|
|
|
- &dobj.data()[1],
|
|
|
- &dobj.data()[2]);
|
|
|
- obj(0) = dobj(0);
|
|
|
- obj(1) = dobj(1);
|
|
|
- obj(2) = dobj(2);
|
|
|
- return ret;
|
|
|
+ obj = igl::unproject(win).template cast<typename Derivedobj::Scalar>();
|
|
|
}
|
|
|
|
|
|
template <typename Derivedwin>
|
|
|
IGL_INLINE Eigen::PlainObjectBase<Derivedwin> igl::unproject(
|
|
|
const Eigen::PlainObjectBase<Derivedwin> & win)
|
|
|
{
|
|
|
- Eigen::PlainObjectBase<Derivedwin> obj;
|
|
|
- unproject(win,obj);
|
|
|
- return obj;
|
|
|
+ using namespace Eigen;
|
|
|
+ typedef typename Derivedwin::Scalar Scalar;
|
|
|
+ Matrix4d MV,P;
|
|
|
+ Vector4i VPi;
|
|
|
+ Vector4d VPd;
|
|
|
+ glGetDoublev(GL_MODELVIEW_MATRIX,MV.data());
|
|
|
+ glGetDoublev(GL_PROJECTION_MATRIX,P.data());
|
|
|
+ glGetIntegerv(GL_VIEWPORT,VPi.data());
|
|
|
+ VPd = VPi.cast<double>();
|
|
|
+ Vector3d wind = win.template cast<double>();
|
|
|
+ Vector3d objd = igl::unproject(wind,MV,P,VPd);
|
|
|
+ return objd.template cast<Scalar>();
|
|
|
}
|
|
|
|
|
|
#endif
|
|
|
#endif
|
|
|
|
|
|
|
|
|
-Eigen::Vector3f igl::unproject(
|
|
|
- const Eigen::Vector3f& win,
|
|
|
- const Eigen::Matrix4f& model,
|
|
|
- const Eigen::Matrix4f& proj,
|
|
|
- const Eigen::Vector4f& viewport)
|
|
|
+template <typename Scalar>
|
|
|
+IGL_INLINE Eigen::Matrix<Scalar,3,1> igl::unproject(
|
|
|
+ const Eigen::Matrix<Scalar,3,1>& win,
|
|
|
+ const Eigen::Matrix<Scalar,4,4>& model,
|
|
|
+ const Eigen::Matrix<Scalar,4,4>& proj,
|
|
|
+ const Eigen::Matrix<Scalar,4,1>& viewport)
|
|
|
{
|
|
|
- Eigen::Matrix4f Inverse = (proj * model).inverse();
|
|
|
+ Eigen::Matrix<Scalar,4,4> Inverse = (proj * model).inverse();
|
|
|
|
|
|
- Eigen::Vector4f tmp;
|
|
|
+ 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::Vector4f obj = Inverse * tmp;
|
|
|
+ Eigen::Matrix<Scalar,4,1> obj = Inverse * tmp;
|
|
|
obj /= obj(3);
|
|
|
|
|
|
return obj.head(3);
|
|
@@ -86,13 +84,15 @@ Eigen::Vector3f igl::unproject(
|
|
|
#ifndef IGL_NO_OPENGL
|
|
|
#ifndef IGL_OPENGL_4
|
|
|
// Explicit template instanciation
|
|
|
-template int igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
|
|
|
-template int igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 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, 3, 1, 0, 3, 1> >&);
|
|
|
+template void igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
|
|
|
+template void igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 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, 3, 1, 0, 3, 1> >&);
|
|
|
template Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&);
|
|
|
-template int igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
|
|
|
+template void igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&);
|
|
|
template Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > igl::unproject<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
|
|
|
-template int igl::unproject<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&);
|
|
|
+template void igl::unproject<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&);
|
|
|
+template Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > igl::unproject<Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&);
|
|
|
#endif
|
|
|
+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&);
|
|
|
#endif
|
|
|
|
|
|
#endif
|