00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
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