1 // This file is part of libigl, a simple c++ geometry processing library.
2 //
3 // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public License
6 // v. 2.0. If a copy of the MPL was not distributed with this file, You can
7 // obtain one at http://mozilla.org/MPL/2.0/.
8 #include "project.h"
9 #include "../project.h"
10 #include "gl.h"
11 #include "glu.h"
12 #include <iostream>
13
project(const double objX,const double objY,const double objZ,double * winX,double * winY,double * winZ)14 IGL_INLINE int igl::opengl2::project(
15 const double objX,
16 const double objY,
17 const double objZ,
18 double* winX,
19 double* winY,
20 double* winZ)
21 {
22 using namespace std;
23 // Put model, projection, and viewport matrices into double arrays
24 double MV[16];
25 double P[16];
26 int VP[4];
27 glGetDoublev(GL_MODELVIEW_MATRIX, MV);
28 glGetDoublev(GL_PROJECTION_MATRIX, P);
29 glGetIntegerv(GL_VIEWPORT, VP);
30 int ret = gluProject(objX,objY,objZ,MV,P,VP,winX,winY,winZ);
31 return ret;
32 }
33
34 template <typename Derivedobj, typename Derivedwin>
project(const Eigen::PlainObjectBase<Derivedobj> & obj,Eigen::PlainObjectBase<Derivedwin> & win)35 IGL_INLINE int igl::opengl2::project(
36 const Eigen::PlainObjectBase<Derivedobj> & obj,
37 Eigen::PlainObjectBase<Derivedwin> & win)
38 {
39 assert(obj.size() >= 3);
40 Eigen::Vector3d dobj(obj(0),obj(1),obj(2));
41 Eigen::Vector3d dwin;
42 int ret = igl::opengl2::project(dobj(0),dobj(1),dobj(2),
43 &dwin.data()[0],
44 &dwin.data()[1],
45 &dwin.data()[2]);
46 win(0) = dwin(0);
47 win(1) = dwin(1);
48 win(2) = dwin(2);
49 return ret;
50 }
51
52 template <typename Derivedobj>
project(const Eigen::PlainObjectBase<Derivedobj> & obj)53 IGL_INLINE Derivedobj igl::opengl2::project(
54 const Eigen::PlainObjectBase<Derivedobj> & obj)
55 {
56 Derivedobj win;
57 igl::opengl2::project(obj,win);
58 return win;
59 }
60
61 #ifdef IGL_STATIC_LIBRARY
62 // Explicit template instantiation
63 template int igl::opengl2::project<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> >&);
64 template int igl::opengl2::project<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> >&);
65 template int igl::opengl2::project<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> >&);
66 template Eigen::Matrix<double, 3, 1, 0, 3, 1> igl::opengl2::project<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> > const&);
67 template Eigen::Matrix<float, 3, 1, 0, 3, 1> igl::opengl2::project<Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> > const&);
68 template Eigen::Matrix<double, 1, -1, 1, 1, -1> igl::opengl2::project<Eigen::Matrix<double, 1, -1, 1, 1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, -1, 1, 1, -1> > const&);
69 template Eigen::Matrix<double, 1, 3, 1, 1, 3> igl::opengl2::project<Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&);
70 template Eigen::Matrix<double, 1, 2, 1, 1, 2> igl::opengl2::project<Eigen::Matrix<double, 1, 2, 1, 1, 2> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> > const&);
71 template Eigen::Matrix<double, 2, 1, 0, 2, 1> igl::opengl2::project<Eigen::Matrix<double, 2, 1, 0, 2, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, 2, 1, 0, 2, 1> > const&);
72 #endif
73
74