summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-02-24 00:50:20 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-02-24 00:50:20 (GMT)
commit0f977609b40d5a6b6b5237060198e6dd97df06c5 (patch)
tree43c93a204f677ceef9c5b02b3ee28643c2acee12
parent5389107aa684ab99701e238a7297f07b35f7d521 (diff)
put qglview.h into mainwin for deps. unify camera functions into glview.
remove duplicate code.
-rw-r--r--openscad.pro4
-rw-r--r--src/GLView.cc71
-rw-r--r--src/GLView.h32
-rw-r--r--src/OGL_helper.h1
-rw-r--r--src/OffscreenView.cc18
-rw-r--r--src/OffscreenView.h6
-rw-r--r--src/QGLView.h16
-rw-r--r--src/mainwin.cc1
-rw-r--r--src/qglview.cc23
-rw-r--r--tests/CMakeLists.txt1
10 files changed, 127 insertions, 46 deletions
diff --git a/openscad.pro b/openscad.pro
index 18d9dae..15f76f8 100644
--- a/openscad.pro
+++ b/openscad.pro
@@ -118,7 +118,9 @@ netbsd* {
}
*clang* {
- # disable enormous amount of warnings about CGAL
+ # http://llvm.org/bugs/show_bug.cgi?id=9182
+ QMAKE_CXXFLAGS_WARN_ON += -Wno-overloaded-virtual
+ # disable enormous amount of warnings about CGAL / boost / etc
QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-parameter
QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-variable
QMAKE_CXXFLAGS_WARN_ON += -Wno-unused-function
diff --git a/src/GLView.cc b/src/GLView.cc
index 36aa6b3..0c23f97 100644
--- a/src/GLView.cc
+++ b/src/GLView.cc
@@ -1,21 +1,76 @@
#include "GLView.h"
-void GLView::setRenderer(class Renderer* r)
+#include "printutils.h"
+#include <iostream>
+
+GLView::GLView()
+{
+ std::cout << "glview();" << std::endl;
+ this->renderer = NULL;
+}
+
+void GLView::setRenderer(Renderer* r)
{
+ std::cout << "setr " << r << "\n" << std::endl;
this->renderer = r;
}
+void GLView::setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance)
+{
+ PRINT("set gimbal camera not implemented");
+}
+
+void GLView::setupGimbalPerspective()
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ glFrustum(-w_h_ratio, +w_h_ratio, -(1/w_h_ratio), +(1/w_h_ratio), +10.0, +FAR_FAR_AWAY);
+ gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+}
+
+void GLView::setupGimbalOrtho(double distance, bool offset)
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ if(offset)
+ glTranslated(-0.8, -0.8, 0);
+ double l = distance/10;
+ glOrtho(-w_h_ratio*l, +w_h_ratio*l,
+ -(1/w_h_ratio)*l, +(1/w_h_ratio)*l,
+ -FAR_FAR_AWAY, +FAR_FAR_AWAY);
+ gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
+}
+
+void GLView::setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center)
+{
+ this->camera_eye = pos;
+ this->camera_center = center;
+}
+
+void GLView::setupPerspective()
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ double dist = (this->camera_center - this->camera_eye).norm();
+ gluPerspective(45, w_h_ratio, 0.1*dist, 100*dist);
+}
+
+void GLView::setupOrtho(bool offset)
+{
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ if (offset) glTranslated(-0.8, -0.8, 0);
+ double l = (this->camera_center - this->camera_eye).norm() / 10;
+ glOrtho(-w_h_ratio*l, +w_h_ratio*l,
+ -(1/w_h_ratio)*l, +(1/w_h_ratio)*l,
+ -FAR_FAR_AWAY, +FAR_FAR_AWAY);
+}
+
+
/*
void initializeGL(); //
void resizeGL(int w, int h); //
- void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance); //
- void setupGimbalPerspective(); //
- void setupGimbalOrtho(double distance, bool offset=false); //
-
- void setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center); //
- void setupPerspective(); //
- void setupOrtho(bool offset=false); //
void paintGL(); //
bool save(const char *filename); //
diff --git a/src/GLView.h b/src/GLView.h
index d6e0236..32e3898 100644
--- a/src/GLView.h
+++ b/src/GLView.h
@@ -11,23 +11,41 @@
#include <iostream>
#include "renderer.h"
+#define FAR_FAR_AWAY 100000.0
+
class GLView
{
public:
+ GLView();
void setRenderer(Renderer* r);
- Renderer *renderer = 0;
+ virtual bool save(const char *filename) = 0;
+ Renderer *renderer;
/*
void initializeGL(); //
void resizeGL(int w, int h); //
- void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance); //
- void setupGimbalPerspective(); //
- void setupGimbalOrtho(double distance, bool offset=false); //
+*/
+ void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance);
+ void setupGimbalPerspective();
+ void setupGimbalOrtho(double distance, bool offset=false);
+
+ void setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center);
+ void setupPerspective();
+ void setupOrtho(bool offset=false);
- void setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center); //
- void setupPerspective(); //
- void setupOrtho(bool offset=false); //
+ double viewer_distance;//
+ double w_h_ratio;//
+ bool orthomode;//
+ bool showaxes;//
+ bool showfaces;//
+ bool showedges;//
+ Eigen::Vector3d object_trans;
+ Eigen::Vector3d object_rot;
+ Eigen::Vector3d camera_eye;
+ Eigen::Vector3d camera_center;
+
+/*
void paintGL(); //
bool save(const char *filename); //
//bool save(std::ostream &output); // not implemented in qgl?
diff --git a/src/OGL_helper.h b/src/OGL_helper.h
index 74f92bf..24611e7 100644
--- a/src/OGL_helper.h
+++ b/src/OGL_helper.h
@@ -544,6 +544,7 @@ namespace OGL {
if (switches[SNC_AXES]) glCallList(object_list_+3); // axis
}
+
void debug(std::ostream& os = std::cerr) const
{
os << "OGL::Polyhedron" << std::endl;
diff --git a/src/OffscreenView.cc b/src/OffscreenView.cc
index da129d8..0604ba4 100644
--- a/src/OffscreenView.cc
+++ b/src/OffscreenView.cc
@@ -7,12 +7,16 @@
#include <cstdlib>
#include <sstream>
-#define FAR_FAR_AWAY 100000.0
-
OffscreenView::OffscreenView(size_t width, size_t height)
- : orthomode(false), showaxes(false), showfaces(true), showedges(false),
- object_rot(35, 0, 25), camera_eye(0, 0, 0), camera_center(0, 0, 0)
{
+ orthomode = false;
+ showaxes = false;
+ showfaces = true;
+ showedges = false;
+ object_rot << 35, 0, 25;
+ camera_eye << 0, 0, 0;
+ camera_center << 0, 0, 0;
+
for (int i = 0; i < 10; i++) this->shaderinfo[i] = 0;
this->ctx = create_offscreen_context(width, height);
if ( this->ctx == NULL ) throw -1;
@@ -61,7 +65,7 @@ void OffscreenView::resizeGL(int w, int h)
w_h_ratio = sqrt((double)w / (double)h);
}
-void OffscreenView::setupGimbalPerspective()
+/*void OffscreenView::setupGimbalPerspective()
{
fprintf(stderr, "gimbal camera not implemented in Offscreen View\n");
}
@@ -88,7 +92,7 @@ void OffscreenView::setupOrtho(bool offset)
glOrtho(-w_h_ratio*l, +w_h_ratio*l,
-(1/w_h_ratio)*l, +(1/w_h_ratio)*l,
-FAR_FAR_AWAY, +FAR_FAR_AWAY);
-}
+}*/
void OffscreenView::paintGL()
{
@@ -161,9 +165,11 @@ std::string OffscreenView::getRendererInfo()
return out.str();
}
+/*
void OffscreenView::setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center)
{
this->camera_eye = pos;
this->camera_center = center;
}
+*/
diff --git a/src/OffscreenView.h b/src/OffscreenView.h
index 3414d60..e41acf9 100644
--- a/src/OffscreenView.h
+++ b/src/OffscreenView.h
@@ -21,6 +21,7 @@ public:
void initializeGL(); //
void resizeGL(int w, int h); //
+/*
void setGimbalCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &rot, double distance); //
void setupGimbalPerspective(); //
void setupGimbalOrtho(double distance, bool offset=false); //
@@ -28,6 +29,7 @@ public:
void setCamera(const Eigen::Vector3d &pos, const Eigen::Vector3d &center); //
void setupPerspective(); //
void setupOrtho(bool offset=false); //
+*/
void paintGL(); //
bool save(const char *filename); //
@@ -39,7 +41,7 @@ public:
OffscreenContext *ctx; // not
size_t width; // not
size_t height; // not
-private:
+/*private:
double w_h_ratio;//
bool orthomode;//
bool showaxes;//
@@ -48,7 +50,7 @@ private:
Eigen::Vector3d object_rot;//
Eigen::Vector3d camera_eye;//
- Eigen::Vector3d camera_center;//
+ Eigen::Vector3d camera_center;//*/
};
#endif
diff --git a/src/QGLView.h b/src/QGLView.h
index f617286..ae382c2 100644
--- a/src/QGLView.h
+++ b/src/QGLView.h
@@ -42,10 +42,10 @@ public:
public:
QLabel *statusLabel;
- Eigen::Vector3d object_rot;
+/* Eigen::Vector3d object_rot;
Eigen::Vector3d object_trans;
Eigen::Vector3d camera_eye;
- Eigen::Vector3d camera_center;
+ Eigen::Vector3d camera_center;*/
GLint shaderinfo[11];
@@ -59,15 +59,15 @@ private:
std::string rendererInfo;
- bool showfaces;
- bool showedges;
- bool showaxes;
+// bool showfaces;
+// bool showedges;
+// bool showaxes;
bool showcrosshairs;
- bool orthomode;
+// bool orthomode;
- double viewer_distance;
+// double viewer_distance;
- double w_h_ratio;
+// double w_h_ratio;
bool mouse_drag_active;
QPoint last_mouse;
diff --git a/src/mainwin.cc b/src/mainwin.cc
index 54f6d37..89e39a1 100644
--- a/src/mainwin.cc
+++ b/src/mainwin.cc
@@ -48,6 +48,7 @@
#include "ProgressWidget.h"
#include "ThrownTogetherRenderer.h"
#include "csgtermnormalizer.h"
+#include "QGLView.h"
#include <QMenu>
#include <QTime>
diff --git a/src/qglview.cc b/src/qglview.cc
index 7b193ec..f1c2cc6 100644
--- a/src/qglview.cc
+++ b/src/qglview.cc
@@ -57,8 +57,6 @@
#include <GL/glxew.h>
#endif
-#define FAR_FAR_AWAY 100000.0
-
QGLView::QGLView(QWidget *parent) : QGLWidget(parent)
{
init();
@@ -74,12 +72,8 @@ static bool running_under_wine = false;
void QGLView::init()
{
this->viewer_distance = 500;
- this->object_rot.x() = 35;
- this->object_rot.y() = 0;
- this->object_rot.z() = -25;
- this->object_trans.x() = 0;
- this->object_trans.y() = 0;
- this->object_trans.z() = 0;
+ this->object_rot << 35, 0, -25;
+ this->object_trans << 0, 0, 0;
this->mouse_drag_active = false;
@@ -334,10 +328,10 @@ void QGLView::resizeGL(int w, int h)
glViewport(0, 0, w, h);
w_h_ratio = sqrt((double)w / (double)h);
- setupGimbalPerspective();
+ GLView::setupGimbalPerspective();
}
-void QGLView::setupPerspective()
+/*void QGLView::setupPerspective()
{
fprintf(stderr,"non-gimbal camera not implemented for qglview\n");
}
@@ -367,13 +361,14 @@ void QGLView::setupGimbalOrtho(double distance, bool offset)
-FAR_FAR_AWAY, +FAR_FAR_AWAY);
gluLookAt(0.0, -viewer_distance, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
}
+*/
void QGLView::paintGL()
{
glEnable(GL_LIGHTING);
- if (orthomode) setupGimbalOrtho(viewer_distance);
- else setupGimbalPerspective();
+ if (orthomode) GLView::setupGimbalOrtho(viewer_distance);
+ else GLView::setupGimbalPerspective();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -443,7 +438,7 @@ void QGLView::paintGL()
{
glDepthFunc(GL_ALWAYS);
- setupGimbalOrtho(1000,true);
+ GLView::setupGimbalOrtho(1000,true);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
@@ -512,7 +507,7 @@ void QGLView::paintGL()
//Restore perspective for next paint
if(!orthomode)
- setupGimbalPerspective();
+ GLView::setupGimbalPerspective();
}
if (statusLabel) {
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index b7541e3..d9f6c3b 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -483,6 +483,7 @@ elseif(WIN32)
endif()
set(OFFSCREEN_SOURCES
+ ../src/GLView.cc
../src/OffscreenView.cc
../src/${OFFSCREEN_CTX_SOURCE}
../src/${OFFSCREEN_IMGUTILS_SOURCE}
contact: Jan Huwald // Impressum