*** empty log message ***

This commit is contained in:
Paolo Cignoni 2004-12-15 18:45:50 +00:00
parent 45154f0716
commit 02aee67598
8 changed files with 319 additions and 149 deletions

View File

@ -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 <vcg/space/point3.h>
#include <vcg/space/point2.h>
#include <vcg/space/Point3.h>
#include <vcg/space/Point2.h>
#include <vcg/math/similarity.h>
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> s; // Scale factor of the image (nei casi in cui a senso)
vcg::Point2<S> c; // pin-hole position
vcg::Point2<int> 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> s; // Scale factor of the image (nei casi in cui a senso)
vcg::Point2<S> 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<int> 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<S> viewport=vcg::Point2<S>(500,-1) );
inline void SetPerspective(S angle, S ratio, S near, S farend,vcg::Point2<S> viewport=vcg::Point2<S>(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<S> viewport=vcg::Point2<S>(500,-1));
inline void SetFrustum(S dx, S sx, S bt, S tp, S near, S farend,vcg::Point2<S> viewport=vcg::Point2<S>(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<S> Project(const vcg::Point3<S> & p);
inline vcg::Point3<S> UnProject(const vcg::Point2<S> & p);
};
/// project a point in the camera plane
@ -132,38 +137,57 @@ vcg::Point2<S> Camera<S>::Project(const vcg::Point3<S> & p){
}
return q;
}
/// unproject a point from the camera plane
template<class S>
vcg::Point3<S> Camera<S>::UnProject(const vcg::Point2<S> & p){
S tx = p.X();
S ty = p.Y();
/// set the camera specifying the perspecive view
template<class S>
void Camera<S>::SetPerspective(S angle, S ratio, S nr, S _farend,vcg::Point2<S> 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<S> q(0,0,0);
/// set the camera specifying the frustum view
template<class S>
void Camera<S>::SetFrustum(S sx, S dx, S bt, S tp, S nr, S _farend,vcg::Point2<S> 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<class S>
void Camera<S>::SetPerspective(S angle, S ratio, S nr, S _far,vcg::Point2<S> 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<class S>
void Camera<S>::SetFrustum(S sx, S dx, S bt, S tp, S nr, S _far,vcg::Point2<S> 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;
}
}

View File

@ -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 <class Matrix44Type>
void ToMatrix(Matrix44Type & m) const {for(int i = 0; i < 16; i++) m.V()[i]=V()[i];}
template <class Matrix44Type>
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);

View File

@ -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 <class S> void Quaternion<S>::ToMatrix(Matrix44<S> &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 <class S> void Quaternion<S>::ToMatrix(Matrix44<S> &m) const {
m[1][3] = (S)0.0;
m[2][3] = (S)0.0;
m[3][3] = (S)1.0;
//>>>>>>> 1.9
}

View File

@ -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<S>, 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 <vcg/space/point2.h>
#include <vcg/space/point3.h>
// #include <vector>
// #include <vcg/Matrix44.h>
// #include <vcg/Box3.h>
#include <vcg/space/Point2.h>
#include <vcg/space/Point3.h>
#include <vcg/math/similarity.h>
#include <vcg/math/camera.h>
@ -105,9 +99,14 @@ public:
/// convert a 3d point in camera coordinates
vcg::Point3<S> ConvertToCameraCoordinates(const vcg::Point3<S> & p) const;
/// convert a 3d point in camera coordinates
vcg::Point3<S> ConvertToWorldCoordinates(const vcg::Point3<S> & p) const;
/// project onto the camera plane
vcg::Point2<S> Project(const vcg::Point3<S> & p) const;
vcg::Point3<S> UnProject(const vcg::Point2<S> & 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<S> & p)const;
@ -125,7 +124,7 @@ template <class S>
vcg::Point3<S> Shot<S>::Axis(const int & i) const {
vcg::Matrix44<S> m;
similarity.rot.ToMatrix(m);
vcg::Point3f aa = m.Row3(i);
vcg::Point3<S> aa = m.Row3(i);
return aa;
}
@ -142,23 +141,23 @@ void Shot<S>::LookAt(const vcg::Point3<S> & z_dir,const vcg::Point3<S> & up){
template <class S>
void Shot<S>::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<S>(eye_x,eye_y,eye_z));
LookAt(Point3<S>(at_x,at_y,at_z),Point3<S>(up_x,up_y,up_z));
}
SetViewPoint(Point3<S>(eye_x,eye_y,eye_z));
LookAt(Point3<S>(at_x,at_y,at_z),Point3<S>(up_x,up_y,up_z));
}
template <class S>
void Shot<S>::LookTowards(const vcg::Point3<S> & z_dir,const vcg::Point3<S> & up){
vcg::Point3<S> x_dir = up ^-z_dir ;
vcg::Point3<S> y_dir = -z_dir ^x_dir ;
Matrix44<S> m;
m.SetIdentity();
*(vcg::Point3<S> *)&m[0][0] = x_dir/x_dir.Norm();
*(vcg::Point3<S> *)&m[1][0] = y_dir/y_dir.Norm();
*(vcg::Point3<S> *)&m[2][0] = -z_dir/z_dir.Norm();
vcg::Point3<S> x_dir = up ^-z_dir ;
vcg::Point3<S> y_dir = -z_dir ^x_dir ;
Matrix44<S> m;
m.SetIdentity();
*(vcg::Point3<S> *)&m[0][0] = x_dir/x_dir.Norm();
*(vcg::Point3<S> *)&m[1][0] = y_dir/y_dir.Norm();
*(vcg::Point3<S> *)&m[2][0] = -z_dir/z_dir.Norm();
similarity.rot.FromMatrix(m);
similarity.rot.FromMatrix(m);
}
template <class S>
@ -168,18 +167,28 @@ vcg::Point3<S> Shot<S>::ConvertToCameraCoordinates(const vcg::Point3<S> & p) con
cp[2]=-cp[2];
return cp;
}
template <class S>
vcg::Point3<S> Shot<S>::ConvertToWorldCoordinates(const vcg::Point3<S> & p) const{
vcg::Point3<S> cp = Inverse(similarity.Matrix())*p;
// note: the World reference system is left handed
cp[2]=-cp[2];
return cp;
}
template <class S>
vcg::Point2<S> Shot<S>::Project(const vcg::Point3<S> & p) const{
return camera.Project(ConvertToCameraCoordinates(p));
}
template <class S>
vcg::Point3<S> Shot<S>::UnProject(const vcg::Point2<S> & p) const{
vcg::Point3<S> q = camera.UnProject(p);
return ConvertToWorldCoordinates(q);
}
template <class S>
S Shot<S>::Depth(const vcg::Point3<S> & p)const {
return ConvertToCameraCoordinates(p).Z();
}
}
};
#endif

