From 02aee675986ac57d69f1771cd9e5f21683a85780 Mon Sep 17 00:00:00 2001 From: cnr-isti-vclab Date: Wed, 15 Dec 2004 18:45:50 +0000 Subject: [PATCH] *** empty log message *** --- vcg/math/camera.h | 100 +++++++++++++++++++------------- vcg/math/matrix44.h | 11 +++- vcg/math/quaternion.h | 28 +++++++++ vcg/math/shot.h | 65 ++++++++++++--------- vcg/math/similarity.h | 14 ++++- wrap/gl/camera.h | 129 +++++++++++++++++++++++++++++++++--------- wrap/gl/shot.h | 116 +++++++++++++++++++++---------------- wrap/gl/trimesh.h | 5 +- 8 files changed, 319 insertions(+), 149 deletions(-) diff --git a/vcg/math/camera.h b/vcg/math/camera.h index 1c0bbc28..82f11d10 100644 --- a/vcg/math/camera.h +++ b/vcg/math/camera.h @@ -23,6 +23,8 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +<<<<<<< camera.h +======= Revision 1.8 2004/11/23 10:15:38 cignoni removed comment in comment gcc warning @@ -32,6 +34,7 @@ Point?.h to point?.h Revision 1.6 2004/11/03 09:32:50 ganovelli SetPerspective and SetFrustum added (same parameters as in opengl) +>>>>>>> 1.8 Revision 1.4 2004/10/07 14:39:57 fasano Remove glew.h include @@ -57,8 +60,8 @@ creation #define __VCGLIB_CAMERA // VCG -#include -#include +#include +#include #include namespace vcg{ @@ -75,15 +78,16 @@ public: _flags(0),viewportM(1) {} - S f; // Focal Distance (cioe' la distanza del piano immagine dal centro di proiezione - S farend; // farend end of frustum (it doesn influence the projection ) - vcg::Point2 s; // Scale factor of the image (nei casi in cui a senso) - vcg::Point2 c; // pin-hole position - vcg::Point2 viewport; // Size viewport (in pixels) - S k[4]; // 1st & 2nd order radial lens distortion coefficient + S f; // Focal Distance (cioe' la distanza del piano immagine dal centro di proiezione + S farend; // farend end of frustum (it doesn influence the projection ) + vcg::Point2 s; // Scale factor of the image (nei casi in cui a senso) + vcg::Point2 c; // pin-hole position - S viewportM; // ratio between viewport in pixel and size (useful to avoid chancing s or viewport when - // zooming a ortho camera (for a perspective camera it is 1) + vcg::Point2 viewport; // Size viewport (in pixels) + S k[4]; // 1st & 2nd order radial lens distortion coefficient + + S viewportM; // ratio between viewport in pixel and size (useful to avoid chancing s or viewport when + // zooming a ortho camera (for a perspective camera it is 1) enum{ ORTHO_BIT = 0x01 // true if the camera is orthogonal @@ -95,14 +99,15 @@ public: char & UberFlags() {return _flags;} /// set the camera specifying the perspecive view - inline void SetPerspective(S angle, S ratio, S nearend, S farend,vcg::Point2 viewport=vcg::Point2(500,-1) ); + inline void SetPerspective(S angle, S ratio, S near, S farend,vcg::Point2 viewport=vcg::Point2(500,-1) ); /// set the camera specifying the frustum view - inline void SetFrustum(S dx, S sx, S bt, S tp, S nearend, S farend,vcg::Point2 viewport=vcg::Point2(500,-1)); + inline void SetFrustum(S dx, S sx, S bt, S tp, S near, S farend,vcg::Point2 viewport=vcg::Point2(500,-1)); /// project a point from space 3d (in the reference system of the camera) to the camera's plane /// the result is in absolute coordinates inline vcg::Point2 Project(const vcg::Point3 & p); + inline vcg::Point3 UnProject(const vcg::Point2 & p); }; /// project a point in the camera plane @@ -132,38 +137,57 @@ vcg::Point2 Camera::Project(const vcg::Point3 & p){ } return q; } +/// unproject a point from the camera plane +template +vcg::Point3 Camera::UnProject(const vcg::Point2 & p){ + S tx = p.X(); + S ty = p.Y(); - /// set the camera specifying the perspecive view - template - void Camera::SetPerspective(S angle, S ratio, S nr, S _farend,vcg::Point2 vp){ - S halfsize[2]; - halfsize[1] = tan(math::ToRad(angle/2)) * nr; - halfsize[0] = halfsize[1]*ratio; - SetFrustum(-halfsize[0],halfsize[0],-halfsize[1],halfsize[1],nr,_farend,vp); - } + vcg::Point3 q(0,0,0); - /// set the camera specifying the frustum view - template - void Camera::SetFrustum(S sx, S dx, S bt, S tp, S nr, S _farend,vcg::Point2 vp){ - S vpt[2]; - vpt[0] = dx-sx; - vpt[1] = tp-bt; + if(!IsOrtho()) + { + tx = (tx-c.X())*s.X(); + ty = (tx-c.Y())*s.Y(); - viewport[0] = vp[0]; - if(vp[1] != -1) - viewport[1] = vp[1];// the user specified the viewport - else - viewport[1] = viewport[0];// default viewport + q[0] = tx/f; + q[1] = ty/f; + q[2] = f; + } - s[0] = vpt[0]/(S) viewport[0]; - s[1] = vpt[1]/(S) viewport[1]; + return q; +} +/// set the camera specifying the perspective view +template + void Camera::SetPerspective(S angle, S ratio, S nr, S _far,vcg::Point2 vp){ + S halfsize[2]; + halfsize[1] = tan(math::ToRad(angle/2)) * nr; + halfsize[0] = halfsize[1]*ratio; + SetFrustum(-halfsize[0],halfsize[0],-halfsize[1],halfsize[1],nr,_far,vp); +} - c[0] = -sx/vpt[0] * viewport[0]; - c[1] = -bt/vpt[1] * viewport[1]; +/// set the camera specifying the frustum view +template + void Camera::SetFrustum(S sx, S dx, S bt, S tp, S nr, S _far,vcg::Point2 vp){ + S vpt[2]; + vpt[0] = dx-sx; + vpt[1] = tp-bt; - f =nr; - farend = _farend; - } + viewport[0] = vp[0]; + if(vp[1] != -1) + viewport[1] = vp[1];// the user specified the viewport + else + viewport[1] = viewport[0];// default viewport + + s[0] = vpt[0]/(S) viewport[0]; + s[1] = vpt[1]/(S) viewport[1]; + + c[0] = -sx/vpt[0] * viewport[0]; + c[1] = -bt/vpt[1] * viewport[1]; + + f =nr; + farend = _far; + } } diff --git a/vcg/math/matrix44.h b/vcg/math/matrix44.h index 55cdeb5c..50253fdb 100644 --- a/vcg/math/matrix44.h +++ b/vcg/math/matrix44.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.21 2004/10/22 14:41:30 ponchio +return in operator+ added. + Revision 1.20 2004/10/18 15:03:14 fiorin Updated interface: all Matrix classes have now the same interface @@ -192,9 +195,11 @@ public: void operator-=(const Matrix44 &m); void operator*=( const Matrix44 & m ); void operator*=( const T k ); - - void ToMatrix(Matrix44 & m) const {for(int i = 0; i < 16; i++) m.V()[i]=V()[i];} - void FromMatrix(const Matrix44 & m){for(int i = 0; i < 16; i++) V()[i]=m.V()[i];} + + template + void ToMatrix(Matrix44Type & m) const {for(int i = 0; i < 16; i++) m.V()[i]=V()[i];} + template + void FromMatrix(const Matrix44Type & m){for(int i = 0; i < 16; i++) V()[i]=m.V()[i];} void SetZero(); void SetIdentity(); void SetDiagonal(const T k); diff --git a/vcg/math/quaternion.h b/vcg/math/quaternion.h index 8dbc60b6..3196c410 100644 --- a/vcg/math/quaternion.h +++ b/vcg/math/quaternion.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.9 2004/10/22 14:35:42 ponchio +m.element(x, y) -> m[x][y] + Revision 1.8 2004/10/07 13:54:03 ganovelli added SetIdentity @@ -32,6 +35,9 @@ updated access to matrix44 elements through V() instead simple [] Revision 1.6 2004/03/25 14:57:49 ponchio Microerror. ($LOG$ -> $Log: not supported by cvs2svn $ +Microerror. ($LOG$ -> Revision 1.9 2004/10/22 14:35:42 ponchio +Microerror. ($LOG$ -> m.element(x, y) -> m[x][y] +Microerror. ($LOG$ -> Microerror. ($LOG$ -> Revision 1.8 2004/10/07 13:54:03 ganovelli Microerror. ($LOG$ -> added SetIdentity Microerror. ($LOG$ -> @@ -191,6 +197,27 @@ template void Quaternion::ToMatrix(Matrix44 &m) const { S q22 = V(3)*V(3); S q23 = V(3)*V(0); +/* <<<<<<< quaternion.h + m[0][ 0] = (S)(1.0-(q11 + q22)*2.0); + m[1][ 0] = (S)((q01 - q23)*2.0); + m[2][ 0] = (S)((q02 + q13)*2.0); + m[3][ 0] = (S)0.0; + + m[0][ 1] = (S)((q01 + q23)*2.0); + m[1][ 1] = (S)(1.0-(q22 + q00)*2.0); + m[2][ 1] = (S)((q12 - q03)*2.0); + m[3][ 1] = (S)0.0; + + m[0][ 2] = (S)((q02 - q13)*2.0); + m[1][ 2] = (S)((q12 + q03)*2.0); + m[2][ 2] = (S)(1.0-(q11 + q00)*2.0); + m[3][ 2] = (S)0.0; + + m[0][ 3] = (S)0.0; + m[1][ 3] = (S)0.0; + m[2][ 3] = (S)0.0; + m[3][ 3] = (S)1.0; +=======*/ m[0][0] = (S)(1.0-(q11 + q22)*2.0); m[1][0] = (S)((q01 - q23)*2.0); m[2][0] = (S)((q02 + q13)*2.0); @@ -210,6 +237,7 @@ template void Quaternion::ToMatrix(Matrix44 &m) const { m[1][3] = (S)0.0; m[2][3] = (S)0.0; m[3][3] = (S)1.0; +//>>>>>>> 1.9 } diff --git a/vcg/math/shot.h b/vcg/math/shot.h index 9a5bce66..116141f2 100644 --- a/vcg/math/shot.h +++ b/vcg/math/shot.h @@ -23,15 +23,6 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ -Revision 1.7 2004/11/23 10:15:38 cignoni -removed comment in comment gcc warning - -Revision 1.6 2004/11/03 09:25:52 ganovelli -replaced Matrix44f to Matrix44, added LookAt - -Revision 1.5 2004/10/22 14:29:40 ponchio -#include <...Point --> #include <...point - Revision 1.4 2004/10/07 14:41:31 fasano Little fix on ViewPoint() method @@ -50,14 +41,17 @@ Revision 1.2 2004/09/06 21:41:30 ganovelli Revision 1.1 2004/09/03 13:01:51 ganovelli creation -****************************************************************************/ +/****************************************************************************/ #ifndef __VCGLIB_SHOT #define __VCGLIB_SHOT -#include -#include +// #include +// #include +// #include +#include +#include #include #include @@ -105,9 +99,14 @@ public: /// convert a 3d point in camera coordinates vcg::Point3 ConvertToCameraCoordinates(const vcg::Point3 & p) const; + /// convert a 3d point in camera coordinates + vcg::Point3 ConvertToWorldCoordinates(const vcg::Point3 & p) const; + /// project onto the camera plane vcg::Point2 Project(const vcg::Point3 & p) const; + vcg::Point3 UnProject(const vcg::Point2 & p) const; + /// take the distance from the point p and the plane parallel to the camera plane and passing through the view /// point. The would be z depth S Depth(const vcg::Point3 & p)const; @@ -125,7 +124,7 @@ template vcg::Point3 Shot::Axis(const int & i) const { vcg::Matrix44 m; similarity.rot.ToMatrix(m); - vcg::Point3f aa = m.Row3(i); + vcg::Point3 aa = m.Row3(i); return aa; } @@ -142,23 +141,23 @@ void Shot::LookAt(const vcg::Point3 & z_dir,const vcg::Point3 & up){ template void Shot::LookAt(const S & eye_x,const S & eye_y,const S & eye_z,const S & at_x,const S & at_y,const S & at_z, const S & up_x,const S & up_y,const S & up_z){ - SetViewPoint(Point3(eye_x,eye_y,eye_z)); - LookAt(Point3(at_x,at_y,at_z),Point3(up_x,up_y,up_z)); - } + SetViewPoint(Point3(eye_x,eye_y,eye_z)); + LookAt(Point3(at_x,at_y,at_z),Point3(up_x,up_y,up_z)); +} template void Shot::LookTowards(const vcg::Point3 & z_dir,const vcg::Point3 & up){ - vcg::Point3 x_dir = up ^-z_dir ; - vcg::Point3 y_dir = -z_dir ^x_dir ; - - Matrix44 m; - m.SetIdentity(); - *(vcg::Point3 *)&m[0][0] = x_dir/x_dir.Norm(); - *(vcg::Point3 *)&m[1][0] = y_dir/y_dir.Norm(); - *(vcg::Point3 *)&m[2][0] = -z_dir/z_dir.Norm(); + vcg::Point3 x_dir = up ^-z_dir ; + vcg::Point3 y_dir = -z_dir ^x_dir ; + + Matrix44 m; + m.SetIdentity(); + *(vcg::Point3 *)&m[0][0] = x_dir/x_dir.Norm(); + *(vcg::Point3 *)&m[1][0] = y_dir/y_dir.Norm(); + *(vcg::Point3 *)&m[2][0] = -z_dir/z_dir.Norm(); - similarity.rot.FromMatrix(m); + similarity.rot.FromMatrix(m); } template @@ -168,18 +167,28 @@ vcg::Point3 Shot::ConvertToCameraCoordinates(const vcg::Point3 & p) con cp[2]=-cp[2]; return cp; } - +template +vcg::Point3 Shot::ConvertToWorldCoordinates(const vcg::Point3 & p) const{ + vcg::Point3 cp = Inverse(similarity.Matrix())*p; + // note: the World reference system is left handed + cp[2]=-cp[2]; + return cp; +} template vcg::Point2 Shot::Project(const vcg::Point3 & p) const{ return camera.Project(ConvertToCameraCoordinates(p)); } - +template +vcg::Point3 Shot::UnProject(const vcg::Point2 & p) const{ + vcg::Point3 q = camera.UnProject(p); + return ConvertToWorldCoordinates(q); +} template S Shot::Depth(const vcg::Point3 & p)const { return ConvertToCameraCoordinates(p).Z(); } -} +}; #endif diff --git a/vcg/math/similarity.h b/vcg/math/similarity.h index 47285e4c..eddf9b90 100644 --- a/vcg/math/similarity.h +++ b/vcg/math/similarity.h @@ -24,6 +24,10 @@ History $Log: not supported by cvs2svn $ +Revision 1.10 2004/10/07 13:55:47 ganovelli +templated on the kind of class used to implement rotation +(default is QUternion but it can be Matrix44 as well) + Revision 1.9 2004/06/04 13:35:07 cignoni added InverseMatrix, @@ -35,6 +39,10 @@ unified to the gl stlyle matix*vector. removed vector*matrix operator Revision 1.6 2004/03/25 14:57:49 ponchio Microerror. ($LOG$ -> $Log: not supported by cvs2svn $ +Microerror. ($LOG$ -> Revision 1.10 2004/10/07 13:55:47 ganovelli +Microerror. ($LOG$ -> templated on the kind of class used to implement rotation +Microerror. ($LOG$ -> (default is QUternion but it can be Matrix44 as well) +Microerror. ($LOG$ -> Microerror. ($LOG$ -> Revision 1.9 2004/06/04 13:35:07 cignoni Microerror. ($LOG$ -> added InverseMatrix, Microerror. ($LOG$ -> @@ -154,9 +162,9 @@ template void Similarity::FromMatri assert(sca != 0); Matrix44 t = m * Matrix44().SetScale(1/sca, 1/sca, 1/sca); rot.FromMatrix(t); - tra[0] = t.element(3, 0); - tra[1] = t.element(3, 1); - tra[2] = t.element(3, 2); + tra[0] = t.ElementAt(3, 0); + tra[1] = t.ElementAt(3, 1); + tra[2] = t.ElementAt(3, 2); } template Similarity &Invert(Similarity &a) { diff --git a/wrap/gl/camera.h b/wrap/gl/camera.h index e4a04ede..98556127 100644 --- a/wrap/gl/camera.h +++ b/wrap/gl/camera.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.3 2004/11/03 09:38:21 ganovelli +added SetSubView, some comment and put the class back(!) + Revision 1.2 2004/10/05 19:04:44 ganovelli changed from classes to functions @@ -40,6 +43,7 @@ creation // opengl #include +//<<<<<<< camera.h template struct GlCamera{ @@ -47,9 +51,20 @@ struct GlCamera{ typedef typename CameraType::ScalarType ScalarType; typedef typename CameraType::ScalarType S; - /// returns the opengl matrix corresponding to the camera static vcg::Matrix44 -MatrixGL(const vcg::Camera & cam, vcg::Matrix44 &m){ +MatrixGL(const vcg::Camera & cam, vcg::Matrix44 &m){ +//======= +// +//template +//struct GlCamera{ +// +// typedef typename CameraType::ScalarType ScalarType; +// typedef typename CameraType::ScalarType S; +// +// /// returns the opengl matrix corresponding to the camera +//static vcg::Matrix44 +//MatrixGL(const vcg::Camera & cam, vcg::Matrix44 &m){ +//>>>>>>> 1.3 glPushAttrib(GL_TRANSFORM_BIT); glMatrixMode(GL_PROJECTION); glPushMatrix(); @@ -61,18 +76,16 @@ MatrixGL(const vcg::Camera & cam, vcg::Matrix44 &m){ return m; } - /// computes the parametrs as to call the glFrustum(..) -static void -GetFrustum(const CameraType & camera, - typename CameraType::ScalarType & sx, - typename CameraType::ScalarType & dx, - typename CameraType::ScalarType & bt, - typename CameraType::ScalarType & tp, - typename CameraType::ScalarType & f , - typename CameraType::ScalarType & fr - ) -{ - dx = camera.c.X()*camera.s.X(); +//<<<<<<< camera.h +static void GetFrustum(const CameraType & camera, + typename S & sx, + typename S & dx, + typename S & bt, + typename S & tp, + typename S & f , + typename S & fr + ){ + dx = camera.c.X()*camera.s.X(); //scaled center sx = -( camera.viewport.X() - camera.c.X() ) * camera.s.X(); bt = -camera.c.Y()*camera.s.Y(); @@ -82,29 +95,89 @@ GetFrustum(const CameraType & camera, fr = camera.farend; } -/// perform the opengl trasformatino correponding to the camera -static void TransformGL(const vcg::Camera & camera,typename ScalarType farDist = -1 ) { - ScalarType sx,dx,bt,tp,nr,fr; +//======= +// /// computes the parametrs as to call the glFrustum(..) +//static void +//GetFrustum(const CameraType & camera, +// typename CameraType::ScalarType & sx, +// typename CameraType::ScalarType & dx, +// typename CameraType::ScalarType & bt, +// typename CameraType::ScalarType & tp, +// typename CameraType::ScalarType & f , +// typename CameraType::ScalarType & fr +// ) +//{ +// dx = camera.c.X()*camera.s.X(); +// sx = -( camera.viewport.X() - camera.c.X() ) * camera.s.X(); +//>>>>>>> 1.3 + +//<<<<<<< camera.h +static void TransformGL(const vcg::Camera & camera,typename S farDist = -1 ) { + S sx,dx,bt,tp,nr,fr; GetFrustum(camera,sx,dx,bt,tp,nr,fr); assert(glGetError()==0); glFrustum(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist); assert(glGetError()==0); -} +}; +//======= +// bt = -camera.c.Y()*camera.s.Y(); +// tp = ( camera.viewport.Y() - camera.c.Y() ) * camera.s.Y(); +//>>>>>>> 1.3 -/// set the view as from the camera but only in a portion of the view (c0,c1 in [0,1]x[0,1] -static void SetSubView(const CameraType & camera,vcg::Point2 c0,vcg::Point2 c1){ - typedef typename CameraType::ScalarType S; +//<<<<<<< camera.h +static void GetViewSize(const vcg::Camera & camera, typename S &width, typename S &height) { S sx,dx,bt,tp,nr,fr; GetFrustum(camera,sx,dx,bt,tp,nr,fr); + width = dx-sx; //right - left = width + height = tp-bt; //top - bottom = height +}; +//======= +// f = camera.f; +// fr = camera.farend; +//} +//>>>>>>> 1.3 + +//<<<<<<< camera.h +static void SetSubView(const CameraType & camera,vcg::Point2 p0,vcg::Point2 p1){ + //typedef typename CameraType::ScalarType S; + S sx,dx,bt,tp,nr,fr; + GetFrustum(camera,sx,dx,bt,tp,nr,fr); +//======= +///// perform the opengl trasformatino correponding to the camera +//static void TransformGL(const vcg::Camera & camera,typename ScalarType farDist = -1 ) { +// ScalarType sx,dx,bt,tp,nr,fr; +// GetFrustum(camera,sx,dx,bt,tp,nr,fr); +// assert(glGetError()==0); +// glFrustum(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist); +// assert(glGetError()==0); +//} +// +///// set the view as from the camera but only in a portion of the view (c0,c1 in [0,1]x[0,1] +//static void SetSubView(const CameraType & camera,vcg::Point2 c0,vcg::Point2 c1){ +// typedef typename CameraType::ScalarType S; +// S sx,dx,bt,tp,nr,fr; +// GetFrustum(camera,sx,dx,bt,tp,nr,fr); +//>>>>>>> 1.3 - S cv[2]; - cv[0] = dx-sx; - cv[1] = tp-bt; - glFrustum(sx + cv[0]* c0[0],sx + cv[0] * c1[0], - bt + cv[1]* c0[1],bt + cv[1] * c1[1], - nr,fr); +//<<<<<<< camera.h + S width = dx-sx; //right - left = width + S height = tp-bt; //top - bottom = height + glFrustum( + width* p0[0]+ sx, width* p1[0]+ sx, + height* p0[1]+ bt, height* p1[1]+ bt, + nr,fr); assert(glGetError()==0); -} +}; +//======= +// S cv[2]; +// cv[0] = dx-sx; +// cv[1] = tp-bt; +// glFrustum(sx + cv[0]* c0[0],sx + cv[0] * c1[0], +// bt + cv[1]* c0[1],bt + cv[1] * c1[1], +// nr,fr); +// assert(glGetError()==0); +//} +//>>>>>>> 1.3 }; #endif diff --git a/wrap/gl/shot.h b/wrap/gl/shot.h index 052d2c94..f64032ac 100644 --- a/wrap/gl/shot.h +++ b/wrap/gl/shot.h @@ -23,6 +23,9 @@ /**************************************************************************** History $Log: not supported by cvs2svn $ +Revision 1.3 2004/11/03 09:41:57 ganovelli +added FromTrackball and fixed include names (Poiint to point) + Revision 1.2 2004/10/05 19:04:45 ganovelli changed from classes to functions @@ -41,11 +44,11 @@ creation #ifndef __VCGLIB_GLSHOT #define __VCGLIB_GLSHOT - // include vcg stuff #include #include #include + #include // include wrap stuff @@ -59,61 +62,78 @@ struct GlShot { typedef typename ShotType::ScalarType ScalarType; typedef typename GlCamera GlCameraType; -/// takes the opengl matrix corresponding to the shot -static void MatrixGL(const ShotType & shot,vcg::Matrix44 & m) { +static void MatrixGL(const ShotType & shot,vcg::Matrix44 & m) { m = shot.similarity.Matrix(); } -/// perform the model transformation correspoding to the shot -static void TransformGL(const vcg::Shot & shot){ - vcg::Matrix44 m; - MatrixGL(shot,m); - glMultMatrix(m); - } - -/// set the view as from the shot -static void SetView(const vcg::Shot & shot){ - assert(glGetError() == 0); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - - assert(glGetError() == 0); - GlCameraType::TransformGL(shot.camera); // apply camera/modelview transformation - assert(glGetError() == 0); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - vcg::Matrix44 m; - TransformGL(shot); // apply similarity/modelview transformation - assert(glGetError() == 0); +static void TransformGL(const vcg::Shot & shot){ + vcg::Matrix44 m; + MatrixGL(shot,m); + glMultMatrix(m); } -/// unset the view -static void UnsetView(){ - glPushAttrib(GL_TRANSFORM_BIT); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glPopAttrib(); - } +static void SetView(const vcg::Shot & shot){ + assert(glGetError() == 0); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + assert(glGetError() == 0); + GlCameraType::TransformGL(shot.camera); // apply camera/modelview transformation + assert(glGetError() == 0); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + GlShot::TransformGL(shot); // apply similarity/modelview transformation + assert(glGetError() == 0); +} +static void SetSubView(vcg::Shot & shot, + vcg::Point2 p1, + vcg::Point2 p2) +{ + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + assert(glGetError() == 0); + GlCameraType::SetSubView(shot.Camera(),p1,p2); + assert(glGetError() == 0); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + GlShot::TransformGL(shot); // apply similarity/modelview transformation + assert(glGetError() == 0); +} + +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 ; +// takes a shot and a trackball and retursn 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(); + vcg::Point3 vpf = vcg::Point3(vp[0],vp[1],vp[2]); + vcg::Matrix44 trInvM = tr.track.InverseMatrix(); - vcg::Matrix44 trInv = tr.track.InverseMatrix(); - nvp = trInv*vp; - shot.SetViewPoint(nvp+tr.center); - shot.similarity.rot = trInv*sShot.similarity.rot; + vcg::Matrix44 trM; /*=*/ trM.FromMatrix(tr.track.Matrix()); + + vcg::Point3 nvp = trInvM*vpf;// nvp = shInvM*nvp; + + shot.SetViewPoint(vcg::Point3(nvp[0],nvp[1],nvp[2])); + shot.similarity.rot = sShot.similarity.rot*trM; + shot.similarity.sca = sShot.similarity.sca*tr.track.sca; } - }; #endif diff --git a/wrap/gl/trimesh.h b/wrap/gl/trimesh.h index 9db8cc34..716ed3dd 100644 --- a/wrap/gl/trimesh.h +++ b/wrap/gl/trimesh.h @@ -24,6 +24,9 @@ History $Log: not supported by cvs2svn $ +Revision 1.4 2004/09/30 01:40:39 ponchio + --> + Revision 1.3 2004/07/13 11:25:57 pietroni changed order of initial include ( it had problems with extension of openGL) @@ -365,7 +368,7 @@ void DrawFill() else if(h&HNUseTriStrip) - { + { //if( (nm==NMPerVert) && ((cm==CMNone) || (cm==CMPerMesh))) // if(h&HNUseVArray){ // glEnableClientState (GL_NORMAL_ARRAY );