From 3c5e2e620213b66e89c5683b18a8816e0cc6610b Mon Sep 17 00:00:00 2001 From: David Williams Date: Wed, 8 Apr 2009 19:18:12 +0000 Subject: [PATCH] Demo now supports large volumes (1024x1024x1024 works nicely). --- examples/OpenGL/OpenGLWidget.cpp | 46 +++++++++++++++++++++++++------- examples/OpenGL/OpenGLWidget.h | 13 +++++++++ 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/examples/OpenGL/OpenGLWidget.cpp b/examples/OpenGL/OpenGLWidget.cpp index 9be4bed9..506fb7dc 100644 --- a/examples/OpenGL/OpenGLWidget.cpp +++ b/examples/OpenGL/OpenGLWidget.cpp @@ -1,5 +1,7 @@ #include "OpenGLWidget.h" +#include + //Some namespaces we need using namespace std; using namespace PolyVox; @@ -7,11 +9,14 @@ using namespace std; OpenGLWidget::OpenGLWidget(QWidget *parent) :QGLWidget(parent) -{ - +{ + m_xRotation = 0; + m_yRotation = 0; + m_distance = -g_uVolumeSideLength / 2.0f; - - + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(update())); + timer->start(0); } void OpenGLWidget::setVolume(PolyVox::Volume* volData) @@ -106,10 +111,9 @@ void OpenGLWidget::resizeGL(int w, int h) glViewport ( 0, 0, w, h ); glMatrixMode ( GL_PROJECTION ); // Select The Projection Matrix glLoadIdentity ( ); // Reset The Projection Matrix - if ( h==0 ) // Calculate The Aspect Ratio Of The Window - gluPerspective ( 80, ( float ) w, 1.0, 5000.0 ); - else - gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 ); + + float aspect = ( float ) w / ( float ) h; + glOrtho(-m_distance*aspect, m_distance*aspect, -m_distance, m_distance, 1.0, 5000); glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix glLoadIdentity ( ); // Reset The Model View Matrix } @@ -122,12 +126,16 @@ void OpenGLWidget::paintGL() glLoadIdentity(); // Reset The Current Modelview Matrix //Moves the camera back so we can see the volume - glTranslatef(0.0f, 0.0f, -100.0f); + glTranslatef(0.0f, 0.0f, m_distance); //Rotate the volume by the required amount //glRotatef(g_xRotation, 1.0f, 0.0f, 0.0f); //glRotatef(g_yRotation, 0.0f, 1.0f, 0.0f); + ; + glRotatef(m_xRotation, 1.0f, 0.0f, 0.0f); + glRotatef(m_yRotation, 0.0f, 1.0f, 0.0f); + //Centre the volume on the origin glTranslatef(-g_uVolumeSideLength/2,-g_uVolumeSideLength/2,-g_uVolumeSideLength/2); @@ -160,4 +168,24 @@ void OpenGLWidget::paintGL() errString = gluErrorString(errCode); cout << "OpenGL Error: " << errString << endl; } // Reset The Current Modelview Matrix +} + +void OpenGLWidget::mousePressEvent(QMouseEvent* event) +{ + m_CurrentMousePos = event->pos(); + m_LastFrameMousePos = m_CurrentMousePos; +} + +void OpenGLWidget::mouseMoveEvent(QMouseEvent* event) +{ + m_CurrentMousePos = event->pos(); + QPoint diff = m_CurrentMousePos - m_LastFrameMousePos; + m_xRotation += diff.x(); + m_yRotation += diff.y(); + m_LastFrameMousePos = m_CurrentMousePos;; +} + +void OpenGLWidget::wheelEvent(QWheelEvent* event) +{ + m_distance += event->delta() / 120.0f; } \ No newline at end of file diff --git a/examples/OpenGL/OpenGLWidget.h b/examples/OpenGL/OpenGLWidget.h index df78e099..8bfd4b6f 100644 --- a/examples/OpenGL/OpenGLWidget.h +++ b/examples/OpenGL/OpenGLWidget.h @@ -4,6 +4,7 @@ #include "glew/glew.h" #include +#include #include "Volume.h" #include "IndexedSurfacePatch.h" @@ -26,12 +27,24 @@ class OpenGLWidget : public QGLWidget void setVolume(PolyVox::Volume* volData); + void mouseMoveEvent(QMouseEvent* event); + void mousePressEvent(QMouseEvent* event); + void wheelEvent ( QWheelEvent * event ); + protected: void initializeGL(); void resizeGL(int w, int h); void paintGL(); private: + QPoint m_LastFrameMousePos; + QPoint m_CurrentMousePos; + + int m_xRotation; + int m_yRotation; + float m_distance; + + QTimer *timer; bool m_bUseOpenGLVertexBufferObjects;