unproject_ray.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_RAY_H
  9. #define IGL_UNPROJECT_RAY_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. namespace igl
  13. {
  14. // Construct a ray (source point + direction vector) given a screen space
  15. // positions (e.g. mouse) and a model-view projection constellation.
  16. //
  17. // Inputs:
  18. // pos 2d screen-space position (x,y)
  19. // model 4x4 model-view matrix
  20. // proj 4x4 projection matrix
  21. // viewport 4-long viewport vector
  22. // Outputs:
  23. // s source of ray (pos unprojected with z=0)
  24. /// dir direction of ray (d - s) where d is pos unprojected with z=1
  25. //
  26. template <
  27. typename Derivedpos,
  28. typename Derivedmodel,
  29. typename Derivedproj,
  30. typename Derivedviewport,
  31. typename Deriveds,
  32. typename Deriveddir>
  33. IGL_INLINE void unproject_ray(
  34. const Eigen::PlainObjectBase<Derivedpos> & pos,
  35. const Eigen::PlainObjectBase<Derivedmodel> & model,
  36. const Eigen::PlainObjectBase<Derivedproj> & proj,
  37. const Eigen::PlainObjectBase<Derivedviewport> & viewport,
  38. Eigen::PlainObjectBase<Deriveds> & s,
  39. Eigen::PlainObjectBase<Deriveddir> & dir);
  40. }
  41. #ifndef IGL_STATIC_LIBRARY
  42. # include "unproject_ray.cpp"
  43. #endif
  44. #endif