unproject_in_mesh.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 _inside_ a given mesh. If the ray through the
  21. // given screen location (x,y) _hits_ the mesh more than twice then the 3D
  22. // midpoint between the first two hits is return. If it hits once, then that
  23. // point is return. If it does not hit the mesh then obj is not set.
  24. //
  25. // Inputs:
  26. // x x-coordinate of mouse location
  27. // y y-coordinate of mouse location
  28. // ei EmbreeIntersector containing (V,F)
  29. // Outputs:
  30. // obj 3d unprojected mouse point in mesh
  31. // Returns number of hits
  32. //
  33. template <
  34. typename Derivedobj>
  35. IGL_INLINE int unproject_in_mesh(
  36. const double x,
  37. const double y,
  38. const igl::EmbreeIntersector & ei,
  39. Eigen::PlainObjectBase<Derivedobj> & obj);
  40. template <
  41. typename Derivedobj>
  42. IGL_INLINE int unproject_in_mesh(
  43. const double x,
  44. const double y,
  45. const igl::EmbreeIntersector & ei,
  46. Eigen::PlainObjectBase<Derivedobj> & obj,
  47. std::vector<igl::Hit > & hits);
  48. #endif
  49. // Unproject a screen location (using the given model, proj and viewewport) to a 3D position
  50. // and a set of hits
  51. //
  52. // Inputs:
  53. // pos screen space coordinates
  54. // model model matrix
  55. // proj projection matrix
  56. // viewport vieweport vector
  57. // ei EmbreeIntersector containing (V,F)
  58. // Outputs:
  59. // obj 3d unprojected mouse point in mesh
  60. // hits vector of embree hits
  61. // Returns number of hits
  62. template <
  63. typename Derivedobj>
  64. IGL_INLINE int unproject_in_mesh(
  65. const Eigen::Vector2f& pos,
  66. const Eigen::Matrix4f& model,
  67. const Eigen::Matrix4f& proj,
  68. const Eigen::Vector4f& viewport,
  69. const igl::EmbreeIntersector & ei,
  70. Eigen::PlainObjectBase<Derivedobj> & obj,
  71. std::vector<igl::Hit > & hits);
  72. }
  73. #ifndef IGL_STATIC_LIBRARY
  74. # include "unproject_in_mesh.cpp"
  75. #endif
  76. #endif