Improved the anttweakbar sample now has zoom with doubleclick...

This commit is contained in:
Paolo Cignoni 2012-03-04 16:26:15 +00:00
parent add25e7bf0
commit 858e4c575f
3 changed files with 41 additions and 17 deletions

View File

@ -44,6 +44,7 @@
#include "glwidget.h" #include "glwidget.h"
#include <wrap/qt/trackball.h> #include <wrap/qt/trackball.h>
#include <wrap/gl/picking.h>
#include <wrap/qt/anttweakbarMapper.h> #include <wrap/qt/anttweakbarMapper.h>
enum DrawMode{SMOOTH=vcg::GLW::DMSmooth, POINTS=vcg::GLW::DMPoints , WIRE, FLATWIRE,HIDDEN,FLAT}; enum DrawMode{SMOOTH=vcg::GLW::DMSmooth, POINTS=vcg::GLW::DMPoints , WIRE, FLATWIRE,HIDDEN,FLAT};
@ -82,6 +83,7 @@ GLWidget::GLWidget(QWidget *parent)
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{ {
filename=0; filename=0;
hasToPick=false;
setWindowTitle(tr("Hello GL")); setWindowTitle(tr("Hello GL"));
bar = TwNewBar("TweakBar"); bar = TwNewBar("TweakBar");
TwCopyCDStringToClientFunc (CopyCDStringToClient); TwCopyCDStringToClientFunc (CopyCDStringToClient);
@ -124,21 +126,33 @@ void GLWidget::paintGL ()
gluPerspective(40, GLWidget::width()/(float)GLWidget::height(), 0.1, 100); gluPerspective(40, GLWidget::width()/(float)GLWidget::height(), 0.1, 100);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
gluLookAt(0,0,5, 0,0,0, 0,1,0); gluLookAt(0,0,3.5f, 0,0,0, 0,1,0);
track.center=vcg::Point3f(0, 0, 0); track.center=vcg::Point3f(0, 0, 0);
track.radius= 1; track.radius= 1;
track.GetView(); track.GetView();
glPushMatrix();
track.Apply(false); track.Apply(false);
glPushMatrix(); glPushMatrix();
if(mesh.vert.size()>0) if(mesh.vert.size()>0)
{ {
float d=1.0f/mesh.bbox.Diag(); vcg::glScale(2.0f/mesh.bbox.Diag());
vcg::glScale(d);
glTranslate(-mesh.bbox.Center()); glTranslate(-mesh.bbox.Center());
glWrap.Draw(GLW::DrawMode(drawmode),GLW::CMNone,GLW::TMNone); glWrap.Draw(GLW::DrawMode(drawmode),GLW::CMNone,GLW::TMNone);
} }
glPopMatrix(); glPopMatrix();
track.DrawPostApply(); track.DrawPostApply();
glPopMatrix();
if(hasToPick)
{
hasToPick=false;
Point3f pp;
if(Pick<Point3f>(pointToPick[0],pointToPick[1],pp))
{
track.Translate(-pp);
track.Scale(1.25f);
QCursor::setPos(mapToGlobal(QPoint(width()/2+2,height()/2+2)));
}
}
TwDraw(); TwDraw();
} }
@ -183,6 +197,14 @@ void GLWidget::mouseMoveEvent (QMouseEvent * e)
TwMouseMotion(e->x (), e->y ()); TwMouseMotion(e->x (), e->y ());
} }
void GLWidget::mouseDoubleClickEvent (QMouseEvent * e)
{
hasToPick=true;
pointToPick=Point2i(e->x(),height()-e->y());
updateGL ();
}
void GLWidget::mouseReleaseEvent (QMouseEvent * e) void GLWidget::mouseReleaseEvent (QMouseEvent * e)
{ {
track.MouseUp (e->x (), height () - e->y (), QT2VCG (e->button (), e->modifiers ())); track.MouseUp (e->x (), height () - e->y (), QT2VCG (e->button (), e->modifiers ()));

View File

@ -75,7 +75,8 @@ class GLWidget : public QGLWidget
public: public:
GLWidget(QWidget *parent = 0); GLWidget(QWidget *parent = 0);
bool hasToPick;
Point2i pointToPick;
~GLWidget() {}; ~GLWidget() {};
QSize sizeHint() const { QSize sizeHint() const {
@ -89,6 +90,7 @@ protected:
void mousePressEvent(QMouseEvent *event); void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);
void mouseDoubleClickEvent ( QMouseEvent * event );
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event);
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);

View File

@ -32,6 +32,6 @@ mac{
# Mac specific Config required to avoid to make application bundles # Mac specific Config required to avoid to make application bundles
CONFIG -= app_bundle CONFIG -= app_bundle
LIBS +=$$ANTDIR/lib/libAntTweakBar.dylib LIBS +=$$ANTDIR/lib/libAntTweakBar.dylib
QMAKE_POST_LINK ="cp -P ../../../../code/lib/AntTweakBar1.14/lib/libAntTweakBar.dylib . ; install_name_tool -change ../lib/libAntTweakBar.dylib ./libAntTweakBar.dylib trimesh_ant_qt" QMAKE_POST_LINK ="cp -P ../../../../code/lib/AntTweakBar1.14/lib/libAntTweakBar.dylib . ; install_name_tool -change ../lib/libAntTweakBar.dylib ./libAntTweakBar.dylib $$TARGET"
} }