updated the basic qt opengl example to support qt 5.0 ways of managing coords
(simply use the new QT2VCG_X/Y helper functions to translate mouse events)
This commit is contained in:
parent
276438958f
commit
fc047dbe3f
|
@ -8,7 +8,7 @@
|
||||||
* \ *
|
* \ *
|
||||||
* All rights reserved. *
|
* All rights reserved. *
|
||||||
* *
|
* *
|
||||||
* This program is free software; you can redistribute it and/or modify *
|
* This program is free software; you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU General Public License as published by *
|
* it under the terms of the GNU General Public License as published by *
|
||||||
* the Free Software Foundation; either version 2 of the License, or *
|
* the Free Software Foundation; either version 2 of the License, or *
|
||||||
* (at your option) any later version. *
|
* (at your option) any later version. *
|
||||||
|
@ -40,52 +40,52 @@ Initial release.
|
||||||
GLArea::GLArea (QWidget * parent)
|
GLArea::GLArea (QWidget * parent)
|
||||||
:QGLWidget (parent)
|
:QGLWidget (parent)
|
||||||
{
|
{
|
||||||
drawmode= SMOOTH;
|
drawmode= SMOOTH;
|
||||||
GLArea::loadTetrahedron();
|
GLArea::loadTetrahedron();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::selectDrawMode(int mode){
|
void GLArea::selectDrawMode(int mode){
|
||||||
drawmode=DrawMode(mode);
|
drawmode=DrawMode(mode);
|
||||||
updateGL();
|
updateGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::loadMesh(QString fileName)
|
void GLArea::loadMesh(QString fileName)
|
||||||
{
|
{
|
||||||
int err=vcg::tri::io::ImporterPLY<CMesh>::Open(mesh,(fileName.toStdString()).c_str());
|
int err=vcg::tri::io::ImporterPLY<CMesh>::Open(mesh,(fileName.toStdString()).c_str());
|
||||||
if(err!=0){
|
if(err!=0){
|
||||||
const char* errmsg=vcg::tri::io::ImporterPLY<CMesh>::ErrorMsg(err);
|
const char* errmsg=vcg::tri::io::ImporterPLY<CMesh>::ErrorMsg(err);
|
||||||
QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg));
|
QMessageBox::warning(this,tr("Error Loading Mesh"),QString(errmsg));
|
||||||
}
|
}
|
||||||
initMesh("Loaded \""+fileName+"\".");
|
initMesh("Loaded \""+fileName+"\".");
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::loadTetrahedron(){
|
void GLArea::loadTetrahedron(){
|
||||||
vcg::tri::Tetrahedron(mesh);
|
vcg::tri::Tetrahedron(mesh);
|
||||||
initMesh(tr("Tethraedron [builtin]"));
|
initMesh(tr("Tethraedron [builtin]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::loadDodecahedron(){
|
void GLArea::loadDodecahedron(){
|
||||||
vcg::tri::Dodecahedron(mesh);
|
vcg::tri::Dodecahedron(mesh);
|
||||||
initMesh(tr("Dodecahedron [builtin]"));
|
initMesh(tr("Dodecahedron [builtin]"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::initMesh(QString message)
|
void GLArea::initMesh(QString message)
|
||||||
{
|
{
|
||||||
// update bounding box
|
// update bounding box
|
||||||
vcg::tri::UpdateBounding<CMesh>::Box(mesh);
|
vcg::tri::UpdateBounding<CMesh>::Box(mesh);
|
||||||
// update Normals
|
// update Normals
|
||||||
vcg::tri::UpdateNormal<CMesh>::PerVertexNormalizedPerFace(mesh);
|
vcg::tri::UpdateNormal<CMesh>::PerVertexNormalizedPerFace(mesh);
|
||||||
vcg::tri::UpdateNormal<CMesh>::PerFaceNormalized(mesh);
|
vcg::tri::UpdateNormal<CMesh>::PerFaceNormalized(mesh);
|
||||||
// Initialize the opengl wrapper
|
// Initialize the opengl wrapper
|
||||||
glWrap.m = &mesh;
|
glWrap.m = &mesh;
|
||||||
glWrap.Update();
|
glWrap.Update();
|
||||||
updateGL();
|
updateGL();
|
||||||
emit setStatusBar(message);
|
emit setStatusBar(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::initializeGL ()
|
void GLArea::initializeGL ()
|
||||||
{
|
{
|
||||||
glClearColor(0, 0, 0, 0);
|
glClearColor(0, 0, 0, 0);
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
glEnable(GL_LIGHT0);
|
glEnable(GL_LIGHT0);
|
||||||
glEnable(GL_NORMALIZE);
|
glEnable(GL_NORMALIZE);
|
||||||
|
@ -96,7 +96,7 @@ void GLArea::initializeGL ()
|
||||||
|
|
||||||
void GLArea::resizeGL (int w, int h)
|
void GLArea::resizeGL (int w, int h)
|
||||||
{
|
{
|
||||||
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
|
||||||
initializeGL();
|
initializeGL();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,46 +105,46 @@ void GLArea::paintGL ()
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
gluPerspective(40, GLArea::width()/(float)GLArea::height(), 0.1, 100);
|
gluPerspective(25, GLArea::width()/(float)GLArea::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,5, 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();
|
||||||
track.Apply();
|
track.Apply();
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
float d=1.0f/mesh.bbox.Diag();
|
float d=2.0f/mesh.bbox.Diag();
|
||||||
vcg::glScale(d);
|
vcg::glScale(d);
|
||||||
glTranslate(-glWrap.m->bbox.Center());
|
glTranslate(-glWrap.m->bbox.Center());
|
||||||
// the trimesh drawing calls
|
// the trimesh drawing calls
|
||||||
switch(drawmode)
|
switch(drawmode)
|
||||||
{
|
{
|
||||||
case SMOOTH:
|
case SMOOTH:
|
||||||
glWrap.Draw<vcg::GLW::DMSmooth, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
glWrap.Draw<vcg::GLW::DMSmooth, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
||||||
break;
|
break;
|
||||||
case POINTS:
|
case POINTS:
|
||||||
glWrap.Draw<vcg::GLW::DMPoints, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
glWrap.Draw<vcg::GLW::DMPoints, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
||||||
break;
|
break;
|
||||||
case WIRE:
|
case WIRE:
|
||||||
glWrap.Draw<vcg::GLW::DMWire, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
glWrap.Draw<vcg::GLW::DMWire, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
||||||
break;
|
break;
|
||||||
case FLATWIRE:
|
case FLATWIRE:
|
||||||
glWrap.Draw<vcg::GLW::DMFlatWire, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
glWrap.Draw<vcg::GLW::DMFlatWire, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
||||||
break;
|
break;
|
||||||
case HIDDEN:
|
case HIDDEN:
|
||||||
glWrap.Draw<vcg::GLW::DMHidden, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
glWrap.Draw<vcg::GLW::DMHidden, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
||||||
break;
|
break;
|
||||||
case FLAT:
|
case FLAT:
|
||||||
glWrap.Draw<vcg::GLW::DMFlat, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
glWrap.Draw<vcg::GLW::DMFlat, vcg::GLW::CMNone,vcg::GLW::TMNone> ();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
track.DrawPostApply();
|
track.DrawPostApply();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::keyReleaseEvent (QKeyEvent * e)
|
void GLArea::keyReleaseEvent (QKeyEvent * e)
|
||||||
{
|
{
|
||||||
|
@ -174,21 +174,21 @@ void GLArea::mousePressEvent (QMouseEvent * e)
|
||||||
{
|
{
|
||||||
e->accept ();
|
e->accept ();
|
||||||
setFocus ();
|
setFocus ();
|
||||||
track.MouseDown (e->x (), height () - e->y (), QT2VCG (e->button (), e->modifiers ()));
|
track.MouseDown (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ()));
|
||||||
updateGL ();
|
updateGL ();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::mouseMoveEvent (QMouseEvent * e)
|
void GLArea::mouseMoveEvent (QMouseEvent * e)
|
||||||
{
|
{
|
||||||
if (e->buttons ()) {
|
if (e->buttons ()) {
|
||||||
track.MouseMove (e->x (), height () - e->y ());
|
track.MouseMove (QT2VCG_X(this,e), QT2VCG_Y(this,e));
|
||||||
updateGL ();
|
updateGL ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GLArea::mouseReleaseEvent (QMouseEvent * e)
|
void GLArea::mouseReleaseEvent (QMouseEvent * e)
|
||||||
{
|
{
|
||||||
track.MouseUp (e->x (), height () - e->y (), QT2VCG (e->button (), e->modifiers ()));
|
track.MouseUp (QT2VCG_X(this,e), QT2VCG_Y(this,e), QT2VCG (e->button (), e->modifiers ()));
|
||||||
updateGL ();
|
updateGL ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue