summaryrefslogtreecommitdiffstats
path: root/src/datavis3d
diff options
context:
space:
mode:
authorTomi Korpipää <tomi.korpipaa@digia.com>2013-03-26 07:29:20 +0200
committerTomi Korpipää <tomi.korpipaa@digia.com>2013-03-26 07:29:20 +0200
commita52b87c191dcb2af72b28cdc952d209a4ec403cc (patch)
tree6b03b92c4121fff223a91ebdabc3b5913a9a1d12 /src/datavis3d
parent8865e64770ac823e78c7adf0a8ae3b15120b489e (diff)
Added API for preset camera positions
Added utilization of presets to example Made some mac fixes
Diffstat (limited to 'src/datavis3d')
-rw-r--r--src/datavis3d/engine/q3dbars.cpp103
-rw-r--r--src/datavis3d/engine/q3dbars.h33
-rw-r--r--src/datavis3d/utils/camerahelper.cpp3
-rw-r--r--src/datavis3d/utils/objecthelper_p.h2
-rw-r--r--src/datavis3d/utils/vertexindexer.cpp3
5 files changed, 139 insertions, 5 deletions
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 <qmath.h>
#include <QMatrix4x4>
#include <QVector3D>
@@ -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 <string.h> // for memcmp
+#include <qmath.h>
#include <QDebug>
@@ -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