diff --git a/wrap/gl/camera.h b/wrap/gl/camera.h index 22aa153e..5e55f093 100644 --- a/wrap/gl/camera.h +++ b/wrap/gl/camera.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.1 2004/09/15 22:59:13 ganovelli +creation + Revision 1.2 2004/09/06 21:41:30 ganovelli *** empty log message *** @@ -34,39 +37,21 @@ creation #ifndef __GL_CAMERA #define __GL_CAMERA - +#include // VCG #include // opengl #include - template -class GlCamera -{ -public: - typedef CameraType::ScalarType ScalarType; - - GlCamera(CameraType & c):camera(c){} - CameraType & camera; - -public: - /// return the projection matrix for opengl - inline vcg::Matrix44 MatrixGL(ScalarType,vcg::Matrix44 &); - - /// return the projection matrix for opengl - inline void TransformGL(CameraType::ScalarType far) const; -}; - - -template -vcg::Matrix44 GlCamera::MatrixGL(CameraType::ScalarType far,vcg::Matrix44 &m){ +vcg::Matrix44 +MatrixGL(const CameraType & cam, typename CameraType::ScalarType far,vcg::Matrix44 &m){ glPushAttrib(GL_TRANSFORM_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); - camera.TransformGL(far); + cam.TransformGL(far); glGetv(GL_PROJECTION_MATRIX,&m[0][0]); glPopMatrix(); glPopAttrib(); @@ -74,12 +59,26 @@ vcg::Matrix44 GlCamera::MatrixGL(CameraType: } template -void GlCamera::TransformGL(CameraType::ScalarType farDist) const{ +void TransformGL(const CameraType & camera,typename CameraType::ScalarType farDist) { /////////////////// METTERE IL FRUSTUM GIUSTO ////////////////////// //glFrustum(1,10,2,20,1,20); + + typedef typename CameraType::ScalarType S; + S sx,dx,bt,tp,nr,fr; + dx = -camera.c.X()*camera.s.X(); + sx = ( camera.viewport.X() - camera.c.X() ) * camera.s.X(); + bt = -camera.c.Y()*camera.s.Y(); + tp = ( camera.viewport.Y() - camera.c.Y() ) * camera.s.Y(); + + nr = camera.f; + fr = farDist; // tmp + + assert(glGetError()==0); + glFrustum(dx,sx,bt,tp,nr,fr); + assert(glGetError()==0); } #endif diff --git a/wrap/gl/shot.h b/wrap/gl/shot.h index 15d14997..63a02d43 100644 --- a/wrap/gl/shot.h +++ b/wrap/gl/shot.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.1 2004/09/15 22:59:13 ganovelli +creation + Revision 1.2 2004/09/06 21:41:30 ganovelli *** empty log message *** @@ -47,70 +50,59 @@ creation #include #include -template -class GlShot { -public: - typedef typename ShotType::ScalarType ScalarType; - - GlCamera & glCamera; // the camera that shot - ShotType &shot; - GlShot(ShotType &s):shot(s),glCamera(GlCamera (s.camera) ){} - - void MatrixGL(vcg::Matrix44 & m) const; - - vcg::Point3const & GlShot::ViewPoint(); - - /// apply the modelview transformation - void TransformGL() const; - - /// Set opengl projection and model matrix pushing them onto the stack (to use with PopView() - void SetView(); - void UnsetView(); - -}; // end class definition - template -void GlShot::MatrixGL(vcg::Matrix44 & m) const{ +void MatrixGL(const ShotType & shot,vcg::Matrix44 & m) { m = shot.similarity.Matrix(); } template -void GlShot::TransformGL()const{ - vcg::Matrix44 m; - MatrixGL(m); +void TransformGL(const ShotType & shot){ + vcg::Matrix44 m; + MatrixGL(shot,m); glMultMatrix(m); } template -void GlShot::SetView(){ +void SetView(const ShotType & shot){ + assert(glGetError() == 0); glPushAttrib(GL_TRANSFORM_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); + assert(glGetError() == 0); OutMatrix("mat.txt","a+"); - glCamera.TransformGL(1.f); + assert(glGetError() == 0); + + TransformGL(shot.camera,1.f); + assert(glGetError() == 0); + OutMatrix("mat.txt","a+"); + assert(glGetError() == 0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); - vcg::Matrix44 m; - TransformGL(); + vcg::Matrix44 m; + TransformGL(shot); + + glPopAttrib(); + + assert(glGetError() == 0); } -template - void GlShot::UnsetView(){ - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glPopAttrib(); - } +#define UnsetView()\ + glPushAttrib(GL_TRANSFORM_BIT);\ + glMatrixMode(GL_MODELVIEW);\ + glPopMatrix();\ + glMatrixMode(GL_PROJECTION);\ + glPopMatrix();\ + glPopAttrib();\ + #endif