Added ability to specify the visible region so that the example framework can support different volume sizes.
This commit is contained in:
parent
ab741583e4
commit
4cec89de38
@ -9,8 +9,7 @@ using namespace std;
|
|||||||
|
|
||||||
OpenGLWidget::OpenGLWidget(QWidget *parent)
|
OpenGLWidget::OpenGLWidget(QWidget *parent)
|
||||||
:QGLWidget(parent)
|
:QGLWidget(parent)
|
||||||
,mCenterPoint(32,32,32)
|
,m_viewableRegion(Region(0, 0, 0, 255, 255, 255))
|
||||||
,mDistFromCenter(50)
|
|
||||||
,m_xRotation(0)
|
,m_xRotation(0)
|
||||||
,m_yRotation(0)
|
,m_yRotation(0)
|
||||||
{
|
{
|
||||||
@ -51,6 +50,12 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<CubicVertex
|
|||||||
mMeshData.push_back(meshData);
|
mMeshData.push_back(meshData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OpenGLWidget::setViewableRegion(Region viewableRegion)
|
||||||
|
{
|
||||||
|
m_viewableRegion = viewableRegion;
|
||||||
|
setupWorldToCameraMatrix();
|
||||||
|
}
|
||||||
|
|
||||||
void OpenGLWidget::initializeGL()
|
void OpenGLWidget::initializeGL()
|
||||||
{
|
{
|
||||||
GLenum err = glewInit();
|
GLenum err = glewInit();
|
||||||
@ -209,11 +214,17 @@ void OpenGLWidget::setupWorldToCameraMatrix()
|
|||||||
{
|
{
|
||||||
shader.bind();
|
shader.bind();
|
||||||
|
|
||||||
|
QVector3D lowerCorner(m_viewableRegion.getLowerX(), m_viewableRegion.getLowerY(), m_viewableRegion.getLowerZ());
|
||||||
|
QVector3D upperCorner(m_viewableRegion.getUpperX(), m_viewableRegion.getUpperY(), m_viewableRegion.getUpperZ());
|
||||||
|
|
||||||
|
QVector3D centerPoint = (lowerCorner + upperCorner) * 0.5;
|
||||||
|
float fDiagonalLength = (upperCorner - lowerCorner).length();
|
||||||
|
|
||||||
QMatrix4x4 worldToCameraMatrix{};
|
QMatrix4x4 worldToCameraMatrix{};
|
||||||
worldToCameraMatrix.translate(0, 0, -mDistFromCenter); //Move the camera back by the required amount
|
worldToCameraMatrix.translate(0, 0, -fDiagonalLength / 2.0f); //Move the camera back by the required amount
|
||||||
worldToCameraMatrix.rotate(m_xRotation, 0, 1, 0); //rotate around y-axis
|
worldToCameraMatrix.rotate(m_xRotation, 0, 1, 0); //rotate around y-axis
|
||||||
worldToCameraMatrix.rotate(m_yRotation, 1, 0, 0); //rotate around x-axis
|
worldToCameraMatrix.rotate(m_yRotation, 1, 0, 0); //rotate around x-axis
|
||||||
worldToCameraMatrix.translate(-mCenterPoint); //centre the model on the origin
|
worldToCameraMatrix.translate(-centerPoint); //centre the model on the origin
|
||||||
|
|
||||||
shader.setUniformValue("worldToCameraMatrix", worldToCameraMatrix);
|
shader.setUniformValue("worldToCameraMatrix", worldToCameraMatrix);
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@ public:
|
|||||||
//Convert a SurfaceMesh to OpenGL index/vertex buffers
|
//Convert a SurfaceMesh to OpenGL index/vertex buffers
|
||||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::CubicVertex<uint8_t> >& surfaceMesh);
|
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::CubicVertex<uint8_t> >& surfaceMesh);
|
||||||
|
|
||||||
|
void setViewableRegion(PolyVox::Region viewableRegion);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//Qt OpenGL functions
|
//Qt OpenGL functions
|
||||||
void initializeGL();
|
void initializeGL();
|
||||||
@ -72,8 +74,7 @@ private:
|
|||||||
QPoint m_CurrentMousePos;
|
QPoint m_CurrentMousePos;
|
||||||
|
|
||||||
//Camera setup
|
//Camera setup
|
||||||
QVector3D mCenterPoint;
|
PolyVox::Region m_viewableRegion;
|
||||||
float mDistFromCenter;
|
|
||||||
int m_xRotation;
|
int m_xRotation;
|
||||||
int m_yRotation;
|
int m_yRotation;
|
||||||
};
|
};
|
||||||
|
@ -86,6 +86,7 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
//Pass the surface to the OpenGL window
|
//Pass the surface to the OpenGL window
|
||||||
openGLWidget.setSurfaceMeshToRender(mesh);
|
openGLWidget.setSurfaceMeshToRender(mesh);
|
||||||
|
openGLWidget.setViewableRegion(volData.getEnclosingRegion());
|
||||||
//openGLWidget.setSurfaceMeshToRender(mesh2);
|
//openGLWidget.setSurfaceMeshToRender(mesh2);
|
||||||
|
|
||||||
//Run the message pump.
|
//Run the message pump.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user