Start to use manipulated frame for clipping plane

This commit is contained in:
Guillaume Damiand 2021-02-03 08:56:52 +01:00
parent 77b9ebc19c
commit a09a4684f4
1 changed files with 41 additions and 4 deletions

View File

@ -31,8 +31,8 @@
#include <QKeyEvent> #include <QKeyEvent>
#include <CGAL/Qt/qglviewer.h> #include <CGAL/Qt/qglviewer.h>
#include <CGAL/Qt/manipulatedFrame.h>
#include <QKeyEvent> #include <QKeyEvent>
#include <QOpenGLFunctions>
#include <QOpenGLVertexArrayObject> #include <QOpenGLVertexArrayObject>
#include <QGLBuffer> #include <QGLBuffer>
#include <QOpenGLShaderProgram> #include <QOpenGLShaderProgram>
@ -186,6 +186,15 @@ public:
setMouseBindingDescription(::Qt::Key_C, ::Qt::ControlModifier, ::Qt::RightButton, "Translate the clipping plane when enabled"); setMouseBindingDescription(::Qt::Key_C, ::Qt::ControlModifier, ::Qt::RightButton, "Translate the clipping plane when enabled");
setMouseBindingDescription(::Qt::Key_C, ::Qt::ControlModifier, ::Qt::MidButton, "Control the clipping plane transparency when enabled"); setMouseBindingDescription(::Qt::Key_C, ::Qt::ControlModifier, ::Qt::MidButton, "Control the clipping plane transparency when enabled");
/*
TODO
setMouseBinding(::Qt::NoModifier, ::Qt::LeftButton, qglviewer::FRAME, qglviewer::ROTATE);
setMouseBinding(::Qt::NoModifier, ::Qt::RightButton, qglviewer::FRAME, qglviewer::TRANSLATE);
setMouseBinding(::Qt::NoModifier, ::Qt::MidButton, qglviewer::FRAME, qglviewer::ZOOM);
setWheelBinding(::Qt::NoModifier, qglviewer::FRAME, qglviewer::ZOOM);
*/
if (title[0]==0) if (title[0]==0)
setWindowTitle("CGAL Basic Viewer"); setWindowTitle("CGAL Basic Viewer");
else else
@ -464,7 +473,7 @@ protected:
{ {
rendering_program_face.removeAllShaders(); rendering_program_face.removeAllShaders();
rendering_program_p_l.removeAllShaders(); rendering_program_p_l.removeAllShaders();
rendering_program_clipping_plane.removeAllShaders(); rendering_program_clipping_plane.removeAllShaders(); // TODO remove this shader: replace by QGLViewer::drawGrid
// Create the buffers // Create the buffers
for (unsigned int i=0; i<NB_VBO_BUFFERS; ++i) for (unsigned int i=0; i<NB_VBO_BUFFERS; ++i)
@ -531,7 +540,7 @@ protected:
// clipping plane shader // clipping plane shader
// TODO REMOVE
if (isOpenGL_4_3()) if (isOpenGL_4_3())
{ {
source_ = vertex_source_clipping_plane; source_ = vertex_source_clipping_plane;
@ -853,6 +862,7 @@ protected:
rendering_program_face.release(); rendering_program_face.release();
// TODO remove
// 6) clipping plane shader // 6) clipping plane shader
if (isOpenGL_4_3()) if (isOpenGL_4_3())
{ {
@ -939,6 +949,7 @@ protected:
rendering_program_p_l.setUniformValue(mvpLocation2, mvpMatrix); rendering_program_p_l.setUniformValue(mvpLocation2, mvpMatrix);
rendering_program_p_l.release(); rendering_program_p_l.release();
// TODO remove
if (isOpenGL_4_3()) if (isOpenGL_4_3())
{ {
QMatrix4x4 clipping_mMatrix; QMatrix4x4 clipping_mMatrix;
@ -1311,6 +1322,13 @@ protected:
} }
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
} }
// Multiply matrix to get in the frame coordinate system.
// glMultMatrixd(manipulatedFrame()->matrix()); // Linker error
// Scale down the drawings
// glScalef(0.3f, 0.3f, 0.3f); // Linker error
// Draw an axis using the QGLViewer static function
// drawAxis();
} }
virtual void init() virtual void init()
@ -1348,6 +1366,7 @@ protected:
bb.zmax())); bb.zmax()));
// init clipping plane array // init clipping plane array
// TODO REMOVE
auto generate_clipping_plane = [this](qreal size, int nbSubdivisions) auto generate_clipping_plane = [this](qreal size, int nbSubdivisions)
{ {
for (int i = 0; i <= nbSubdivisions; i++) for (int i = 0; i <= nbSubdivisions; i++)
@ -1393,6 +1412,19 @@ protected:
{ {
// toggle clipping plane // toggle clipping plane
m_use_clipping_plane = (m_use_clipping_plane + 1) % CLIPPING_PLANE_END_INDEX; m_use_clipping_plane = (m_use_clipping_plane + 1) % CLIPPING_PLANE_END_INDEX;
// TODO verify
if (m_use_clipping_plane==CLIPPING_PLANE_OFF)
{
delete m_frame_plane;
m_frame_plane=nullptr;
setManipulatedFrame(nullptr);
}
else if (m_frame_plane==nullptr)
{
m_frame_plane=new CGAL::qglviewer::ManipulatedFrame;
setManipulatedFrame(m_frame_plane);
}
switch(m_use_clipping_plane) switch(m_use_clipping_plane)
{ {
case CLIPPING_PLANE_OFF: displayMessage(QString("Draw clipping = flase")); break; case CLIPPING_PLANE_OFF: displayMessage(QString("Draw clipping = flase")); break;
@ -1606,6 +1638,7 @@ protected:
CGAL::QGLViewer::keyPressEvent(e); CGAL::QGLViewer::keyPressEvent(e);
} }
// TODO maybe remove
virtual void keyReleaseEvent(QKeyEvent *e) virtual void keyReleaseEvent(QKeyEvent *e)
{ {
const ::Qt::KeyboardModifiers modifiers = e->modifiers(); const ::Qt::KeyboardModifiers modifiers = e->modifiers();
@ -1615,6 +1648,7 @@ protected:
} }
} }
// TODO maybe remove
virtual void mousePressEvent(QMouseEvent *e) { virtual void mousePressEvent(QMouseEvent *e) {
if (clipping_plane_operation && e->modifiers() == ::Qt::ControlModifier && e->buttons() == ::Qt::LeftButton) { if (clipping_plane_operation && e->modifiers() == ::Qt::ControlModifier && e->buttons() == ::Qt::LeftButton) {
// rotation starting point // rotation starting point
@ -1631,6 +1665,7 @@ protected:
} }
} }
// TODO maybe remove
virtual void mouseMoveEvent(QMouseEvent *e) { virtual void mouseMoveEvent(QMouseEvent *e) {
if (clipping_plane_operation && e->modifiers() == ::Qt::ControlModifier && e->buttons() == ::Qt::LeftButton) if (clipping_plane_operation && e->modifiers() == ::Qt::ControlModifier && e->buttons() == ::Qt::LeftButton)
{ {
@ -1660,6 +1695,7 @@ protected:
} }
} }
// TODO maybe remove
virtual void wheelEvent(QWheelEvent *e) virtual void wheelEvent(QWheelEvent *e)
{ {
if (clipping_plane_operation && e->modifiers() == ::Qt::ControlModifier) { if (clipping_plane_operation && e->modifiers() == ::Qt::ControlModifier) {
@ -1728,7 +1764,8 @@ protected:
CLIPPING_PLANE_END_INDEX CLIPPING_PLANE_END_INDEX
}; };
int m_use_clipping_plane = CLIPPING_PLANE_OFF; int m_use_clipping_plane=CLIPPING_PLANE_OFF;
CGAL::qglviewer::ManipulatedFrame* m_frame_plane=nullptr;
double m_size_points; double m_size_points;
double m_size_edges; double m_size_edges;