added FromTrackball and fixed include names (Poiint to point)
This commit is contained in:
parent
e70b193cf0
commit
2a8d132abd
|
@ -23,6 +23,9 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
$Log: not supported by cvs2svn $
|
$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
|
Revision 1.1 2004/09/15 22:59:13 ganovelli
|
||||||
creation
|
creation
|
||||||
|
|
||||||
|
@ -38,73 +41,80 @@ creation
|
||||||
#ifndef __VCGLIB_GLSHOT
|
#ifndef __VCGLIB_GLSHOT
|
||||||
#define __VCGLIB_GLSHOT
|
#define __VCGLIB_GLSHOT
|
||||||
|
|
||||||
// #include <vector>
|
|
||||||
// #include <vcg/Matrix44.h>
|
// include vcg stuff
|
||||||
// #include <vcg/Box3.h>
|
#include <vcg/space/point2.h>
|
||||||
|
#include <vcg/space/point3.h>
|
||||||
#include <vcg/math/similarity.h>
|
#include <vcg/math/similarity.h>
|
||||||
#include <vcg/space/Point2.h>
|
|
||||||
#include <vcg/space/Point3.h>
|
|
||||||
#include <vcg/math/shot.h>
|
#include <vcg/math/shot.h>
|
||||||
|
|
||||||
|
// include wrap stuff
|
||||||
|
#include <wrap/gui/trackball.h>
|
||||||
#include <wrap/gl/math.h>
|
#include <wrap/gl/math.h>
|
||||||
#include <wrap/gl/camera.h>
|
#include <wrap/gl/camera.h>
|
||||||
|
|
||||||
#include <dbgUti.h>
|
template <class ShotType>
|
||||||
|
struct GlShot {
|
||||||
|
|
||||||
|
typedef typename ShotType::ScalarType ScalarType;
|
||||||
|
typedef typename GlCamera<typename ShotType::CameraType> GlCameraType;
|
||||||
|
|
||||||
template<class ShotType>
|
/// takes the opengl matrix corresponding to the shot
|
||||||
void MatrixGL(const ShotType & shot,vcg::Matrix44<typename ShotType::ScalarType> & m) {
|
static void MatrixGL(const ShotType & shot,vcg::Matrix44<typename ShotType::ScalarType> & m) {
|
||||||
m = shot.similarity.Matrix();
|
m = shot.similarity.Matrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// perform the model transformation correspoding to the shot
|
||||||
template<class ShotType>
|
static void TransformGL(const vcg::Shot<typename ShotType::ScalarType> & shot){
|
||||||
void TransformGL(const ShotType & shot){
|
vcg::Matrix44<ScalarType> m;
|
||||||
vcg::Matrix44<typename ShotType::ScalarType> m;
|
|
||||||
MatrixGL(shot,m);
|
MatrixGL(shot,m);
|
||||||
glMultMatrix(m);
|
glMultMatrix(m);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class ShotType>
|
/// set the view as from the shot
|
||||||
void SetView(const ShotType & shot){
|
static void SetView(const vcg::Shot<typename ShotType::ScalarType> & shot){
|
||||||
assert(glGetError() == 0);
|
assert(glGetError() == 0);
|
||||||
glPushAttrib(GL_TRANSFORM_BIT);
|
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
assert(glGetError() == 0);
|
|
||||||
|
|
||||||
OutMatrix("mat.txt","a+");
|
|
||||||
assert(glGetError() == 0);
|
assert(glGetError() == 0);
|
||||||
|
GlCameraType::TransformGL(shot.camera); // apply camera/modelview transformation
|
||||||
TransformGL(shot.camera,1.f);
|
|
||||||
assert(glGetError() == 0);
|
|
||||||
|
|
||||||
OutMatrix("mat.txt","a+");
|
|
||||||
assert(glGetError() == 0);
|
assert(glGetError() == 0);
|
||||||
|
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
vcg::Matrix44<typename ShotType::ScalarType> m;
|
vcg::Matrix44<ScalarType> m;
|
||||||
TransformGL(shot);
|
TransformGL(shot); // apply similarity/modelview transformation
|
||||||
|
|
||||||
glPopAttrib();
|
|
||||||
|
|
||||||
assert(glGetError() == 0);
|
assert(glGetError() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define UnsetView()\
|
/// unset the view
|
||||||
glPushAttrib(GL_TRANSFORM_BIT);\
|
static void UnsetView(){
|
||||||
glMatrixMode(GL_MODELVIEW);\
|
glPushAttrib(GL_TRANSFORM_BIT);
|
||||||
glPopMatrix();\
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glMatrixMode(GL_PROJECTION);\
|
glPopMatrix();
|
||||||
glPopMatrix();\
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPopAttrib();\
|
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 ;
|
||||||
|
|
||||||
|
vcg::Matrix44<ScalarType> trInv = tr.track.InverseMatrix();
|
||||||
|
nvp = trInv*vp;
|
||||||
|
shot.SetViewPoint(nvp+tr.center);
|
||||||
|
shot.similarity.rot = trInv*sShot.similarity.rot;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue