From a52b87c191dcb2af72b28cdc952d209a4ec403cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomi=20Korpip=C3=A4=C3=A4?= Date: Tue, 26 Mar 2013 07:29:20 +0200 Subject: Added API for preset camera positions Added utilization of presets to example Made some mac fixes --- src/datavis3d/engine/q3dbars.cpp | 103 ++++++++++++++++++++++++++++++++++ src/datavis3d/engine/q3dbars.h | 33 ++++++++++- src/datavis3d/utils/camerahelper.cpp | 3 +- src/datavis3d/utils/objecthelper_p.h | 2 +- src/datavis3d/utils/vertexindexer.cpp | 3 +- 5 files changed, 139 insertions(+), 5 deletions(-) (limited to 'src/datavis3d') diff --git a/src/datavis3d/engine/q3dbars.cpp b/src/datavis3d/engine/q3dbars.cpp index 01a58f8d..93ecaf14 100644 --- a/src/datavis3d/engine/q3dbars.cpp +++ b/src/datavis3d/engine/q3dbars.cpp @@ -736,6 +736,109 @@ void Q3DBars::setupSampleSpace(QPoint sampleCount) d_ptr->calculateSceneScalingFactors(); } +void Q3DBars::setCameraPreset(CameraPreset preset) +{ + switch (preset) { + case PresetFrontLow: { + qDebug("PresetFrontLow"); + setCameraPosition(0.0f, 0.0f); + break; + } + case PresetFront: { + qDebug("PresetFront"); + setCameraPosition(0.0f, 22.5f); + break; + } + case PresetFrontHigh: { + qDebug("PresetFrontHigh"); + setCameraPosition(0.0f, 45.0f); + break; + } + case PresetLeftLow: { + qDebug("PresetLeftLow"); + setCameraPosition(90.0f, 0.0f); + break; + } + case PresetLeft: { + qDebug("PresetLeft"); + setCameraPosition(90.0f, 22.5f); + break; + } + case PresetLeftHigh: { + qDebug("PresetLeftHigh"); + setCameraPosition(90.0f, 45.0f); + break; + } + case PresetRightLow: { + qDebug("PresetRightLow"); + setCameraPosition(-90.0f, 0.0f); + break; + } + case PresetRight: { + qDebug("PresetRight"); + setCameraPosition(-90.0f, 22.5f); + break; + } + case PresetRightHigh: { + qDebug("PresetRightHigh"); + setCameraPosition(-90.0f, 45.0f); + break; + } + case PresetBehindLow: { + qDebug("PresetBehindLow"); + setCameraPosition(180.0f, 0.0f); + break; + } + case PresetBehind: { + qDebug("PresetBehind"); + setCameraPosition(180.0f, 22.5f); + break; + } + case PresetBehindHigh: { + qDebug("PresetBehindHigh"); + setCameraPosition(180.0f, 45.0f); + break; + } + case PresetIsometricLeft: { + qDebug("PresetIsometricLeft"); + setCameraPosition(45.0f, 22.5f); + break; + } + case PresetIsometricLeftHigh: { + qDebug("PresetIsometricLeftHigh"); + setCameraPosition(45.0f, 45.0f); + break; + } + case PresetIsometricRight: { + qDebug("PresetIsometricRight"); + setCameraPosition(-45.0f, 22.5f); + break; + } + case PresetIsometricRightHigh: { + qDebug("PresetIsometricRightHigh"); + setCameraPosition(-45.0f, 45.0f); + break; + } + case PresetDirectlyAbove: { + qDebug("PresetDirectlyAbove"); + setCameraPosition(0.0f, 90.0f); + break; + } + case PresetDirectlyAboveCW45: { + qDebug("PresetDirectlyAboveCW45"); + setCameraPosition(-45.0f, 90.0f); + break; + } + case PresetDirectlyAboveCCW45: { + qDebug("PresetDirectlyAboveCCW45"); + setCameraPosition(45.0f, 90.0f); + break; + } + default: + break; + } +} + void Q3DBars::setCameraPosition(float horizontal, float vertical, int distance) { d_ptr->m_horizontalRotation = qBound(-180.0f, horizontal, 180.0f); diff --git a/src/datavis3d/engine/q3dbars.h b/src/datavis3d/engine/q3dbars.h index 5b1ab6ff..dee30d9a 100644 --- a/src/datavis3d/engine/q3dbars.h +++ b/src/datavis3d/engine/q3dbars.h @@ -20,6 +20,29 @@ public: Cones, Cylinders }; + + enum CameraPreset { + PresetFrontLow = 0, + PresetFront, + PresetFrontHigh, + PresetLeftLow, + PresetLeft, + PresetLeftHigh, + PresetRightLow, + PresetRight, + PresetRightHigh, + PresetBehindLow, + PresetBehind, + PresetBehindHigh, + PresetIsometricLeft, + PresetIsometricLeftHigh, + PresetIsometricRight, + PresetIsometricRightHigh, + PresetDirectlyAbove, + PresetDirectlyAboveCW45, + PresetDirectlyAboveCCW45 + }; + enum SelectionMode { None = 0, Bar, @@ -53,12 +76,18 @@ public: void setMeshFileName(const QString &objFileName); // how many samples per row and column void setupSampleSpace(QPoint sampleCount); - // Set camera rotation (in horizontal (-180...180) and vertical (0...90) angles and distance in percentage (10...500)) + // Select preset camera placement + void setCameraPreset(CameraPreset preset); + // Set camera rotation if you don't want to use the presets (in horizontal (-180...180) and + // vertical (0...90) angles and distance in percentage (10...500)) void setCameraPosition(float horizontal, float vertical, int distance = 100); - // TODO: värien asetus (vai themeillä?). Set uniform to false if you want the (height) color to change from bottom to top + // Set theme (bar colors, shaders, background colors and text colors are affected) + void setTheme(); // TODO: joku enum kai + // Set color if you don't want to use themes. Set uniform to false if you want the (height) color to change from bottom to top void setBarColor(QColor baseColor, QColor heightColor, QColor depthColor, bool uniform = true); // TODO: shaderien vaihto (themet?) // TODO: valon siirto / asetus + // Change selection mode; single bar, bar and row, bar and column, or all void setSelectionMode(SelectionMode mode); protected: diff --git a/src/datavis3d/utils/camerahelper.cpp b/src/datavis3d/utils/camerahelper.cpp index 4e0a5409..bef73a56 100644 --- a/src/datavis3d/utils/camerahelper.cpp +++ b/src/datavis3d/utils/camerahelper.cpp @@ -1,5 +1,6 @@ #include "camerahelper_p.h" +#include #include #include @@ -58,7 +59,7 @@ QMatrix4x4 CameraHelper::calculateViewMatrix(QPoint mousePos, int zoom m_xRotation -= mouseMoveX; m_yRotation -= mouseMoveY; // Reset at 360 in x and limit to 0...90 in y - if (fabs(m_xRotation) >= 360) + if (qFabs(m_xRotation) >= 360) m_xRotation = 0; if (m_yRotation >= 90) { m_yRotation = 90; diff --git a/src/datavis3d/utils/objecthelper_p.h b/src/datavis3d/utils/objecthelper_p.h index 059b7ab4..34871567 100644 --- a/src/datavis3d/utils/objecthelper_p.h +++ b/src/datavis3d/utils/objecthelper_p.h @@ -69,8 +69,8 @@ class ObjectHelper QString m_objectFile; GLuint m_vertexbuffer; - GLuint m_uvbuffer; GLuint m_normalbuffer; + GLuint m_uvbuffer; GLuint m_elementbuffer; GLuint m_indexCount; diff --git a/src/datavis3d/utils/vertexindexer.cpp b/src/datavis3d/utils/vertexindexer.cpp index c54cbf8a..343e5a41 100644 --- a/src/datavis3d/utils/vertexindexer.cpp +++ b/src/datavis3d/utils/vertexindexer.cpp @@ -1,6 +1,7 @@ #include "vertexindexer_p.h" #include // for memcmp +#include #include @@ -11,7 +12,7 @@ int unique_vertices = 0; // Returns true if v1 can be considered equal to v2 bool VertexIndexer::is_near(float v1, float v2) { - return fabs(v1 - v2) < 0.01f; + return qFabs(v1 - v2) < 0.01f; } // Searches through all already-exported vertices -- cgit v1.2.3