begin process of unifying GLView and OffscreenView. renames, objrot, objtran

felipesanches-svg
don bright 2013-02-20 19:56:30 -06:00
parent b7d1c94dc1
commit fc2d9341fa
10 changed files with 157 additions and 153 deletions

View File

@ -179,7 +179,7 @@ HEADERS += src/version_check.h \
src/ThrownTogetherRenderer.h \ src/ThrownTogetherRenderer.h \
src/CGAL_renderer.h \ src/CGAL_renderer.h \
src/OGL_helper.h \ src/OGL_helper.h \
src/GLView.h \ src/QGLView.h \
src/MainWindow.h \ src/MainWindow.h \
src/Preferences.h \ src/Preferences.h \
src/OpenCSGWarningDialog.h \ src/OpenCSGWarningDialog.h \
@ -284,7 +284,7 @@ SOURCES += src/version_check.cc \
src/Preferences.cc \ src/Preferences.cc \
src/OpenCSGWarningDialog.cc \ src/OpenCSGWarningDialog.cc \
src/editor.cc \ src/editor.cc \
src/glview.cc \ src/qglview.cc \
\ \
src/builtin.cc \ src/builtin.cc \
src/export.cc \ src/export.cc \

View File

@ -6,8 +6,8 @@
class CsgInfo class CsgInfo
{ {
public: public:
CsgInfo() { glview = NULL; } CsgInfo() { qglview = NULL; }
OffscreenView *glview; OffscreenView *qglview;
}; };
@ -26,7 +26,7 @@ public:
root_chain = NULL; root_chain = NULL;
highlights_chain = NULL; highlights_chain = NULL;
background_chain = NULL; background_chain = NULL;
glview = NULL; qglview = NULL;
} }
shared_ptr<CSGTerm> root_norm_term; // Normalized CSG products shared_ptr<CSGTerm> root_norm_term; // Normalized CSG products
class CSGChain *root_chain; class CSGChain *root_chain;

View File

@ -38,7 +38,7 @@
<property name="orientation"> <property name="orientation">
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<widget class="GLView" name="glview" native="true"/> <widget class="QGLView" name="qglview" native="true"/>
<widget class="QTextEdit" name="console"> <widget class="QTextEdit" name="console">
<property name="readOnly"> <property name="readOnly">
<bool>true</bool> <bool>true</bool>
@ -679,9 +679,9 @@
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>
<class>GLView</class> <class>QGLView</class>
<extends>QWidget</extends> <extends>QWidget</extends>
<header>GLView.h</header> <header>QGLView.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget> <customwidget>

View File

@ -147,7 +147,7 @@ bool OffscreenView::save(std::ostream &output)
return save_framebuffer(this->ctx, output); return save_framebuffer(this->ctx, output);
} }
std::string OffscreenView::getInfo() const std::string &OffscreenView::getRendererInfo()
{ {
std::stringstream out; std::stringstream out;
GLint rbits, gbits, bbits, abits, dbits, sbits; GLint rbits, gbits, bbits, abits, dbits, sbits;

View File

@ -26,24 +26,25 @@ public:
void paintGL(); void paintGL();
bool save(const char *filename); bool save(const char *filename);
bool save(std::ostream &output); bool save(std::ostream &output);
std::string getInfo(); const std::string &getRendererInfo();
GLint shaderinfo[11]; GLint shaderinfo[11]; //
OffscreenContext *ctx;
size_t width; OffscreenContext *ctx; // not
size_t height; size_t width; // not
size_t height; // not
private: private:
Renderer *renderer; Renderer *renderer;//
double w_h_ratio; double w_h_ratio;//
bool orthomode; bool orthomode;//
bool showaxes; bool showaxes;//
bool showfaces; bool showfaces;//
bool showedges; bool showedges;//
Eigen::Vector3d object_rot; Eigen::Vector3d object_rot;//
Eigen::Vector3d camera_eye; Eigen::Vector3d camera_eye;//
Eigen::Vector3d camera_center; Eigen::Vector3d camera_center;//
}; };
#endif #endif

View File

