project.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #include "project.h"
  9. template <typename Scalar>
  10. Eigen::Matrix<Scalar,3,1> igl::project(
  11. const Eigen::Matrix<Scalar,3,1>& obj,
  12. const Eigen::Matrix<Scalar,4,4>& model,
  13. const Eigen::Matrix<Scalar,4,4>& proj,
  14. const Eigen::Matrix<Scalar,4,1>& viewport)
  15. {
  16. Eigen::Matrix<Scalar,4,1> tmp;
  17. tmp << obj,1;
  18. tmp = model * tmp;
  19. tmp = proj * tmp;
  20. tmp = tmp.array() / tmp(3);
  21. tmp = tmp.array() * 0.5f + 0.5f;
  22. tmp(0) = tmp(0) * viewport(2) + viewport(0);
  23. tmp(1) = tmp(1) * viewport(3) + viewport(1);
  24. return tmp.head(3);
  25. }
  26. #ifdef IGL_STATIC_LIBRARY
  27. // Explicit template specialization
  28. template Eigen::Matrix<double, 3, 1, 0, 3, 1> igl::project<double>(Eigen::Matrix<double, 3, 1, 0, 3, 1> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 4, 0, 4, 4> const&, Eigen::Matrix<double, 4, 1, 0, 4, 1> const&);
  29. template Eigen::Matrix<float, 3, 1, 0, 3, 1> igl::project<float>(Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&);
  30. #endif