Demo now supports large volumes (1024x1024x1024 works nicely).

This commit is contained in:
David Williams 2009-04-08 19:18:12 +00:00
parent 97b162ee20
commit 3c5e2e6202
2 changed files with 50 additions and 9 deletions

View File

@ -1,5 +1,7 @@
#include "OpenGLWidget.h"
#include <QMouseEvent>
//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<PolyVox::uint8_t>* 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;
}

View File

@ -4,6 +4,7 @@
#include "glew/glew.h"
#include <QGLWidget>
#include <QTimer>
#include "Volume.h"
#include "IndexedSurfacePatch.h"
@ -26,12 +27,24 @@ class OpenGLWidget : public QGLWidget
void setVolume(PolyVox::Volume<PolyVox::uint8_t>* 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;