From 858e4c575fb657bfb0d21fc37dab17ba5a981148 Mon Sep 17 00:00:00 2001 From: cignoni Date: Sun, 4 Mar 2012 16:26:15 +0000 Subject: [PATCH] Improved the anttweakbar sample now has zoom with doubleclick... --- apps/sample/trimesh_ant_qt/glwidget.cpp | 52 +++++++++++++------ apps/sample/trimesh_ant_qt/glwidget.h | 4 +- apps/sample/trimesh_ant_qt/trimesh_ant_qt.pro | 2 +- 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/apps/sample/trimesh_ant_qt/glwidget.cpp b/apps/sample/trimesh_ant_qt/glwidget.cpp index 073eeddf..7298ac27 100644 --- a/apps/sample/trimesh_ant_qt/glwidget.cpp +++ b/apps/sample/trimesh_ant_qt/glwidget.cpp @@ -44,6 +44,7 @@ #include "glwidget.h" #include +#include #include enum DrawMode{SMOOTH=vcg::GLW::DMSmooth, POINTS=vcg::GLW::DMPoints , WIRE, FLATWIRE,HIDDEN,FLAT}; @@ -82,20 +83,21 @@ GLWidget::GLWidget(QWidget *parent) : QGLWidget(QGLFormat(QGL::SampleBuffers), parent) { filename=0; - setWindowTitle(tr("Hello GL")); - bar = TwNewBar("TweakBar"); - TwCopyCDStringToClientFunc (CopyCDStringToClient); + hasToPick=false; + setWindowTitle(tr("Hello GL")); + bar = TwNewBar("TweakBar"); + TwCopyCDStringToClientFunc (CopyCDStringToClient); - TwAddVarRW(bar,"Input",TW_TYPE_CDSTRING, &filename," label='Filepath' group=SetMesh help=` Name of the file to load` "); - TwAddButton(bar,"Load from file",loadMesh,0, " label='Load Mesh' group=SetMesh help=`load the mesh` "); - TwAddButton(bar,"Use tetrahedron",loadTetrahedron,0, " label='Make Tetrahedron' group=SetMesh help=`use tetrahedron.` "); + TwAddVarRW(bar,"Input",TW_TYPE_CDSTRING, &filename," label='Filepath' group=SetMesh help=` Name of the file to load` "); + TwAddButton(bar,"Load from file",loadMesh,0, " label='Load Mesh' group=SetMesh help=`load the mesh` "); + TwAddButton(bar,"Use tetrahedron",loadTetrahedron,0, " label='Make Tetrahedron' group=SetMesh help=`use tetrahedron.` "); - // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values - TwEnumVal drawmodes[6] = { {GLW::DMSmooth, "Smooth"}, {GLW::DMPoints, "Per Points"}, {GLW::DMWire, "Wire"}, {GLW::DMFlatWire, "FlatWire"},{GLW::DMHidden, "Hidden"},{GLW::DMFlat, "Flat"}}; - // Create a type for the enum shapeEV - TwType drawMode = TwDefineEnum("DrawMode", drawmodes, 6); - // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>]. - TwAddVarRW(bar, "Draw Mode", drawMode, &drawmode, " keyIncr='<' keyDecr='>' help='Change draw mode.' "); + // ShapeEV associates Shape enum values with labels that will be displayed instead of enum values + TwEnumVal drawmodes[6] = { {GLW::DMSmooth, "Smooth"}, {GLW::DMPoints, "Per Points"}, {GLW::DMWire, "Wire"}, {GLW::DMFlatWire, "FlatWire"},{GLW::DMHidden, "Hidden"},{GLW::DMFlat, "Flat"}}; + // Create a type for the enum shapeEV + TwType drawMode = TwDefineEnum("DrawMode", drawmodes, 6); + // add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>]. + TwAddVarRW(bar, "Draw Mode", drawMode, &drawmode, " keyIncr='<' keyDecr='>' help='Change draw mode.' "); } void GLWidget::initializeGL () @@ -124,21 +126,33 @@ void GLWidget::paintGL () gluPerspective(40, GLWidget::width()/(float)GLWidget::height(), 0.1, 100); glMatrixMode(GL_MODELVIEW); 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.radius= 1; track.GetView(); + glPushMatrix(); track.Apply(false); glPushMatrix(); if(mesh.vert.size()>0) { - float d=1.0f/mesh.bbox.Diag(); - vcg::glScale(d); + vcg::glScale(2.0f/mesh.bbox.Diag()); glTranslate(-mesh.bbox.Center()); glWrap.Draw(GLW::DrawMode(drawmode),GLW::CMNone,GLW::TMNone); } glPopMatrix(); track.DrawPostApply(); + glPopMatrix(); + if(hasToPick) + { + hasToPick=false; + Point3f pp; + if(Pick(pointToPick[0],pointToPick[1],pp)) + { + track.Translate(-pp); + track.Scale(1.25f); + QCursor::setPos(mapToGlobal(QPoint(width()/2+2,height()/2+2))); + } + } TwDraw(); } @@ -183,6 +197,14 @@ void GLWidget::mouseMoveEvent (QMouseEvent * e) 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) { track.MouseUp (e->x (), height () - e->y (), QT2VCG (e->button (), e->modifiers ())); diff --git a/apps/sample/trimesh_ant_qt/glwidget.h b/apps/sample/trimesh_ant_qt/glwidget.h index ee8d82d5..2925c867 100644 --- a/apps/sample/trimesh_ant_qt/glwidget.h +++ b/apps/sample/trimesh_ant_qt/glwidget.h @@ -75,7 +75,8 @@ class GLWidget : public QGLWidget public: GLWidget(QWidget *parent = 0); - + bool hasToPick; + Point2i pointToPick; ~GLWidget() {}; QSize sizeHint() const { @@ -89,6 +90,7 @@ protected: void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); + void mouseDoubleClickEvent ( QMouseEvent * event ); void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); void wheelEvent(QWheelEvent *event); diff --git a/apps/sample/trimesh_ant_qt/trimesh_ant_qt.pro b/apps/sample/trimesh_ant_qt/trimesh_ant_qt.pro index 76c15768..74fda474 100644 --- a/apps/sample/trimesh_ant_qt/trimesh_ant_qt.pro +++ b/apps/sample/trimesh_ant_qt/trimesh_ant_qt.pro @@ -32,6 +32,6 @@ mac{ # Mac specific Config required to avoid to make application bundles CONFIG -= app_bundle 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" }