unproject_in_mesh.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. // 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. // Inputs:
  28. // pos screen space coordinates
  29. // model model matrix
  30. // proj projection matrix
  31. // viewport vieweport vector
  32. // ei EmbreeIntersector containing (V,F)
  33. // Outputs:
  34. // obj 3d unprojected mouse point in mesh
  35. // hits vector of embree hits
  36. // Returns number of hits
  37. //
  38. // Note: Previous prototype did not require model, proj, and viewport. This
  39. // has been removed. Instead replace with:
  40. //
  41. // Eigen::Matrix4f model,proj;
  42. // Eigen::Vector4f viewport;
  43. // igl::opengl2::model_proj_viewport(model,proj,viewport);
  44. // igl::embree::unproject_in_mesh(Vector2f(x,y),model,proj,viewport,ei,obj,hits);
  45. //
  46. template < typename Derivedobj>
  47. IGL_INLINE int unproject_in_mesh(
  48. const Eigen::Vector2f& pos,
  49. const Eigen::Matrix4f& model,
  50. const Eigen::Matrix4f& proj,
  51. const Eigen::Vector4f& viewport,
  52. const EmbreeIntersector & ei,
  53. Eigen::PlainObjectBase<Derivedobj> & obj,
  54. std::vector<igl::Hit > & hits);
  55. template < typename Derivedobj>
  56. IGL_INLINE int unproject_in_mesh(
  57. const Eigen::Vector2f& pos,
  58. const Eigen::Matrix4f& model,
  59. const Eigen::Matrix4f& proj,
  60. const Eigen::Vector4f& viewport,
  61. const EmbreeIntersector & ei,
  62. Eigen::PlainObjectBase<Derivedobj> & obj);
  63. }
  64. }
  65. #ifndef IGL_STATIC_LIBRARY
  66. # include "unproject_in_mesh.cpp"
  67. #endif
  68. #endif