@ -5,7 +5,10 @@
#include <QGLWidget> #include <QGLWidget>
#include <QLabel> #include <QLabel>
class GLView : public QGLWidget #include <Eigen/Core>
#include <Eigen/Geometry>
class QGLView : public QGLWidget
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(bool showFaces READ showFaces WRITE setShowFaces); Q_PROPERTY(bool showFaces READ showFaces WRITE setShowFaces);
@ -15,8 +18,8 @@ class GLView : public QGLWidget
Q_PROPERTY(bool orthoMode READ orthoMode WRITE setOrthoMode); Q_PROPERTY(bool orthoMode READ orthoMode WRITE setOrthoMode);
public: public:
GLView(QWidget *parent = NULL); QGLView(QWidget *parent = NULL);
GLView(const QGLFormat & format, QWidget *parent = NULL); QGLView(const QGLFormat & format, QWidget *parent = NULL);
void setRenderer(class Renderer* r); void setRenderer(class Renderer* r);
#ifdef ENABLE_OPENCSG #ifdef ENABLE_OPENCSG
bool hasOpenCSGSupport() { return this->opencsg_support; } bool hasOpenCSGSupport() { return this->opencsg_support; }
@ -32,16 +35,16 @@ public:
void setShowCrosshairs(bool enabled) { this->showcrosshairs = enabled; } void setShowCrosshairs(bool enabled) { this->showcrosshairs = enabled; }
bool orthoMode() const { return this->orthomode; } bool orthoMode() const { return this->orthomode; }
void setOrthoMode(bool enabled) { this->orthomode = enabled; } void setOrthoMode(bool enabled) { this->orthomode = enabled; }
const QString &getRendererInfo() const { return this->rendererInfo; } const std::string &getRendererInfo() const { return this->rendererInfo; }
public: public:
QLabel *statusLabel; QLabel *statusLabel;
double object_rot_x;
double object_rot_y; Eigen::Vector3d object_rot;
double object_rot_z; Eigen::Vector3d object_trans;
double object_trans_x; Eigen::Vector3d camera_eye;
double object_trans_y; Eigen::Vector3d camera_center;
double object_trans_z;
GLint shaderinfo[11]; GLint shaderinfo[11];
#ifdef ENABLE_OPENCSG #ifdef ENABLE_OPENCSG
@ -53,7 +56,7 @@ private:
void init(); void init();
Renderer *renderer; Renderer *renderer;
QString rendererInfo; std::string rendererInfo;
bool showfaces; bool showfaces;
bool showedges; bool showedges;

View File

