projection.cc

Go to the documentation of this file.
00001 
00003 
00004 //
00005 // Copyright (c) 2004-2007 University of Southern California
00006 // Rob Peters <rjpeters at usc dot edu>
00007 //
00008 // created: Thu Oct 28 16:55:06 2004
00009 // commit: $Id: projection.cc 10065 2007-04-12 05:54:56Z rjpeters $
00010 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/geom/projection.cc $
00011 //
00012 // --------------------------------------------------------------------
00013 //
00014 // This file is part of GroovX.
00015 //   [http://ilab.usc.edu/rjpeters/groovx/]
00016 //
00017 // GroovX is free software; you can redistribute it and/or modify it
00018 // under the terms of the GNU General Public License as published by
00019 // the Free Software Foundation; either version 2 of the License, or
00020 // (at your option) any later version.
00021 //
00022 // GroovX is distributed in the hope that it will be useful, but
00023 // WITHOUT ANY WARRANTY; without even the implied warranty of
00024 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025 // General Public License for more details.
00026 //
00027 // You should have received a copy of the GNU General Public License
00028 // along with GroovX; if not, write to the Free Software Foundation,
00029 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00030 //
00032 
00033 #ifndef GROOVX_GEOM_PROJECTION_CC_UTC20050626084023_DEFINED
00034 #define GROOVX_GEOM_PROJECTION_CC_UTC20050626084023_DEFINED
00035 
00036 #include "projection.h"
00037 
00038 #include "geom/rect.h"
00039 #include "geom/txform.h"
00040 #include "geom/vec3.h"
00041 
00042 #include "rutz/trace.h"
00043 
00044 using geom::recti;
00045 using geom::txform;
00046 using geom::vec3d;
00047 
00048 vec3d geom::unproject(const txform& modelview,
00049                       const txform& projection,
00050                       const recti& viewport,
00051                       const vec3d& screen)
00052 {
00053 GVX_TRACE("geom::unproject");
00054 
00055   const txform pm = projection.mtx_mul(modelview);
00056   const txform pmi = pm.inverted();
00057 
00058   const vec3d screen2(2*(screen.x() - viewport.left())/viewport.width() - 1,
00059                       2*(screen.y() - viewport.bottom())/viewport.height() - 1,
00060                       2*(screen.z()) - 1);
00061 
00062   return pmi.apply_to(screen2);
00063 }
00064 
00065 vec3d geom::project(const txform& modelview,
00066                     const txform& projection,
00067                     const recti& viewport,
00068                     const vec3d& world_pos)
00069 {
00070 GVX_TRACE("geom::project");
00071 
00072   const txform pm = projection.mtx_mul(modelview);
00073 
00074   const vec3d s1 = pm.apply_to(world_pos);
00075 
00076   return vec3d(viewport.left()   + 0.5 * (s1.x()+1) * viewport.width(),
00077                viewport.bottom() + 0.5 * (s1.y()+1) * viewport.height(),
00078                0.5 * (s1.z()+1));
00079 }
00080 
00081 static const char __attribute__((used)) vcid_groovx_geom_projection_cc_utc20050626084023[] = "$Id: projection.cc 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00082 #endif // !GROOVX_GEOM_PROJECTION_CC_UTC20050626084023_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:38 2008 by Doxygen version 1.5.5.