Demo now supports large volumes (1024x1024x1024 works nicely).
This commit is contained in:
parent
97b162ee20
commit
3c5e2e6202
@ -1,5 +1,7 @@
|
|||||||
#include "OpenGLWidget.h"
|
#include "OpenGLWidget.h"
|
||||||
|
|
||||||
|
#include <QMouseEvent>
|
||||||
|
|
||||||
//Some namespaces we need
|
//Some namespaces we need
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace PolyVox;
|
using namespace PolyVox;
|
||||||
@ -7,11 +9,14 @@ using namespace std;
|
|||||||
|
|
||||||
OpenGLWidget::OpenGLWidget(QWidget *parent)
|
OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||||
:QGLWidget(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)
|
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 );
|
glViewport ( 0, 0, w, h );
|
||||||
glMatrixMode ( GL_PROJECTION ); // Select The Projection Matrix
|
glMatrixMode ( GL_PROJECTION ); // Select The Projection Matrix
|
||||||
glLoadIdentity ( ); // Reset 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 );
|
float aspect = ( float ) w / ( float ) h;
|
||||||
else
|
glOrtho(-m_distance*aspect, m_distance*aspect, -m_distance, m_distance, 1.0, 5000);
|
||||||
gluPerspective ( 80, ( float ) w / ( float ) h, 1.0, 5000.0 );
|
|
||||||
glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix
|
glMatrixMode ( GL_MODELVIEW ); // Select The Model View Matrix
|
||||||
glLoadIdentity ( ); // Reset The Model View Matrix
|
glLoadIdentity ( ); // Reset The Model View Matrix
|
||||||
}
|
}
|
||||||
@ -122,12 +126,16 @@ void OpenGLWidget::paintGL()
|
|||||||
glLoadIdentity(); // Reset The Current Modelview Matrix
|
glLoadIdentity(); // Reset The Current Modelview Matrix
|
||||||
|
|
||||||
//Moves the camera back so we can see the volume
|
//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
|
//Rotate the volume by the required amount
|
||||||
//glRotatef(g_xRotation, 1.0f, 0.0f, 0.0f);
|
//glRotatef(g_xRotation, 1.0f, 0.0f, 0.0f);
|
||||||
//glRotatef(g_yRotation, 0.0f, 1.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
|
//Centre the volume on the origin
|
||||||
glTranslatef(-g_uVolumeSideLength/2,-g_uVolumeSideLength/2,-g_uVolumeSideLength/2);
|
glTranslatef(-g_uVolumeSideLength/2,-g_uVolumeSideLength/2,-g_uVolumeSideLength/2);
|
||||||
|
|
||||||
@ -160,4 +168,24 @@ void OpenGLWidget::paintGL()
|
|||||||
errString = gluErrorString(errCode);
|
errString = gluErrorString(errCode);
|
||||||
cout << "OpenGL Error: " << errString << endl;
|
cout << "OpenGL Error: " << errString << endl;
|
||||||
} // Reset The Current Modelview Matrix
|
} // 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;
|
||||||
}
|
}
|
@ -4,6 +4,7 @@
|
|||||||
#include "glew/glew.h"
|
#include "glew/glew.h"
|
||||||
|
|
||||||
#include <QGLWidget>
|
#include <QGLWidget>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "Volume.h"
|
#include "Volume.h"
|
||||||
#include "IndexedSurfacePatch.h"
|
#include "IndexedSurfacePatch.h"
|
||||||
@ -26,12 +27,24 @@ class OpenGLWidget : public QGLWidget
|
|||||||
|
|
||||||
void setVolume(PolyVox::Volume<PolyVox::uint8_t>* volData);
|
void setVolume(PolyVox::Volume<PolyVox::uint8_t>* volData);
|
||||||
|
|
||||||
|
void mouseMoveEvent(QMouseEvent* event);
|
||||||
|
void mousePressEvent(QMouseEvent* event);
|
||||||
|
void wheelEvent ( QWheelEvent * event );
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void initializeGL();
|
void initializeGL();
|
||||||
void resizeGL(int w, int h);
|
void resizeGL(int w, int h);
|
||||||
void paintGL();
|
void paintGL();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QPoint m_LastFrameMousePos;
|
||||||
|
QPoint m_CurrentMousePos;
|
||||||
|
|
||||||
|
int m_xRotation;
|
||||||
|
int m_yRotation;
|
||||||
|
float m_distance;
|
||||||
|
|
||||||
|
QTimer *timer;
|
||||||
|
|
||||||
bool m_bUseOpenGLVertexBufferObjects;
|
bool m_bUseOpenGLVertexBufferObjects;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user