// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 Alec Jacobson // // This Source Code Form is subject to the terms of the Mozilla Public License // v. 2.0. If a copy of the MPL was not distributed with this file, You can // obtain one at http://mozilla.org/MPL/2.0/. #include "unproject.h" #include #include template < typename Derivedwin, typename Derivedmodel, typename Derivedproj, typename Derivedviewport, typename Derivedscene> IGL_INLINE void igl::unproject( const Eigen::PlainObjectBase& win, const Eigen::PlainObjectBase& model, const Eigen::PlainObjectBase& proj, const Eigen::PlainObjectBase& viewport, Eigen::PlainObjectBase & scene) { typedef typename Derivedscene::Scalar Scalar; Eigen::Matrix Inverse = (proj.template cast() * model.template cast()).inverse(); Eigen::Matrix tmp; tmp << win, 1; tmp(0) = (tmp(0) - viewport(0)) / viewport(2); tmp(1) = (tmp(1) - viewport(1)) / viewport(3); tmp = tmp.array() * 2.0f - 1.0f; Eigen::Matrix obj = Inverse * tmp; obj /= obj(3); scene = obj.head(3); } template IGL_INLINE Eigen::Matrix igl::unproject( const Eigen::Matrix& win, const Eigen::Matrix& model, const Eigen::Matrix& proj, const Eigen::Matrix& viewport) { Eigen::Matrix scene; unproject(win,model,proj,viewport,scene); return scene; } #ifdef IGL_STATIC_LIBRARY template Eigen::Matrix igl::unproject(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&); template Eigen::Matrix igl::unproject(Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&, Eigen::Matrix const&); #endif