diff options
author | Mika Salmela <mika.salmela@digia.com> | 2013-07-22 16:51:18 +0300 |
---|---|---|
committer | Mika Salmela <mika.salmela@digia.com> | 2013-07-22 16:52:38 +0300 |
commit | 51d6d0258c8d1fe0608045986792ac5601f8613f (patch) | |
tree | 95956d8f7e2f61ce2a56fc88ee094b51047078b9 /src/datavis3d | |
parent | 2ba572295f102ad06ae95ec676c064909775011f (diff) |
Fancy curve example and other stuff.
Change-Id: Id090ed0bedb3bec96ab6ba64b9af8205c1998f12
Reviewed-by: Mika Salmela <mika.salmela@digia.com>
Diffstat (limited to 'src/datavis3d')
-rw-r--r-- | src/datavis3d/engine/drawer.cpp | 4 | ||||
-rw-r--r-- | src/datavis3d/engine/q3dsurface.cpp | 20 | ||||
-rw-r--r-- | src/datavis3d/engine/q3dsurface.h | 7 | ||||
-rw-r--r-- | src/datavis3d/engine/surface3dcontroller.cpp | 11 | ||||
-rw-r--r-- | src/datavis3d/engine/surface3dcontroller_p.h | 10 | ||||
-rw-r--r-- | src/datavis3d/engine/surface3drenderer.cpp | 27 | ||||
-rw-r--r-- | src/datavis3d/engine/surface3drenderer_p.h | 2 | ||||
-rw-r--r-- | src/datavis3d/utils/abstractobjecthelper.cpp | 5 | ||||
-rw-r--r-- | src/datavis3d/utils/abstractobjecthelper_p.h | 3 | ||||
-rw-r--r-- | src/datavis3d/utils/objecthelper.cpp | 1 | ||||
-rw-r--r-- | src/datavis3d/utils/surfaceobject.cpp | 23 | ||||
-rw-r--r-- | src/datavis3d/utils/surfaceobject_p.h | 4 |
12 files changed, 88 insertions, 29 deletions
diff --git a/src/datavis3d/engine/drawer.cpp b/src/datavis3d/engine/drawer.cpp index 464ad518..43a379fd 100644 --- a/src/datavis3d/engine/drawer.cpp +++ b/src/datavis3d/engine/drawer.cpp @@ -146,7 +146,7 @@ void Drawer::drawObject(ShaderHelper *shader, AbstractObjectHelper *object, GLui glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object->elementBuf()); // Draw the triangles - glDrawElements(GL_TRIANGLES, object->indexCount(), GL_UNSIGNED_SHORT, (void*)0); + glDrawElements(GL_TRIANGLES, object->indexCount(), object->indicesType(), (void*)0); // Free buffers glBindBuffer(GL_ARRAY_BUFFER, 0); @@ -180,7 +180,7 @@ void Drawer::drawSurfaceGrid(ShaderHelper *shader, SurfaceObject *object) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, object->gridElementBuf()); // Draw the lines - glDrawElements(GL_LINES, object->gridIndexCount(), GL_UNSIGNED_SHORT, (void*)0); + glDrawElements(GL_LINES, object->gridIndexCount(), object->indicesType(), (void*)0); // Free buffers glBindBuffer(GL_ARRAY_BUFFER, 0); diff --git a/src/datavis3d/engine/q3dsurface.cpp b/src/datavis3d/engine/q3dsurface.cpp index ef4bebf6..951c3e58 100644 --- a/src/datavis3d/engine/q3dsurface.cpp +++ b/src/datavis3d/engine/q3dsurface.cpp @@ -131,12 +131,27 @@ void Q3DSurface::setHeight(const int height) QWindow::setHeight(height); } +/*! + * \a tickCount How many ticks will be drawn. \c 5 by default. + * + * \a step How large a step each tick is. + * + * \a minimum Minimum value a bar in data set can have. Setting this correctly is especially + * important if values can be negative, or autoscaling won't work correctly. + * + * Sets tick count and step. Note; tickCount * step should be the maximum possible value of data + * set. + */ +void Q3DSurface::setTickCount(int tickCount, qreal step, qreal minimum) +{ + d_ptr->m_shared->setTickCount(GLint(tickCount), GLfloat(step), GLfloat(minimum)); +} // TODO ///////////////////////////////////////// -void Q3DSurface::appendSeries(QList<qreal> series) +void Q3DSurface::appendSeries(QList<qreal> series, int width, int depth ) { d_ptr->appendSeries(series); - d_ptr->m_shared->setData(series, 9, 5); + d_ptr->m_shared->setData(series, width, depth); } void Q3DSurface::showData() @@ -163,6 +178,7 @@ Q3DSurfacePrivate::Q3DSurfacePrivate(Q3DSurface *q, QRect rect) Q3DSurfacePrivate::~Q3DSurfacePrivate() { qDebug() << "Q3DSurfacePrivate::~Q3DSurfacePrivate"; + delete m_shared; } void Q3DSurfacePrivate::appendSeries(QList<qreal> series) diff --git a/src/datavis3d/engine/q3dsurface.h b/src/datavis3d/engine/q3dsurface.h index a8607afe..03be2f17 100644 --- a/src/datavis3d/engine/q3dsurface.h +++ b/src/datavis3d/engine/q3dsurface.h @@ -67,8 +67,13 @@ public: void setSurfaceGrid(bool enable); bool surfaceGrid(); + // Set tick count and step. Note; tickCount * step should be the maximum possible value of data + // set. Minimum is the absolute minimum possible value a bar can have. This is especially + // important to set if values can be negative. + void setTickCount(int tickCount, qreal step, qreal minimum = 0.0f); + //TODO part - void appendSeries(QList<qreal> series); + void appendSeries(QList<qreal> series, int width, int depth); void showData(); //END TODO diff --git a/src/datavis3d/engine/surface3dcontroller.cpp b/src/datavis3d/engine/surface3dcontroller.cpp index 776b4c07..ca24da09 100644 --- a/src/datavis3d/engine/surface3dcontroller.cpp +++ b/src/datavis3d/engine/surface3dcontroller.cpp @@ -182,6 +182,16 @@ Drawer *Surface3dController::drawer() return 0; } +void Surface3dController::setTickCount(GLint tickCount, GLfloat step, GLfloat minimum) +{ + m_tickCount = tickCount; + m_tickStep = step; + m_tickMinimum = minimum; + + emit tickCountChanged(m_tickCount, m_tickStep, m_tickMinimum); +} + + // TODO: Temp void Surface3dController::setData(QList<qreal> series, int width, int depth) { @@ -189,7 +199,6 @@ void Surface3dController::setData(QList<qreal> series, int width, int depth) m_dataWidth = width; m_dataDepth = depth; - m_renderer->setYRangeStuff(5, 50.0f, 0.0f); m_renderer->setXZStuff(width, depth); m_renderer->setSeries(series); } diff --git a/src/datavis3d/engine/surface3dcontroller_p.h b/src/datavis3d/engine/surface3dcontroller_p.h index 1e1e5044..3207f6f3 100644 --- a/src/datavis3d/engine/surface3dcontroller_p.h +++ b/src/datavis3d/engine/surface3dcontroller_p.h @@ -72,6 +72,10 @@ private: bool m_smoothSurface; bool m_surfaceGrid; + GLint m_tickCount; + GLfloat m_tickStep; + GLfloat m_tickMinimum; + // Interaction MouseState m_mouseState; QPoint m_mousePos; @@ -97,6 +101,11 @@ public: void setSurfaceGrid(bool enable); bool surfaceGrid(); + // Set tick count and step. Note; tickCount * step should be the maximum possible value of data + // set. Minimum is the absolute minimum possible value a bar can have. This is especially + // important to set if values can be negative. + void setTickCount(GLint tickCount, GLfloat step, GLfloat minimum = 0.0f); + //TODO: Temp solution void setData(QList<qreal> series, int width, int depth); @@ -115,6 +124,7 @@ public: signals: void smoothStatusChanged(bool enable); void surfaceGridChanged(bool enable); + void tickCountChanged(GLint tickCount, GLfloat step, GLfloat minimum); private: Q_DISABLE_COPY(Surface3dController) diff --git a/src/datavis3d/engine/surface3drenderer.cpp b/src/datavis3d/engine/surface3drenderer.cpp index 13eaa6c7..1cd9231e 100644 --- a/src/datavis3d/engine/surface3drenderer.cpp +++ b/src/datavis3d/engine/surface3drenderer.cpp @@ -100,6 +100,8 @@ Surface3dRenderer::Surface3dRenderer(Surface3dController *controller) &Surface3dRenderer::updateSmoothStatus); QObject::connect(m_controller, &Surface3dController::surfaceGridChanged, this, &Surface3dRenderer::updateSurfaceGridStatus); + QObject::connect(m_controller, &Surface3dController::tickCountChanged, this, + &Surface3dRenderer::updateTickCount); m_cachedSmoothSurface = m_controller->smoothSurface(); updateSurfaceGridStatus(m_controller->surfaceGrid()); @@ -186,7 +188,7 @@ void Surface3dRenderer::initializeOpenGL() // Load background mesh (we need to be initialized first) loadBackgroundMesh(); - loadSurfaceObj(); + //loadSurfaceObj(); } void Surface3dRenderer::render(CameraHelper *camera, const GLuint defaultFboHandle) @@ -258,19 +260,19 @@ void Surface3dRenderer::drawScene(CameraHelper *camera, const GLuint defaultFboH depthViewMatrix.lookAt(lightPos, QVector3D(0.0f, -m_yAdjustment, zComp), QVector3D(0.0f, 1.0f, 0.0f)); // TODO: Move + // Enable texturing + glEnable(GL_TEXTURE_2D); + // // Do the surface drawing // - // Enable texturing - glEnable(GL_TEXTURE_2D); - - m_surfaceShader->bind(); + if (m_surfaceObj) { + m_surfaceShader->bind(); - // For surface we can see climpses from underneath - glDisable(GL_CULL_FACE); + // For surface we can see climpses from underneath + glDisable(GL_CULL_FACE); - if (1) { QMatrix4x4 modelMatrix; QMatrix4x4 MVPMatrix; QMatrix4x4 depthMVPMatrix; @@ -417,7 +419,7 @@ void Surface3dRenderer::drawScene(CameraHelper *camera, const GLuint defaultFboH } } -void Surface3dRenderer::setYRangeStuff(GLint tickCount, GLfloat step, GLfloat minimum) +void Surface3dRenderer::updateTickCount(GLint tickCount, GLfloat step, GLfloat minimum) { m_tickYCount = tickCount; m_tickYStep = step; @@ -453,6 +455,10 @@ void Surface3dRenderer::setSeries(QList<qreal> series) // m_surfaceObj->setUpData(temp, 3, 3, m_yRange); m_series = series; + // TODO temp solution + if (!m_surfaceObj) + loadSurfaceObj(); + if (m_cachedSmoothSurface) m_surfaceObj->setUpSmoothData(series, m_tickXCount, m_tickZCount, m_yRange, true); else @@ -487,6 +493,9 @@ void Surface3dRenderer::updateSmoothStatus(bool enable) { m_cachedSmoothSurface = enable; + if (!m_surfaceObj) + return; + if (m_cachedSmoothSurface) m_surfaceObj->setUpSmoothData(m_series, m_tickXCount, m_tickZCount, m_yRange, true); else diff --git a/src/datavis3d/engine/surface3drenderer_p.h b/src/datavis3d/engine/surface3drenderer_p.h index 11b19573..1d6ffafe 100644 --- a/src/datavis3d/engine/surface3drenderer_p.h +++ b/src/datavis3d/engine/surface3drenderer_p.h @@ -153,6 +153,7 @@ public: public slots: void updateSmoothStatus(bool enable); void updateSurfaceGridStatus(bool enable); + void updateTickCount(GLint tickCount, GLfloat step, GLfloat minimum = 0.0f); public: // Size @@ -186,7 +187,6 @@ public: void loadSurfaceObj(); // TODO: temp - void setYRangeStuff(GLint tickCount, GLfloat step, GLfloat minimum); void setXZStuff(GLint tickXCount, GLint tickZCount); void setSeries(QList<qreal> series); diff --git a/src/datavis3d/utils/abstractobjecthelper.cpp b/src/datavis3d/utils/abstractobjecthelper.cpp index d80e416b..c75d9cf5 100644 --- a/src/datavis3d/utils/abstractobjecthelper.cpp +++ b/src/datavis3d/utils/abstractobjecthelper.cpp @@ -98,4 +98,9 @@ GLuint AbstractObjectHelper::indexCount() return m_indexCount; } +GLuint AbstractObjectHelper::indicesType() +{ + return m_indicesType; +} + QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/abstractobjecthelper_p.h b/src/datavis3d/utils/abstractobjecthelper_p.h index 4fa9d0ec..fd565b10 100644 --- a/src/datavis3d/utils/abstractobjecthelper_p.h +++ b/src/datavis3d/utils/abstractobjecthelper_p.h @@ -69,6 +69,7 @@ public: GLuint uvBuf(); GLuint elementBuf(); GLuint indexCount(); + GLuint indicesType(); public: GLuint m_vertexbuffer; @@ -78,6 +79,8 @@ public: GLuint m_indexCount; GLboolean m_meshDataLoaded; + + GLuint m_indicesType; }; QT_DATAVIS3D_END_NAMESPACE diff --git a/src/datavis3d/utils/objecthelper.cpp b/src/datavis3d/utils/objecthelper.cpp index df77d395..aef1ddd0 100644 --- a/src/datavis3d/utils/objecthelper.cpp +++ b/src/datavis3d/utils/objecthelper.cpp @@ -51,6 +51,7 @@ QT_DATAVIS3D_BEGIN_NAMESPACE ObjectHelper::ObjectHelper(const QString &objectFile) : m_objectFile(objectFile) { + m_indicesType = GL_UNSIGNED_SHORT; } ObjectHelper::~ObjectHelper() diff --git a/src/datavis3d/utils/surfaceobject.cpp b/src/datavis3d/utils/surfaceobject.cpp index 32d6b65c..8fe14aee 100644 --- a/src/datavis3d/utils/surfaceobject.cpp +++ b/src/datavis3d/utils/surfaceobject.cpp @@ -51,6 +51,7 @@ QT_DATAVIS3D_BEGIN_NAMESPACE SurfaceObject::SurfaceObject() { + m_indicesType = GL_UNSIGNED_INT; } SurfaceObject::~SurfaceObject() @@ -99,10 +100,10 @@ void SurfaceObject::setUpSmoothData(QList<qreal> series, int columns, int rows, vertices.at(p - columns - 1))); // Create indice table - GLushort *indices = 0; + GLint *indices = 0; if (changeGeometry) { m_indexCount = 6 * (columns - 1) * (rows - 1); - indices = new GLushort[m_indexCount]; + indices = new GLint[m_indexCount]; p = 0; for (int row = 0; row < (rows - 1) * columns; row += columns) { for (int j = 0; j < columns - 1; j++) { @@ -120,10 +121,10 @@ void SurfaceObject::setUpSmoothData(QList<qreal> series, int columns, int rows, } // Create line element indices - GLushort *gridIndices = 0; + GLint *gridIndices = 0; if (changeGeometry) { m_gridIndexCount = 2 * columns * (rows - 1) + 2 * rows * (columns - 1); - gridIndices = new GLushort[m_gridIndexCount]; + gridIndices = new GLint[m_gridIndexCount]; p = 0; for (int i = 0, row = 0; i < rows; i++, row += columns) { for (int j = 0; j < columns - 1; j++) { @@ -174,11 +175,11 @@ void SurfaceObject::setUpData(QList<qreal> series, int columns, int rows, GLfloa QVector<QVector3D> normals; int doubleColumns = columns * 2 - 2; - GLushort *indices = 0; + GLint *indices = 0; int p = 0; if (changeGeometry) { m_indexCount = 6 * (columns - 1) * (rows - 1); - indices = new GLushort[m_indexCount]; + indices = new GLint[m_indexCount]; } for (int row = 0, upperRow = doubleColumns; @@ -211,7 +212,7 @@ void SurfaceObject::setUpData(QList<qreal> series, int columns, int rows, GLfloa // Create grid line element indices m_gridIndexCount = 2 * columns * (rows - 1) + 2 * rows * (columns - 1); - GLushort *gridIndices = new GLushort[m_gridIndexCount]; + GLint *gridIndices = new GLint[m_gridIndexCount]; p = 0; int rowLimit = (rows - 1) * doubleColumns; for (int row = 0; row < rows * doubleColumns; row += doubleColumns) { @@ -240,8 +241,8 @@ void SurfaceObject::setUpData(QList<qreal> series, int columns, int rows, GLfloa void SurfaceObject::createBuffers(const QVector<QVector3D> &vertices, const QVector<QVector2D> &uvs, - const QVector<QVector3D> &normals, const GLushort *indices, - const GLushort *gridIndices, bool changeGeometry) + const QVector<QVector3D> &normals, const GLint *indices, + const GLint *gridIndices, bool changeGeometry) { initializeOpenGLFunctions(); if (m_meshDataLoaded) { @@ -274,12 +275,12 @@ void SurfaceObject::createBuffers(const QVector<QVector3D> &vertices, const QVec glGenBuffers(1, &m_elementbuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_elementbuffer); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indexCount * sizeof(GLushort), + glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_indexCount * sizeof(GLint), indices, GL_STATIC_DRAW); glGenBuffers(1, &m_gridElementbuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_gridElementbuffer); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_gridIndexCount * sizeof(GLushort), + glBufferData(GL_ELEMENT_ARRAY_BUFFER, m_gridIndexCount * sizeof(GLint), gridIndices, GL_STATIC_DRAW); } diff --git a/src/datavis3d/utils/surfaceobject_p.h b/src/datavis3d/utils/surfaceobject_p.h index 3ebac514..7ca422de 100644 --- a/src/datavis3d/utils/surfaceobject_p.h +++ b/src/datavis3d/utils/surfaceobject_p.h @@ -72,8 +72,8 @@ public: private: QVector3D normal(const QVector3D &a, const QVector3D &b, const QVector3D &c); void createBuffers(const QVector<QVector3D> &vertices, const QVector<QVector2D> &uvs, - const QVector<QVector3D> &normals, const GLushort *indices, - const GLushort *gridIndices, bool changeGeometry); + const QVector<QVector3D> &normals, const GLint *indices, + const GLint *gridIndices, bool changeGeometry); private: QList<qreal> m_series; |