Improved the anttweakbar sample now has zoom with doubleclick...
This commit is contained in:
parent
add25e7bf0
commit
858e4c575f
|
@ -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,20 +83,21 @@ GLWidget::GLWidget(QWidget *parent)
|
||||||
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
|
: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
|
||||||
{
|
{
|
||||||
filename=0;
|
filename=0;
|
||||||
setWindowTitle(tr("Hello GL"));
|
hasToPick=false;
|
||||||
bar = TwNewBar("TweakBar");
|
setWindowTitle(tr("Hello GL"));
|
||||||
TwCopyCDStringToClientFunc (CopyCDStringToClient);
|
bar = TwNewBar("TweakBar");
|
||||||
|
TwCopyCDStringToClientFunc (CopyCDStringToClient);
|
||||||
|
|
||||||
TwAddVarRW(bar,"Input",TW_TYPE_CDSTRING, &filename," label='Filepath' group=SetMesh help=` Name of the file to load` ");
|
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,"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.` ");
|
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
|
// 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"}};
|
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
|
// Create a type for the enum shapeEV
|
||||||
TwType drawMode = TwDefineEnum("DrawMode", drawmodes, 6);
|
TwType drawMode = TwDefineEnum("DrawMode", drawmodes, 6);
|
||||||
// add 'g_CurrentShape' to 'bar': this is a variable of type ShapeType. Its key shortcuts are [<] and [>].
|
// 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.' ");
|
TwAddVarRW(bar, "Draw Mode", drawMode, &drawmode, " keyIncr='<' keyDecr='>' help='Change draw mode.' ");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLWidget::initializeGL ()
|
void GLWidget::initializeGL ()
|
||||||
|
@ -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 ()));
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue