unproject_in_mesh.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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_EMBREE_UNPROJECT_IN_MESH
  9. #define IGL_EMBREE_UNPROJECT_IN_MESH
  10. #include "../igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. #include "../Hit.h"
  14. namespace igl
  15. {
  16. namespace embree
  17. {
  18. // Forward define
  19. class EmbreeIntersector;
  20. /// Unproject a screen location (using current opengl viewport, projection, and
  21. /// model view) to a 3D position _inside_ a given mesh. If the ray through the
  22. /// given screen location (x,y) _hits_ the mesh more than twice then the 3D
  23. /// midpoint between the first two hits is return. If it hits once, then that
  24. /// point is return. If it does not hit the mesh then obj is not set.
  25. ///
  26. ///
  27. /// @param[in] pos screen space coordinates
  28. /// @param[in] model model matrix
  29. /// @param[in] proj projection matrix
  30. /// @param[in] viewport vieweport vector
  31. /// @param[in] ei EmbreeIntersector containing (V,F)
  32. /// @param[out] obj 3d unprojected mouse point in mesh
  33. /// @param[out] hits vector of embree hits
  34. /// @return number of hits
  35. ///
  36. /// \note Previous prototype did not require model, proj, and viewport. This
  37. /// has been removed. Instead replace with:
  38. ///
  39. /// Eigen::Matrix4f model,proj;
  40. /// Eigen::Vector4f viewport;
  41. /// igl::opengl2::model_proj_viewport(model,proj,viewport);
  42. /// igl::embree::unproject_in_mesh(Vector2f(x,y),model,proj,viewport,ei,obj,hits);
  43. ///
  44. template < typename Derivedobj>
  45. IGL_INLINE int unproject_in_mesh(
  46. const Eigen::Vector2f& pos,
  47. const Eigen::Matrix4f& model,
  48. const Eigen::Matrix4f& proj,
  49. const Eigen::Vector4f& viewport,
  50. const EmbreeIntersector & ei,
  51. Eigen::PlainObjectBase<Derivedobj> & obj,
  52. std::vector<igl::Hit > & hits);
  53. /// \overload
  54. template < typename Derivedobj>
  55. IGL_INLINE int unproject_in_mesh(
  56. const Eigen::Vector2f& pos,
  57. const Eigen::Matrix4f& model,
  58. const Eigen::Matrix4f& proj,
  59. const Eigen::Vector4f& viewport,
  60. const EmbreeIntersector & ei,
  61. Eigen::PlainObjectBase<Derivedobj> & obj);
  62. }
  63. }
  64. #ifndef IGL_STATIC_LIBRARY
  65. # include "unproject_in_mesh.cpp"
  66. #endif
  67. #endif