From 16cbb94d90b1d8a1df1c89759beba30c2f47b52e Mon Sep 17 00:00:00 2001 From: David Williams Date: Thu, 22 May 2014 16:51:41 +0200 Subject: [PATCH] Rotation is now applied by moving the camera rather than the meshes. --- examples/Basic/OpenGLWidget.cpp | 27 +++++++++++++++------------ examples/Basic/main.cpp | 8 ++++---- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/examples/Basic/OpenGLWidget.cpp b/examples/Basic/OpenGLWidget.cpp index e9998220..5ca5880f 100644 --- a/examples/Basic/OpenGLWidget.cpp +++ b/examples/Basic/OpenGLWidget.cpp @@ -129,15 +129,6 @@ void OpenGLWidget::initializeGL() std::cerr << shader.log().toStdString() << std::endl; exit(EXIT_FAILURE); } - - shader.bind(); - - QMatrix4x4 worldToCameraMatrix{}; - worldToCameraMatrix.translate(0, 0, -50); //Move the camera back by 50 units - - shader.setUniformValue("worldToCameraMatrix", worldToCameraMatrix); - - shader.release(); } void OpenGLWidget::resizeGL(int w, int h) @@ -163,9 +154,9 @@ void OpenGLWidget::paintGL() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); QMatrix4x4 modelToWorldMatrix{}; - modelToWorldMatrix.rotate(m_xRotation, 0, 1, 0); //rotate around y-axis - modelToWorldMatrix.rotate(m_yRotation, 1, 0, 0); //rotate around x-axis - modelToWorldMatrix.translate(-32, -32, -32); //centre the model on the origin + //modelToWorldMatrix.rotate(m_xRotation, 0, 1, 0); //rotate around y-axis + //modelToWorldMatrix.rotate(m_yRotation, 1, 0, 0); //rotate around x-axis + //modelToWorldMatrix.translate(-32, -32, -32); //centre the model on the origin shader.bind(); @@ -205,5 +196,17 @@ void OpenGLWidget::mouseMoveEvent(QMouseEvent* event) m_yRotation += diff.y(); m_LastFrameMousePos = m_CurrentMousePos; + shader.bind(); + + QMatrix4x4 worldToCameraMatrix{}; + worldToCameraMatrix.translate(0, 0, -50); //Move the camera back by 50 units + worldToCameraMatrix.rotate(m_xRotation, 0, 1, 0); //rotate around y-axis + worldToCameraMatrix.rotate(m_yRotation, 1, 0, 0); //rotate around x-axis + worldToCameraMatrix.translate(-32, -32, -32); //centre the model on the origin + + shader.setUniformValue("worldToCameraMatrix", worldToCameraMatrix); + + shader.release(); + update(); } diff --git a/examples/Basic/main.cpp b/examples/Basic/main.cpp index 3b04f04c..72dd96eb 100644 --- a/examples/Basic/main.cpp +++ b/examples/Basic/main.cpp @@ -78,15 +78,15 @@ int main(int argc, char *argv[]) createSphereInVolume(volData, 30); // Extract the surface for the specified region of the volume. Uncomment the line for the kind of surface extraction you want to see. - //auto mesh = extractCubicSurface(&volData, volData.getEnclosingRegion()); + auto mesh = extractCubicSurface(&volData, volData.getEnclosingRegion()); //auto mesh = extractMarchingCubesSurface(&volData, volData.getEnclosingRegion()); - auto mesh = extractCubicSurface(&volData, PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(31, 31, 31))); - auto mesh2 = extractCubicSurface(&volData, PolyVox::Region(Vector3DInt32(32, 32, 32), Vector3DInt32(63, 63, 63))); + //auto mesh = extractCubicSurface(&volData, PolyVox::Region(Vector3DInt32(0, 0, 0), Vector3DInt32(31, 31, 31))); + //auto mesh2 = extractCubicSurface(&volData, PolyVox::Region(Vector3DInt32(32, 32, 32), Vector3DInt32(63, 63, 63))); //Pass the surface to the OpenGL window openGLWidget.setSurfaceMeshToRender(mesh); - openGLWidget.setSurfaceMeshToRender(mesh2); + //openGLWidget.setSurfaceMeshToRender(mesh2); //Run the message pump. return app.exec();