unproject_in_mesh.h 2.6 KB

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