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)
|
||||
:QGLWidget(parent)
|
||||
,mCenterPoint(32,32,32)
|
||||
,mDistFromCenter(50)
|
||||
,m_viewableRegion(Region(0, 0, 0, 255, 255, 255))
|
||||
,m_xRotation(0)
|
||||
,m_yRotation(0)
|
||||
{
|
||||
@ -51,6 +50,12 @@ void OpenGLWidget::setSurfaceMeshToRender(const PolyVox::SurfaceMesh<CubicVertex
|
||||
mMeshData.push_back(meshData);
|
||||
}
|
||||
|
||||
void OpenGLWidget::setViewableRegion(Region viewableRegion)
|
||||
{
|
||||
m_viewableRegion = viewableRegion;
|
||||
setupWorldToCameraMatrix();
|
||||
}
|
||||
|
||||
void OpenGLWidget::initializeGL()
|
||||
{
|
||||
GLenum err = glewInit();
|
||||
@ -209,11 +214,17 @@ void OpenGLWidget::setupWorldToCameraMatrix()
|
||||
{
|
||||
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{};
|
||||
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_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);
|
||||
|
||||
|
@ -52,6 +52,8 @@ public:
|
||||
//Convert a SurfaceMesh to OpenGL index/vertex buffers
|
||||
void setSurfaceMeshToRender(const PolyVox::SurfaceMesh<PolyVox::CubicVertex<uint8_t> >& surfaceMesh);
|
||||
|
||||
void setViewableRegion(PolyVox::Region viewableRegion);
|
||||
|
||||
protected:
|
||||
//Qt OpenGL functions
|
||||
void initializeGL();
|
||||
@ -72,8 +74,7 @@ private:
|
||||
QPoint m_CurrentMousePos;
|
||||
|
||||
//Camera setup
|
||||
QVector3D mCenterPoint;
|
||||
float mDistFromCenter;
|
||||
PolyVox::Region m_viewableRegion;
|
||||
int m_xRotation;
|
||||
int m_yRotation;
|
||||
};
|
||||
|
@ -86,6 +86,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
//Pass the surface to the OpenGL window
|
||||
openGLWidget.setSurfaceMeshToRender(mesh);
|
||||
openGLWidget.setViewableRegion(volData.getEnclosingRegion());
|
||||
//openGLWidget.setSurfaceMeshToRender(mesh2);
|
||||
|
||||
//Run the message pump.
|
||||
|
Loading…
x
Reference in New Issue
Block a user