@ -14,7 +14,7 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output)
{ {
CsgInfo csgInfo; CsgInfo csgInfo;
try { try {
csgInfo.glview = new OffscreenView(512,512); csgInfo.qglview = new OffscreenView(512,512);
} catch (int error) { } catch (int error) {
fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error); fprintf(stderr,"Can't create OpenGL OffscreenView. Code: %i.\n", error);
return; return;
@ -40,10 +40,10 @@ void export_png_with_cgal(CGAL_Nef_polyhedron *root_N, std::ostream &output)
//std::cerr << center << "\n"; //std::cerr << center << "\n";
//std::cerr << radius << "\n"; //std::cerr << radius << "\n";
csgInfo.glview->setCamera(camerapos, center); csgInfo.qglview->setCamera(camerapos, center);
csgInfo.glview->setRenderer(&cgalRenderer); csgInfo.qglview->setRenderer(&cgalRenderer);
csgInfo.glview->paintGL(); csgInfo.qglview->paintGL();
csgInfo.glview->save(output); csgInfo.qglview->save(output);
} }
void export_png_with_opencsg(CGAL_Nef_polyhedron *root_N, std::ostream &output) void export_png_with_opencsg(CGAL_Nef_polyhedron *root_N, std::ostream &output)

View File

@ -190,8 +190,8 @@ MainWindow::MainWindow(const QString &filename)
editor->setTabStopWidth(30); editor->setTabStopWidth(30);
editor->setLineWrapping(true); // Not designable editor->setLineWrapping(true); // Not designable
this->glview->statusLabel = new QLabel(this); this->qglview->statusLabel = new QLabel(this);
statusBar()->addWidget(this->glview->statusLabel); statusBar()->addWidget(this->qglview->statusLabel);
animate_timer = new QTimer(this); animate_timer = new QTimer(this);
connect(animate_timer, SIGNAL(timeout()), this, SLOT(updateTVal())); connect(animate_timer, SIGNAL(timeout()), this, SLOT(updateTVal()));
@ -291,7 +291,7 @@ MainWindow::MainWindow(const QString &filename)
this->viewActionOpenCSG->setVisible(false); this->viewActionOpenCSG->setVisible(false);
#else #else
connect(this->viewActionOpenCSG, SIGNAL(triggered()), this, SLOT(viewModeOpenCSG())); connect(this->viewActionOpenCSG, SIGNAL(triggered()), this, SLOT(viewModeOpenCSG()));
if (!this->glview->hasOpenCSGSupport()) { if (!this->qglview->hasOpenCSGSupport()) {
this->viewActionOpenCSG->setEnabled(false); this->viewActionOpenCSG->setEnabled(false);
} }
#endif #endif
@ -343,9 +343,9 @@ MainWindow::MainWindow(const QString &filename)
connect(editor->document(), SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged())); connect(editor->document(), SIGNAL(contentsChanged()), this, SLOT(animateUpdateDocChanged()));
connect(editor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool))); connect(editor->document(), SIGNAL(modificationChanged(bool)), this, SLOT(setWindowModified(bool)));
connect(editor->document(), SIGNAL(modificationChanged(bool)), fileActionSave, SLOT(setEnabled(bool))); connect(editor->document(), SIGNAL(modificationChanged(bool)), fileActionSave, SLOT(setEnabled(bool)));
connect(this->glview, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate())); connect(this->qglview, SIGNAL(doAnimateUpdate()), this, SLOT(animateUpdate()));
connect(Preferences::inst(), SIGNAL(requestRedraw()), this->glview, SLOT(updateGL())); connect(Preferences::inst(), SIGNAL(requestRedraw()), this->qglview, SLOT(updateGL()));
connect(Preferences::inst(), SIGNAL(fontChanged(const QString&,uint)), connect(Preferences::inst(), SIGNAL(fontChanged(const QString&,uint)),
this, SLOT(setFont(const QString&,uint))); this, SLOT(setFont(const QString&,uint)));
connect(Preferences::inst(), SIGNAL(openCSGSettingsChanged()), connect(Preferences::inst(), SIGNAL(openCSGSettingsChanged()),
@ -595,7 +595,7 @@ bool MainWindow::compile(bool reload, bool procevents)
if (!compileTopLevelDocument(reload)) return false; if (!compileTopLevelDocument(reload)) return false;
// Invalidate renderers before we kill the CSG tree // Invalidate renderers before we kill the CSG tree
this->glview->setRenderer(NULL); this->qglview->setRenderer(NULL);
delete this->opencsgRenderer; delete this->opencsgRenderer;
this->opencsgRenderer = NULL; this->opencsgRenderer = NULL;
delete this->thrownTogetherRenderer; delete this->thrownTogetherRenderer;
@ -759,7 +759,7 @@ void MainWindow::compileCSG(bool procevents)
this->opencsgRenderer = new OpenCSGRenderer(this->root_chain, this->opencsgRenderer = new OpenCSGRenderer(this->root_chain,
this->highlights_chain, this->highlights_chain,
this->background_chain, this->background_chain,
this->glview->shaderinfo); this->qglview->shaderinfo);
} }
this->thrownTogetherRenderer = new ThrownTogetherRenderer(this->root_chain, this->thrownTogetherRenderer = new ThrownTogetherRenderer(this->root_chain,
this->highlights_chain, this->highlights_chain,
@ -942,7 +942,7 @@ void MainWindow::pasteViewportTranslation()
{ {
QTextCursor cursor = editor->textCursor(); QTextCursor cursor = editor->textCursor();
QString txt; QString txt;
txt.sprintf("[ %.2f, %.2f, %.2f ]", -this->glview->object_trans_x, -this->glview->object_trans_y, -this->glview->object_trans_z); txt.sprintf("[ %.2f, %.2f, %.2f ]", -this->qglview->object_trans_x, -this->qglview->object_trans_y, -this->qglview->object_trans_z);
cursor.insertText(txt); cursor.insertText(txt);
} }
@ -951,7 +951,7 @@ void MainWindow::pasteViewportRotation()
QTextCursor cursor = editor->textCursor(); QTextCursor cursor = editor->textCursor();
QString txt; QString txt;
txt.sprintf("[ %.2f, %.2f, %.2f ]", txt.sprintf("[ %.2f, %.2f, %.2f ]",
fmodf(360 - this->glview->object_rot_x + 90, 360), fmodf(360 - this->glview->object_rot_y, 360), fmodf(360 - this->glview->object_rot_z, 360)); fmodf(360 - this->qglview->object_rot_x + 90, 360), fmodf(360 - this->qglview->object_rot_y, 360), fmodf(360 - this->qglview->object_rot_z, 360));
cursor.insertText(txt); cursor.insertText(txt);
} }
@ -960,15 +960,15 @@ void MainWindow::updateTemporalVariables()
this->root_ctx.set_variable("$t", Value(this->e_tval->text().toDouble())); this->root_ctx.set_variable("$t", Value(this->e_tval->text().toDouble()));
Value::VectorType vpt; Value::VectorType vpt;
vpt.push_back(Value(-this->glview->object_trans_x)); vpt.push_back(Value(-this->qglview->object_trans_x));
vpt.push_back(Value(-this->glview->object_trans_y)); vpt.push_back(Value(-this->qglview->object_trans_y));
vpt.push_back(Value(-this->glview->object_trans_z)); vpt.push_back(Value(-this->qglview->object_trans_z));
this->root_ctx.set_variable("$vpt", Value(vpt)); this->root_ctx.set_variable("$vpt", Value(vpt));
Value::VectorType vpr; Value::VectorType vpr;
vpr.push_back(Value(fmodf(360 - this->glview->object_rot_x + 90, 360))); vpr.push_back(Value(fmodf(360 - this->qglview->object_rot_x + 90, 360)));
vpr.push_back(Value(fmodf(360 - this->glview->object_rot_y, 360))); vpr.push_back(Value(fmodf(360 - this->qglview->object_rot_y, 360)));
vpr.push_back(Value(fmodf(360 - this->glview->object_rot_z, 360))); vpr.push_back(Value(fmodf(360 - this->qglview->object_rot_z, 360)));
root_ctx.set_variable("$vpr", Value(vpr)); root_ctx.set_variable("$vpr", Value(vpr));
} }
@ -1147,7 +1147,7 @@ void MainWindow::actionCompile()
} }
if (viewActionAnimate->isChecked() && e_dump->isChecked()) { if (viewActionAnimate->isChecked() && e_dump->isChecked()) {
QImage img = this->glview->grabFrameBuffer(); QImage img = this->qglview->grabFrameBuffer();
QString filename; QString filename;
double s = this->e_fsteps->text().toDouble(); double s = this->e_fsteps->text().toDouble();
double t = this->e_tval->text().toDouble(); double t = this->e_tval->text().toDouble();
@ -1176,7 +1176,7 @@ void MainWindow::actionRenderCGAL()
return; return;
} }
this->glview->setRenderer(NULL); this->qglview->setRenderer(NULL);
delete this->cgalRenderer; delete this->cgalRenderer;
this->cgalRenderer = NULL; this->cgalRenderer = NULL;
if (this->root_N) { if (this->root_N) {
@ -1452,7 +1452,7 @@ void MainWindow::actionExportCSG()
void MainWindow::actionExportImage() void MainWindow::actionExportImage()
{ {
QImage img = this->glview->grabFrameBuffer(); QImage img = this->qglview->grabFrameBuffer();
setCurrentOutput(); setCurrentOutput();
QString img_filename = QFileDialog::getSaveFileName(this, QString img_filename = QFileDialog::getSaveFileName(this,
@ -1497,10 +1497,10 @@ void MainWindow::viewModeActionsUncheck()
*/ */
void MainWindow::viewModeOpenCSG() void MainWindow::viewModeOpenCSG()
{ {
if (this->glview->hasOpenCSGSupport()) { if (this->qglview->hasOpenCSGSupport()) {
viewModeActionsUncheck(); viewModeActionsUncheck();
viewActionOpenCSG->setChecked(true); viewActionOpenCSG->setChecked(true);
this->glview->setRenderer(this->opencsgRenderer ? (Renderer *)this->opencsgRenderer : (Renderer *)this->thrownTogetherRenderer); this->qglview->setRenderer(this->opencsgRenderer ? (Renderer *)this->opencsgRenderer : (Renderer *)this->thrownTogetherRenderer);
} else { } else {
viewModeThrownTogether(); viewModeThrownTogether();
} }
@ -1514,17 +1514,17 @@ void MainWindow::viewModeCGALSurface()
{ {
viewModeActionsUncheck(); viewModeActionsUncheck();
viewActionCGALSurfaces->setChecked(true); viewActionCGALSurfaces->setChecked(true);
this->glview->setShowFaces(true); this->qglview->setShowFaces(true);
this->glview->setRenderer(this->cgalRenderer); this->qglview->setRenderer(this->cgalRenderer);
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewModeCGALGrid() void MainWindow::viewModeCGALGrid()
{ {
viewModeActionsUncheck(); viewModeActionsUncheck();
viewActionCGALGrid->setChecked(true); viewActionCGALGrid->setChecked(true);
this->glview->setShowFaces(false); this->qglview->setShowFaces(false);
this->glview->setRenderer(this->cgalRenderer); this->qglview->setRenderer(this->cgalRenderer);
} }
#endif /* ENABLE_CGAL */ #endif /* ENABLE_CGAL */
@ -1533,31 +1533,31 @@ void MainWindow::viewModeThrownTogether()
{ {
viewModeActionsUncheck(); viewModeActionsUncheck();
viewActionThrownTogether->setChecked(true); viewActionThrownTogether->setChecked(true);
this->glview->setRenderer(this->thrownTogetherRenderer); this->qglview->setRenderer(this->thrownTogetherRenderer);
} }
void MainWindow::viewModeShowEdges() void MainWindow::viewModeShowEdges()
{ {
QSettings settings; QSettings settings;
settings.setValue("view/showEdges",viewActionShowEdges->isChecked()); settings.setValue("view/showEdges",viewActionShowEdges->isChecked());
this->glview->setShowEdges(viewActionShowEdges->isChecked()); this->qglview->setShowEdges(viewActionShowEdges->isChecked());
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewModeShowAxes() void MainWindow::viewModeShowAxes()
{ {
QSettings settings; QSettings settings;
settings.setValue("view/showAxes",viewActionShowAxes->isChecked()); settings.setValue("view/showAxes",viewActionShowAxes->isChecked());
this->glview->setShowAxes(viewActionShowAxes->isChecked()); this->qglview->setShowAxes(viewActionShowAxes->isChecked());
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewModeShowCrosshairs() void MainWindow::viewModeShowCrosshairs()
{ {
QSettings settings; QSettings settings;
settings.setValue("view/showCrosshairs",viewActionShowCrosshairs->isChecked()); settings.setValue("view/showCrosshairs",viewActionShowCrosshairs->isChecked());
this->glview->setShowCrosshairs(viewActionShowCrosshairs->isChecked()); this->qglview->setShowCrosshairs(viewActionShowCrosshairs->isChecked());
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewModeAnimate() void MainWindow::viewModeAnimate()
@ -1595,66 +1595,66 @@ void MainWindow::animateUpdate()
void MainWindow::viewAngleTop() void MainWindow::viewAngleTop()
{ {
this->glview->object_rot_x = 90; this->qglview->object_rot_x = 90;
this->glview->object_rot_y = 0; this->qglview->object_rot_y = 0;
this->glview->object_rot_z = 0; this->qglview->object_rot_z = 0;
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewAngleBottom() void MainWindow::viewAngleBottom()
{ {
this->glview->object_rot_x = 270; this->qglview->object_rot_x = 270;
this->glview->object_rot_y = 0; this->qglview->object_rot_y = 0;
this->glview->object_rot_z = 0; this->qglview->object_rot_z = 0;
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewAngleLeft() void MainWindow::viewAngleLeft()
{ {
this->glview->object_rot_x = 0; this->qglview->object_rot_x = 0;
this->glview->object_rot_y = 0; this->qglview->object_rot_y = 0;
this->glview->object_rot_z = 90; this->qglview->object_rot_z = 90;
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewAngleRight() void MainWindow::viewAngleRight()
{ {
this->glview->object_rot_x = 0; this->qglview->object_rot_x = 0;
this->glview->object_rot_y = 0; this->qglview->object_rot_y = 0;
this->glview->object_rot_z = 270; this->qglview->object_rot_z = 270;
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewAngleFront() void MainWindow::viewAngleFront()
{ {
this->glview->object_rot_x = 0; this->qglview->object_rot_x = 0;
this->glview->object_rot_y = 0; this->qglview->object_rot_y = 0;
this->glview->object_rot_z = 0; this->qglview->object_rot_z = 0;
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewAngleBack() void MainWindow::viewAngleBack()
{ {
this->glview->object_rot_x = 0; this->qglview->object_rot_x = 0;
this->glview->object_rot_y = 0; this->qglview->object_rot_y = 0;
this->glview->object_rot_z = 180; this->qglview->object_rot_z = 180;
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewAngleDiagonal() void MainWindow::viewAngleDiagonal()
{ {
this->glview->object_rot_x = 35; this->qglview->object_rot_x = 35;
this->glview->object_rot_y = 0; this->qglview->object_rot_y = 0;
this->glview->object_rot_z = -25; this->qglview->object_rot_z = -25;
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewCenter() void MainWindow::viewCenter()
{ {
this->glview->object_trans_x = 0; this->qglview->object_trans_x = 0;
this->glview->object_trans_y = 0; this->qglview->object_trans_y = 0;
this->glview->object_trans_z = 0; this->qglview->object_trans_z = 0;
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewPerspective() void MainWindow::viewPerspective()
@ -1663,8 +1663,8 @@ void MainWindow::viewPerspective()
settings.setValue("view/orthogonalProjection",false); settings.setValue("view/orthogonalProjection",false);
viewActionPerspective->setChecked(true); viewActionPerspective->setChecked(true);
viewActionOrthogonal->setChecked(false); viewActionOrthogonal->setChecked(false);
this->glview->setOrthoMode(false); this->qglview->setOrthoMode(false);
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::viewOrthogonal() void MainWindow::viewOrthogonal()
@ -1673,8 +1673,8 @@ void MainWindow::viewOrthogonal()
settings.setValue("view/orthogonalProjection",true); settings.setValue("view/orthogonalProjection",true);
viewActionPerspective->setChecked(false); viewActionPerspective->setChecked(false);
viewActionOrthogonal->setChecked(true); viewActionOrthogonal->setChecked(true);
this->glview->setOrthoMode(true); this->qglview->setOrthoMode(true);
this->glview->updateGL(); this->qglview->updateGL();
} }
void MainWindow::hideConsole() void MainWindow::hideConsole()
@ -1751,7 +1751,7 @@ void MainWindow::helpLibrary()
} }
this->openglbox->setDetailedText(libinfo + this->glview->getRendererInfo()); this->openglbox->setDetailedText(libinfo + QString(this->qglview->getRendererInfo()));
this->openglbox->show(); this->openglbox->show();
} }

View File

@ -24,7 +24,7 @@
* *
*/ */
#include "GLView.h" #include "QGLView.h"
#include "Preferences.h" #include "Preferences.h"
#include "renderer.h" #include "renderer.h"
#include "rendersettings.h" #include "rendersettings.h"
@ -59,27 +59,27 @@
#define FAR_FAR_AWAY 100000.0 #define FAR_FAR_AWAY 100000.0
GLView::GLView(QWidget *parent) : QGLWidget(parent), renderer(NULL) QGLView::QGLView(QWidget *parent) : QGLWidget(parent), renderer(NULL)
{ {
init(); init();
} }
GLView::GLView(const QGLFormat & format, QWidget *parent) : QGLWidget(format, parent) QGLView::QGLView(const QGLFormat & format, QWidget *parent) : QGLWidget(format, parent)
{ {
init(); init();
} }
static bool running_under_wine = false; static bool running_under_wine = false;
void GLView::init() void QGLView::init()
{ {
this->viewer_distance = 500; this->viewer_distance = 500;
this->object_rot_x = 35; this->object_rot.x() = 35;
this->object_rot_y = 0; this->object_rot.y() = 0;
this->object_rot_z = -25; this->object_rot.z() = -25;
this->object_trans_x = 0; this->object_trans.x() = 0;
this->object_trans_y = 0; this->object_trans.y() = 0;
this->object_trans_z = 0; this->object_trans.z() = 0;
this->mouse_drag_active = false; this->mouse_drag_active = false;
@ -113,13 +113,13 @@ void GLView::init()
#endif #endif
} }
void GLView::setRenderer(Renderer *r) void QGLView::setRenderer(Renderer *r)
{ {
this->renderer = r; this->renderer = r;
if (r) updateGL(); // Let the last image stay, e.g. to avoid animation flickering if (r) updateGL(); // Let the last image stay, e.g. to avoid animation flickering
} }
void GLView::initializeGL() void QGLView::initializeGL()
{ {
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
glDepthRange(-FAR_FAR_AWAY, +FAR_FAR_AWAY); glDepthRange(-FAR_FAR_AWAY, +FAR_FAR_AWAY);
@ -320,7 +320,7 @@ void GLView::initializeGL()
} }
#ifdef ENABLE_OPENCSG #ifdef ENABLE_OPENCSG
void GLView::display_opencsg_warning() void QGLView::display_opencsg_warning()
{ {
OpenCSGWarningDialog *dialog = new OpenCSGWarningDialog(this); OpenCSGWarningDialog *dialog = new OpenCSGWarningDialog(this);
@ -352,7 +352,7 @@ void GLView::display_opencsg_warning()
} }
#endif #endif
void GLView::resizeGL(int w, int h) void QGLView::resizeGL(int w, int h)
{ {
#ifdef ENABLE_OPENCSG #ifdef ENABLE_OPENCSG
shaderinfo[9] = w; shaderinfo[9] = w;
@ -364,7 +364,7 @@ void GLView::resizeGL(int w, int h)
setupPerspective(); setupPerspective();
} }
void GLView::setupPerspective() void QGLView::setupPerspective()
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -372,7 +372,7 @@ void GLView::setupPerspective()
gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
} }
void GLView::setupOrtho(double distance, bool offset) void QGLView::setupOrtho(double distance, bool offset)
{ {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
@ -385,7 +385,7 @@ void GLView::setupOrtho(double distance, bool offset)
gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0); gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
} }
void GLView::paintGL() void QGLView::paintGL()
{ {
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
@ -400,9 +400,9 @@ void GLView::paintGL()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
glRotated(object_rot_x, 1.0, 0.0, 0.0); glRotated(object_rot.x(), 1.0, 0.0, 0.0);
glRotated(object_rot_y, 0.0, 1.0, 0.0); glRotated(object_rot.y(), 0.0, 1.0, 0.0);
glRotated(object_rot_z, 0.0, 0.0, 1.0); glRotated(object_rot.z(), 0.0, 0.0, 1.0);
// FIXME: Crosshairs and axes are lighted, this doesn't make sense and causes them // FIXME: Crosshairs and axes are lighted, this doesn't make sense and causes them
// to change color based on view orientation. // to change color based on view orientation.
@ -421,7 +421,7 @@ void GLView::paintGL()
glEnd(); glEnd();
} }
glTranslated(object_trans_x, object_trans_y, object_trans_z); glTranslated(object_trans.x(), object_trans.y(), object_trans.z());
// Large gray axis cross inline with the model // Large gray axis cross inline with the model
// FIXME: This is always gray - adjust color to keep contrast with background // FIXME: This is always gray - adjust color to keep contrast with background
@ -464,9 +464,9 @@ void GLView::paintGL()
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glRotated(object_rot_x, 1.0, 0.0, 0.0); glRotated(object_rot.x(), 1.0, 0.0, 0.0);
glRotated(object_rot_y, 0.0, 1.0, 0.0); glRotated(object_rot.y(), 0.0, 1.0, 0.0);
glRotated(object_rot_z, 0.0, 0.0, 1.0); glRotated(object_rot.z(), 0.0, 0.0, 1.0);
glLineWidth(1); glLineWidth(1);
glBegin(GL_LINES); glBegin(GL_LINES);
@ -535,15 +535,15 @@ void GLView::paintGL()
if (statusLabel) { if (statusLabel) {
QString msg; QString msg;
msg.sprintf("Viewport: translate = [ %.2f %.2f %.2f ], rotate = [ %.2f %.2f %.2f ], distance = %.2f", msg.sprintf("Viewport: translate = [ %.2f %.2f %.2f ], rotate = [ %.2f %.2f %.2f ], distance = %.2f",
-object_trans_x, -object_trans_y, -object_trans_z, -object_trans.x(), -object_trans.y(), -object_trans.z(),
fmodf(360 - object_rot_x + 90, 360), fmodf(360 - object_rot_y, 360), fmodf(360 - object_rot_z, 360), viewer_distance); fmodf(360 - object_rot.x() + 90, 360), fmodf(360 - object_rot.y(), 360), fmodf(360 - object_rot.z(), 360), viewer_distance);
statusLabel->setText(msg); statusLabel->setText(msg);
} }
if (running_under_wine) swapBuffers(); if (running_under_wine) swapBuffers();
} }
void GLView::keyPressEvent(QKeyEvent *event) void QGLView::keyPressEvent(QKeyEvent *event)
{ {
if (event->key() == Qt::Key_Plus) { if (event->key() == Qt::Key_Plus) {
viewer_distance *= 0.9; viewer_distance *= 0.9;
@ -557,19 +557,19 @@ void GLView::keyPressEvent(QKeyEvent *event)
} }
} }
void GLView::wheelEvent(QWheelEvent *event) void QGLView::wheelEvent(QWheelEvent *event)
{ {
viewer_distance *= pow(0.9, event->delta() / 120.0); viewer_distance *= pow(0.9, event->delta() / 120.0);
updateGL(); updateGL();
} }
void GLView::mousePressEvent(QMouseEvent *event) void QGLView::mousePressEvent(QMouseEvent *event)
{ {
mouse_drag_active = true; mouse_drag_active = true;
last_mouse = event->globalPos(); last_mouse = event->globalPos();
} }
void GLView::normalizeAngle(GLdouble& angle) void QGLView::normalizeAngle(GLdouble& angle)
{ {
while(angle < 0) while(angle < 0)
angle += 360; angle += 360;
@ -577,7 +577,7 @@ void GLView::normalizeAngle(GLdouble& angle)
angle -= 360; angle -= 360;
} }
void GLView::mouseMoveEvent(QMouseEvent *event) void QGLView::mouseMoveEvent(QMouseEvent *event)
{ {
QPoint this_mouse = event->globalPos(); QPoint this_mouse = event->globalPos();
double dx = (this_mouse.x()-last_mouse.x()) * 0.7; double dx = (this_mouse.x()-last_mouse.x()) * 0.7;
@ -590,15 +590,15 @@ void GLView::mouseMoveEvent(QMouseEvent *event)
) { ) {
// Left button rotates in xz, Shift-left rotates in xy // Left button rotates in xz, Shift-left rotates in xy
// On Mac, Ctrl-Left is handled as right button on other platforms // On Mac, Ctrl-Left is handled as right button on other platforms
object_rot_x += dy; object_rot.x() += dy;
if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0) if ((QApplication::keyboardModifiers() & Qt::ShiftModifier) != 0)
object_rot_y += dx; object_rot.y() += dx;
else else
object_rot_z += dx; object_rot.z() += dx;
normalizeAngle(object_rot_x); normalizeAngle(object_rot.x());
normalizeAngle(object_rot_y); normalizeAngle(object_rot.y());
normalizeAngle(object_rot_z); normalizeAngle(object_rot.z());
} else { } else {
// Right button pans in the xz plane // Right button pans in the xz plane
// Middle button pans in the xy plane // Middle button pans in the xy plane
@ -624,9 +624,9 @@ void GLView::mouseMoveEvent(QMouseEvent *event)
} }
Matrix3d aax, aay, aaz, tm3; Matrix3d aax, aay, aaz, tm3;
aax = Eigen::AngleAxisd(-(object_rot_x/180) * M_PI, Vector3d::UnitX()); aax = Eigen::AngleAxisd(-(object_rot.x()/180) * M_PI, Vector3d::UnitX());
aay = Eigen::AngleAxisd(-(object_rot_y/180) * M_PI, Vector3d::UnitY()); aay = Eigen::AngleAxisd(-(object_rot.y()/180) * M_PI, Vector3d::UnitY());
aaz = Eigen::AngleAxisd(-(object_rot_z/180) * M_PI, Vector3d::UnitZ()); aaz = Eigen::AngleAxisd(-(object_rot.z()/180) * M_PI, Vector3d::UnitZ());
tm3 = Matrix3d::Identity(); tm3 = Matrix3d::Identity();
tm3 = aaz * (aay * (aax * tm3)); tm3 = aaz * (aay * (aax * tm3));
@ -642,9 +642,9 @@ void GLView::mouseMoveEvent(QMouseEvent *event)
0, 0, 0, 1 0, 0, 0, 1
; ;
tm = tm * vec; tm = tm * vec;
object_trans_x += tm(0,3); object_trans.x() += tm(0,3);
object_trans_y += tm(1,3); object_trans.y() += tm(1,3);
object_trans_z += tm(2,3); object_trans.z() += tm(2,3);
} }
} }
updateGL(); updateGL();
@ -653,7 +653,7 @@ void GLView::mouseMoveEvent(QMouseEvent *event)
last_mouse = this_mouse; last_mouse = this_mouse;
} }
void GLView::mouseReleaseEvent(QMouseEvent*) void QGLView::mouseReleaseEvent(QMouseEvent*)
{ {
mouse_drag_active = false; mouse_drag_active = false;
releaseMouse(); releaseMouse();

View File

@ -92,7 +92,7 @@ string info_dump(OffscreenView *glview)
<< EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION << EIGEN_MAJOR_VERSION << "." << EIGEN_MINOR_VERSION
<< "\nCGAL version: " << TOSTRING(CGAL_VERSION) << "\nCGAL version: " << TOSTRING(CGAL_VERSION)
<< "\nOpenCSG version: " << OPENCSG_VERSION_STRING << "\nOpenCSG version: " << OPENCSG_VERSION_STRING
<< "\n" << glview->getInfo() << "\n" << glview->getRendererInfo()
<< "\n"; << "\n";
return out.str(); return out.str();