diff --git a/wrap/gl/shot.h b/wrap/gl/shot.h index 63a02d43..052d2c94 100644 --- a/wrap/gl/shot.h +++ b/wrap/gl/shot.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.2 2004/10/05 19:04:45 ganovelli +changed from classes to functions + Revision 1.1 2004/09/15 22:59:13 ganovelli creation @@ -38,73 +41,80 @@ creation #ifndef __VCGLIB_GLSHOT #define __VCGLIB_GLSHOT -// #include -// #include -// #include + +// include vcg stuff +#include +#include #include -#include -#include #include +// include wrap stuff +#include #include #include -#include +template +struct GlShot { + typedef typename ShotType::ScalarType ScalarType; + typedef typename GlCamera GlCameraType; -template -void MatrixGL(const ShotType & shot,vcg::Matrix44 & m) { +/// takes the opengl matrix corresponding to the shot +static void MatrixGL(const ShotType & shot,vcg::Matrix44 & m) { m = shot.similarity.Matrix(); } - -template -void TransformGL(const ShotType & shot){ - vcg::Matrix44 m; +/// perform the model transformation correspoding to the shot +static void TransformGL(const vcg::Shot & shot){ + vcg::Matrix44 m; MatrixGL(shot,m); glMultMatrix(m); } -template -void SetView(const ShotType & shot){ +/// set the view as from the shot +static void SetView(const vcg::Shot & shot){ assert(glGetError() == 0); - glPushAttrib(GL_TRANSFORM_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - assert(glGetError() == 0); - OutMatrix("mat.txt","a+"); assert(glGetError() == 0); - - TransformGL(shot.camera,1.f); - assert(glGetError() == 0); - - OutMatrix("mat.txt","a+"); + GlCameraType::TransformGL(shot.camera); // apply camera/modelview transformation assert(glGetError() == 0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - vcg::Matrix44 m; - TransformGL(shot); - - glPopAttrib(); - + vcg::Matrix44 m; + TransformGL(shot); // apply similarity/modelview transformation assert(glGetError() == 0); } -#define UnsetView()\ - glPushAttrib(GL_TRANSFORM_BIT);\ - glMatrixMode(GL_MODELVIEW);\ - glPopMatrix();\ - glMatrixMode(GL_PROJECTION);\ - glPopMatrix();\ - glPopAttrib();\ - +/// unset the view +static void UnsetView(){ + glPushAttrib(GL_TRANSFORM_BIT); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glPopAttrib(); + } + +/// takes a shot and a trackball and retur the shot corresponding to the transformation +/// applied by the trackball +static void FromTrackball(const vcg::Trackball & tr, const vcg::Shot & sShot, + vcg::Shot & shot ){ + vcg::Point3 vp = sShot.ViewPoint()-tr.center; + vcg::Point3 nvp ; + vcg::Matrix44 trInv = tr.track.InverseMatrix(); + nvp = trInv*vp; + shot.SetViewPoint(nvp+tr.center); + shot.similarity.rot = trInv*sShot.similarity.rot; +} +}; #endif