View File

@ -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 <class S,class RotationType> void Similarity<S,RotationType>::FromMatri
assert(sca != 0);
Matrix44<S> t = m * Matrix44<S>().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 <class S,class RotationType> Similarity<S,RotationType> &Invert(Similarity<S,RotationType> &a) {

View File

@ -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 <GL/glew.h>
//<<<<<<< camera.h
template <class CameraType>
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<ScalarType>
MatrixGL(const vcg::Camera<ScalarType> & cam, vcg::Matrix44<ScalarType> &m){
MatrixGL(const vcg::Camera<S> & cam, vcg::Matrix44<S> &m){
//=======
//
//template <class CameraType>
//struct GlCamera{
//
// typedef typename CameraType::ScalarType ScalarType;
// typedef typename CameraType::ScalarType S;
//
// /// returns the opengl matrix corresponding to the camera
//static vcg::Matrix44<ScalarType>
//MatrixGL(const vcg::Camera<ScalarType> & cam, vcg::Matrix44<ScalarType> &m){
//>>>>>>> 1.3
glPushAttrib(GL_TRANSFORM_BIT);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
@ -61,18 +76,16 @@ MatrixGL(const vcg::Camera<ScalarType> & cam, vcg::Matrix44<ScalarType> &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<ScalarType> & 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<S> & 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<S> c0,vcg::Point2<S> c1){
typedef typename CameraType::ScalarType S;
//<<<<<<< camera.h
static void GetViewSize(const vcg::Camera<S> & 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<S> p0,vcg::Point2<S> 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<ScalarType> & 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<S> c0,vcg::Point2<S> 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

View File

@ -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 <vcg/space/point2.h>
#include <vcg/space/point3.h>
#include <vcg/math/similarity.h>
#include <vcg/math/shot.h>
// include wrap stuff
@ -59,61 +62,78 @@ struct GlShot {
typedef typename ShotType::ScalarType ScalarType;
typedef typename GlCamera<typename ShotType::CameraType> GlCameraType;
/// takes the opengl matrix corresponding to the shot
static void MatrixGL(const ShotType & shot,vcg::Matrix44<typename ShotType::ScalarType> & m) {
static void MatrixGL(const ShotType & shot,vcg::Matrix44<ScalarType> & m) {
m = shot.similarity.Matrix();
}
/// perform the model transformation correspoding to the shot
static void TransformGL(const vcg::Shot<typename ShotType::ScalarType> & shot){
vcg::Matrix44<ScalarType> m;
MatrixGL(shot,m);
glMultMatrix(m);
}
/// set the view as from the shot
static void SetView(const vcg::Shot<typename ShotType::ScalarType> & 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<ScalarType> m;
TransformGL(shot); // apply similarity/modelview transformation
assert(glGetError() == 0);
static void TransformGL(const vcg::Shot<ScalarType> & shot){
vcg::Matrix44<ScalarType> 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<ScalarType> & 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<ShotType>::TransformGL(shot); // apply similarity/modelview transformation
assert(glGetError() == 0);
}
static void SetSubView(vcg::Shot<ScalarType> & shot,
vcg::Point2<ScalarType> p1,
vcg::Point2<ScalarType> p2)
{
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
assert(glGetError() == 0);
GlCameraType::SetSubView(shot.Camera(),p1,p2);
assert(glGetError() == 0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
GlShot<ShotType>::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<typename ShotType::ScalarType> & sShot,
vcg::Shot<ScalarType> & shot ){
vcg::Point3<ScalarType> vp = sShot.ViewPoint()-tr.center;
vcg::Point3<ScalarType> 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<ScalarType> & sShot,
vcg::Shot<ScalarType> & shot )
{
vcg::Point3<ScalarType> vp = sShot.ViewPoint();
vcg::Point3<float> vpf = vcg::Point3<float>(vp[0],vp[1],vp[2]);
vcg::Matrix44<float> trInvM = tr.track.InverseMatrix();
vcg::Matrix44<ScalarType> trInv = tr.track.InverseMatrix();
nvp = trInv*vp;
shot.SetViewPoint(nvp+tr.center);
shot.similarity.rot = trInv*sShot.similarity.rot;
vcg::Matrix44<ScalarType> trM; /*=*/ trM.FromMatrix(tr.track.Matrix());
vcg::Point3<float> nvp = trInvM*vpf;// nvp = shInvM*nvp;
shot.SetViewPoint(vcg::Point3<ScalarType>(nvp[0],nvp[1],nvp[2]));
shot.similarity.rot = sShot.similarity.rot*trM;
shot.similarity.sca = sShot.similarity.sca*tr.track.sca;
}
};
#endif

View File

@ -24,6 +24,9 @@
History
$Log: not supported by cvs2svn $
Revision 1.4 2004/09/30 01:40:39 ponchio
<gl/glew.h> --> <GL/glew.h>
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 );