added SetSubView, some comment and put the class back(!)
This commit is contained in:
parent
d0c1352cf3
commit
a66d6d3ebd
wrap/gl
|
@ -23,64 +23,90 @@
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
History
|
History
|
||||||
$Log: not supported by cvs2svn $
|
$Log: not supported by cvs2svn $
|
||||||
|
Revision 1.2 2004/10/05 19:04:44 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
|
||||||
|
|
||||||
Revision 1.2 2004/09/06 21:41:30 ganovelli
|
|
||||||
*** empty log message ***
|
|
||||||
|
|
||||||
Revision 1.1 2004/09/03 13:01:51 ganovelli
|
|
||||||
creation
|
|
||||||
|
|
||||||
/****************************************************************************/
|
/****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __GL_CAMERA
|
#ifndef __GL_CAMERA
|
||||||
#define __GL_CAMERA
|
#define __GL_CAMERA
|
||||||
#include <QMessageBox.h>
|
|
||||||
// VCG
|
// VCG
|
||||||
#include <vcg/math/camera.h>
|
#include <vcg/math/camera.h>
|
||||||
|
|
||||||
// opengl
|
// opengl
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
template<class CameraType>
|
|
||||||
vcg::Matrix44<typename CameraType::ScalarType>
|
template <class CameraType>
|
||||||
MatrixGL(const CameraType & cam, typename CameraType::ScalarType far,vcg::Matrix44<typename CameraType::ScalarType> &m){
|
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){
|
||||||
glPushAttrib(GL_TRANSFORM_BIT);
|
glPushAttrib(GL_TRANSFORM_BIT);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
cam.TransformGL(far);
|
TransformGL(cam);
|
||||||
glGetv(GL_PROJECTION_MATRIX,&m[0][0]);
|
glGetv(GL_PROJECTION_MATRIX,&m[0][0]);
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
glPopAttrib();
|
glPopAttrib();
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class CameraType>
|
/// computes the parametrs as to call the glFrustum(..)
|
||||||
void TransformGL(const CameraType & camera,typename CameraType::ScalarType farDist) {
|
static void
|
||||||
|
GetFrustum(const CameraType & camera,
|
||||||
/////////////////// METTERE IL FRUSTUM GIUSTO //////////////////////
|
typename CameraType::ScalarType & sx,
|
||||||
//glFrustum(1,10,2,20,1,20);
|
typename CameraType::ScalarType & dx,
|
||||||
|
typename CameraType::ScalarType & bt,
|
||||||
typedef typename CameraType::ScalarType S;
|
typename CameraType::ScalarType & tp,
|
||||||
S sx,dx,bt,tp,nr,fr;
|
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();
|
{
|
||||||
|
dx = camera.c.X()*camera.s.X();
|
||||||
|
sx = -( camera.viewport.X() - camera.c.X() ) * camera.s.X();
|
||||||
|
|
||||||
bt = -camera.c.Y()*camera.s.Y();
|
bt = -camera.c.Y()*camera.s.Y();
|
||||||
tp = ( camera.viewport.Y() - camera.c.Y() ) * camera.s.Y();
|
tp = ( camera.viewport.Y() - camera.c.Y() ) * camera.s.Y();
|
||||||
|
|
||||||
nr = camera.f;
|
f = camera.f;
|
||||||
fr = farDist; // tmp
|
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;
|
||||||
|
GetFrustum(camera,sx,dx,bt,tp,nr,fr);
|
||||||
assert(glGetError()==0);
|
assert(glGetError()==0);
|
||||||
glFrustum(dx,sx,bt,tp,nr,fr);
|
glFrustum(sx,dx,bt,tp,nr,(farDist == -1)?fr:farDist);
|
||||||
assert(glGetError()==0);
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue