unproject_in_mesh.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #ifndef IGL_UNPROJECT_IN_MESH
  9. #define IGL_UNPROJECT_IN_MESH
  10. #include <igl/igl_inline.h>
  11. #include <Eigen/Core>
  12. #include <vector>
  13. #include "Hit.h"
  14. namespace igl
  15. {
  16. // Forward define
  17. class EmbreeIntersector;
  18. #ifndef IGL_OPENGL_4
  19. // Unproject a screen location (using current opengl viewport, projection, and
  20. // model view) to a 3D position
  21. //
  22. // Inputs:
  23. // x x-coordinate of mouse location
  24. // y y-coordinate of mouse location
  25. // ei EmbreeIntersector containing (V,F)
  26. // Outputs:
  27. // obj 3d unprojected mouse point in mesh
  28. // Returns number of hits
  29. //
  30. template <
  31. typename Derivedobj>
  32. IGL_INLINE int unproject_in_mesh(
  33. const double x,
  34. const double y,
  35. const igl::EmbreeIntersector & ei,
  36. Eigen::PlainObjectBase<Derivedobj> & obj);
  37. template <
  38. typename Derivedobj>
  39. IGL_INLINE int unproject_in_mesh(
  40. const double x,
  41. const double y,
  42. const igl::EmbreeIntersector & ei,
  43. Eigen::PlainObjectBase<Derivedobj> & obj,
  44. std::vector<igl::Hit > & hits);
  45. #endif
  46. // Unproject a screen location (using the given model, proj and viewewport) to a 3D position
  47. // and a set of hits
  48. //
  49. // Inputs:
  50. // pos screen space coordinates
  51. // model model matrix
  52. // proj projection matrix
  53. // viewport vieweport vector
  54. // ei EmbreeIntersector containing (V,F)
  55. // Outputs:
  56. // obj 3d unprojected mouse point in mesh
  57. // hits vector of embree hits
  58. // Returns number of hits
  59. template <
  60. typename Derivedobj>
  61. IGL_INLINE int unproject_in_mesh(
  62. const Eigen::Vector2f& pos,
  63. const Eigen::Matrix4f& model,
  64. const Eigen::Matrix4f& proj,
  65. const Eigen::Vector4f& viewport,
  66. const igl::EmbreeIntersector & ei,
  67. Eigen::PlainObjectBase<Derivedobj> & obj,
  68. std::vector<igl::Hit > & hits);
  69. }
  70. #ifndef IGL_STATIC_LIBRARY
  71. # include "unproject_in_mesh.cpp"
  72. #endif
  73. #endif