summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/datavisualization/engine/abstract3drenderer.cpp2
-rw-r--r--src/datavisualization/engine/bars3drenderer.cpp14
-rw-r--r--src/datavisualization/engine/q3dcamera.cpp510
-rw-r--r--src/datavisualization/engine/q3dcamera.h37
-rw-r--r--src/datavisualization/engine/q3dcamera_p.h29
-rw-r--r--src/datavisualization/engine/q3dscene.cpp34
-rw-r--r--src/datavisualization/engine/q3dscene.h3
-rw-r--r--src/datavisualization/engine/q3dscene_p.h4
-rw-r--r--src/datavisualization/engine/scatter3drenderer.cpp8
-rw-r--r--src/datavisualization/engine/selectionpointer.cpp4
-rw-r--r--src/datavisualization/engine/surface3drenderer.cpp6
11 files changed, 267 insertions, 384 deletions
diff --git a/src/datavisualization/engine/abstract3drenderer.cpp b/src/datavisualization/engine/abstract3drenderer.cpp
index 7824000e..e3ec7c9a 100644
--- a/src/datavisualization/engine/abstract3drenderer.cpp
+++ b/src/datavisualization/engine/abstract3drenderer.cpp
@@ -188,7 +188,7 @@ void Abstract3DRenderer::updateScene(Q3DScene *scene)
scene->activeCamera()->d_ptr->updateViewMatrix(m_autoScaleAdjustment);
// Set light position (rotate light with activeCamera, a bit above it (as set in defaultLightPos))
- scene->setLightPositionRelativeToCamera(defaultLightPos);
+ scene->d_ptr->setLightPositionRelativeToCamera(defaultLightPos);
QPoint logicalPixelPosition = scene->selectionQueryPosition();
updateInputPosition(QPoint(logicalPixelPosition.x() * m_devicePixelRatio,
diff --git a/src/datavisualization/engine/bars3drenderer.cpp b/src/datavisualization/engine/bars3drenderer.cpp
index 664dbabd..7b610cd9 100644
--- a/src/datavisualization/engine/bars3drenderer.cpp
+++ b/src/datavisualization/engine/bars3drenderer.cpp
@@ -274,15 +274,15 @@ void Bars3DRenderer::updateSeries(const QList<QAbstract3DSeries *> &seriesList,
void Bars3DRenderer::updateScene(Q3DScene *scene)
{
if (m_hasNegativeValues)
- scene->activeCamera()->setMinYRotation(-90.0);
+ scene->activeCamera()->d_ptr->setMinYRotation(-90.0);
else
- scene->activeCamera()->setMinYRotation(0.0f);
+ scene->activeCamera()->d_ptr->setMinYRotation(0.0f);
if (m_hasHeightAdjustmentChanged) {
// Set initial camera position. Also update if height adjustment has changed.
- scene->activeCamera()->setBaseOrientation(cameraDistanceVector,
- zeroVector,
- upVector);
+ scene->activeCamera()->d_ptr->setBaseOrientation(cameraDistanceVector,
+ zeroVector,
+ upVector);
m_hasHeightAdjustmentChanged = false;
}
@@ -767,7 +767,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
projectionMatrix.perspective(45.0f, viewPortRatio, 0.1f, 100.0f);
// Get the view matrix
- QMatrix4x4 viewMatrix = activeCamera->viewMatrix();
+ QMatrix4x4 viewMatrix = activeCamera->d_ptr->viewMatrix();
// Calculate drawing order
// Draw order is reversed to optimize amount of drawing (ie. draw front objects first,
@@ -842,7 +842,7 @@ void Bars3DRenderer::drawScene(GLuint defaultFboHandle)
// Get the depth view matrix
// It may be possible to hack lightPos here if we want to make some tweaks to shadow
- QVector3D depthLightPos = activeCamera->calculatePositionRelativeToCamera(
+ QVector3D depthLightPos = activeCamera->d_ptr->calculatePositionRelativeToCamera(
zeroVector, 0.0f, 3.5f / m_autoScaleAdjustment);
depthViewMatrix.lookAt(depthLightPos, zeroVector, upVector);
diff --git a/src/datavisualization/engine/q3dcamera.cpp b/src/datavisualization/engine/q3dcamera.cpp
index 426fa51d..a3afd019 100644
--- a/src/datavisualization/engine/q3dcamera.cpp
+++ b/src/datavisualization/engine/q3dcamera.cpp
@@ -35,9 +35,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
* \since Qt Data Visualization 1.0
*
* Q3DCamera represents a basic orbit around centerpoint 3D camera that is used when rendering the
- * data visualization. The class offers simple methods for setting the orbit point in rotations,
- * but allows also setting the 4x4 view matrix directly in case a more customized camera behavior is
- * needed.
+ * data visualization. The class offers simple methods for rotating the camera around the origin
+ * and setting zoom level.
*/
/*!
@@ -85,9 +84,8 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
* \brief Representation of a camera in 3D space.
*
* Camera3D represents a basic orbit around centerpoint 3D camera that is used when rendering the
- * data visualization. The class offers simple methods for setting the orbit point in rotations,
- * but allows also setting the 4x4 view matrix directly in case a more customized camera behavior is
- * needed.
+ * data visualization. The type offers simple methods for rotating the camera around the origin
+ * and setting zoom level.
*
* For Camera3D enums, see \l Q3DCamera::CameraPreset
*/
@@ -107,74 +105,6 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
*/
/*!
- * \qmlproperty float Camera3D::minXRotation
- *
- * This property contains the current minimum X-rotation for the camera.
- * The full circle range is \c{[-180, 180]} and the minimum value is limited to \c -180.
- * Also the value can't be higher than the maximum, and is adjusted if necessary.
- *
- * \sa wrapXRotation, maxXRotation
- */
-
-/*!
- * \qmlproperty float Camera3D::minYRotation
- *
- * This property contains the current minimum Y-rotation for the camera.
- * The full Y angle range is \c{[-90, 90]} and the minimum value is limited to \c -90.
- * Also the value can't be higher than the maximum, and is adjusted if necessary.
- *
- * \sa wrapYRotation, maxYRotation
- */
-
-/*!
- * \qmlproperty float Camera3D::maxXRotation
- *
- * This property contains the current maximum X-rotation for the camera.
- * The full circle range is \c{[-180, 180]} and the maximum value is limited to \c 180.
- * Also the value can't be lower than the minimum, and is adjusted if necessary.
- *
- * \sa wrapXRotation, minXRotation
- */
-
-/*!
- * \qmlproperty float Camera3D::maxYRotation
- *
- * This property contains the current maximum Y-rotation for the camera.
- * The full Y angle range is \c{[-90, 90]} and the maximum value is limited to \c 90.
- * Also the value can't be lower than the minimum, and is adjusted if necessary.
- *
- * \sa wrapYRotation, minYRotation
- */
-
-/*!
- * \qmlmethod void Camera3D::setBaseOrientation(vector3d basePosition, vector3d target, vector3d baseUp)
- *
- * Sets the base values for the camera that are used when calculating the camera position using the
- * rotation values. The base position of the camera is defined by \a basePosition, expectation is
- * that the x and y values are 0. Look at target point is defined by \a target and the camera
- * rotates around it. Up direction for the camera is defined by \a baseUp, normally this is a
- * vector with only y value set to 1.
- */
-
-/*!
- * \qmlproperty matrix4x4 Camera3D::viewMatrix
- *
- * This property contains the view matrix used in the 3D calculations. When the default orbiting
- * camera behavior is sufficient, there is no need to touch this property. If the default
- * behavior is insufficient, the view matrix can be set directly.
- * \note When setting the view matrix directly remember to set viewMatrixAutoUpdateEnabled
- * property to \c false.
- */
-
-/*!
- * \qmlproperty bool Camera3D::viewMatrixAutoUpdateEnabled
- *
- * This property determines if view matrix is automatically updated each render cycle using the
- * current base orientation and rotations. If set to \c false, no automatic recalculation is done and
- * the view matrix can be set using the viewMatrix property.
- */
-
-/*!
* \qmlproperty Camera3D.CameraPreset Camera3D::cameraPreset
*
* This property contains the currently active camera preset, which is one of
@@ -272,8 +202,7 @@ void Q3DCamera::copyValuesFrom(const Q3DObject &source)
/*!
* \property Q3DCamera::xRotation
*
- * This property contains the X-rotation angle of the camera around the target point in degrees
- * starting from the current base position set by the setBaseOrientation() method.
+ * This property contains the X-rotation angle of the camera around the target point in degrees.
*/
float Q3DCamera::xRotation() const {
return d_ptr->m_xRotation;
@@ -300,8 +229,7 @@ void Q3DCamera::setXRotation(float rotation)
/*!
* \property Q3DCamera::yRotation
*
- * This property contains the Y-rotation angle of the camera around the target point in degrees
- * starting from the current base position set by the setBaseOrientation() method.
+ * This property contains the Y-rotation angle of the camera around the target point in degrees.
*/
float Q3DCamera::yRotation() const {
return d_ptr->m_yRotation;
@@ -326,192 +254,10 @@ void Q3DCamera::setYRotation(float rotation)
}
/*!
- * \property Q3DCamera::minXRotation
- *
- * This property contains the current minimum X-rotation for the camera.
- * The full circle range is \c{[-180, 180]} and the minimum value is limited to \c -180.
- * Also the value can't be higher than the maximum, and is adjusted if necessary.
- *
- * \sa wrapXRotation, maxXRotation
- */
-float Q3DCamera::minXRotation() const
-{
- return d_ptr->m_minXRotation;
-}
-
-void Q3DCamera::setMinXRotation(float minRotation)
-{
- minRotation = qBound(-180.0f, minRotation, 180.0f);
- if (minRotation > d_ptr->m_maxXRotation)
- minRotation = d_ptr->m_maxXRotation;
-
- if (d_ptr->m_minXRotation != minRotation) {
- d_ptr->m_minXRotation = minRotation;
- emit minXRotationChanged(minRotation);
-
- if (d_ptr->m_xRotation < d_ptr->m_minXRotation)
- setXRotation(d_ptr->m_xRotation);
- }
-}
-
-/*!
- * \property Q3DCamera::minYRotation
- *
- * This property contains the current minimum Y-rotation for the camera.
- * The full Y angle range is \c{[-90, 90]} and the minimum value is limited to \c -90.
- * Also the value can't be higher than the maximum, and is adjusted if necessary.
- *
- * \sa wrapYRotation, maxYRotation
- */
-float Q3DCamera::minYRotation() const
-{
- return d_ptr->m_minYRotation;
-}
-
-void Q3DCamera::setMinYRotation(float minRotation)
-{
- minRotation = qBound(-90.0f, minRotation, 90.0f);
- if (minRotation > d_ptr->m_maxYRotation)
- minRotation = d_ptr->m_maxYRotation;
-
- if (d_ptr->m_minYRotation != minRotation) {
- d_ptr->m_minYRotation = minRotation;
- emit minYRotationChanged(minRotation);
-
- if (d_ptr->m_yRotation < d_ptr->m_minYRotation)
- setYRotation(d_ptr->m_yRotation);
- }
-}
-
-/*!
- * \property Q3DCamera::maxXRotation
- *
- * This property contains the current maximum X-rotation for the camera.
- * The full circle range is \c{[-180, 180]} and the maximum value is limited to \c 180.
- * Also the value can't be lower than the minimum, and is adjusted if necessary.
- *
- * \sa wrapXRotation, minXRotation
- */
-float Q3DCamera::maxXRotation() const
-{
- return d_ptr->m_maxXRotation;
-}
-
-void Q3DCamera::setMaxXRotation(float maxRotation)
-{
- maxRotation = qBound(-180.0f, maxRotation, 180.0f);
-
- if (maxRotation < d_ptr->m_minXRotation)
- maxRotation = d_ptr->m_minXRotation;
-
- if (d_ptr->m_maxXRotation != maxRotation) {
- d_ptr->m_maxXRotation = maxRotation;
- emit maxXRotationChanged(maxRotation);
-
- if (d_ptr->m_xRotation > d_ptr->m_maxXRotation)
- setXRotation(d_ptr->m_xRotation);
- }
-}
-
-/*!
- * \property Q3DCamera::maxYRotation
- *
- * This property contains the current maximum Y-rotation for the camera.
- * The full Y angle range is \c{[-90, 90]} and the maximum value is limited to \c 90.
- * Also the value can't be lower than the minimum, and is adjusted if necessary.
- *
- * \sa wrapYRotation, minYRotation
- */
-float Q3DCamera::maxYRotation() const
-{
- return d_ptr->m_maxYRotation;
-}
-
-void Q3DCamera::setMaxYRotation(float maxRotation)
-{
- maxRotation = qBound(-90.0f, maxRotation, 90.0f);
-
- if (maxRotation < d_ptr->m_minYRotation)
- maxRotation = d_ptr->m_minYRotation;
-
- if (d_ptr->m_maxYRotation != maxRotation) {
- d_ptr->m_maxYRotation = maxRotation;
- emit maxYRotationChanged(maxRotation);
-
- if (d_ptr->m_yRotation > d_ptr->m_maxYRotation)
- setYRotation(d_ptr->m_yRotation);
- }
-}
-
-/*!
- * Sets the base values for the camera that are used when calculating the camera position using the
- * rotation values. The base position of the camera is defined by \a basePosition, expectation is
- * that the x and y values are 0. Look at target point is defined by \a target and the camera
- * rotates around it. Up direction for the camera is defined by \a baseUp, normally this is a
- * vector with only y value set to 1.
- */
-void Q3DCamera::setBaseOrientation(const QVector3D &basePosition,
- const QVector3D &target,
- const QVector3D &baseUp)
-{
- if (position() != basePosition
- || d_ptr->m_target != target
- || d_ptr->m_up != baseUp) {
- setPosition(basePosition);
- d_ptr->m_target = target;
- d_ptr->m_up = baseUp;
- setDirty(true);
- }
-}
-
-/*!
- * \property Q3DCamera::viewMatrix
- *
- * This property contains the view matrix used in the 3D calculations. When the default orbiting
- * camera behavior is sufficient, there is no need to touch this property. If the default
- * behavior is insufficient, the view matrix can be set directly.
- * \note When setting the view matrix directly remember to set viewMatrixAutoUpdateEnabled to
- * \c false.
- */
-QMatrix4x4 Q3DCamera::viewMatrix() const
-{
- return d_ptr->m_viewMatrix;
-}
-
-void Q3DCamera::setViewMatrix(const QMatrix4x4 &viewMatrix)
-{
- if (d_ptr->m_viewMatrix != viewMatrix) {
- d_ptr->m_viewMatrix = viewMatrix;
- setDirty(true);
- emit viewMatrixChanged(d_ptr->m_viewMatrix);
- }
-}
-
-/*!
- * \property Q3DCamera::viewMatrixAutoUpdateEnabled
- *
- * This property determines if view matrix is automatically updated each render cycle using the
- * current base orientation and rotations. If set to \c false, no automatic recalculation is done
- * and the view matrix can be set using the viewMatrix property.
- */
-bool Q3DCamera::isViewMatrixAutoUpdateEnabled() const
-{
- return d_ptr->m_isViewMatrixUpdateActive;
-}
-
-void Q3DCamera::setViewMatrixAutoUpdateEnabled(bool isEnabled)
-{
- d_ptr->m_isViewMatrixUpdateActive = isEnabled;
- emit viewMatrixAutoUpdateChanged(isEnabled);
-}
-
-/*!
* \property Q3DCamera::cameraPreset
*
* This property contains the currently active camera preset, if no preset is active the value
* is CameraPresetNone.
- * \note The base camera orientation set by setBaseOrientation() will affect
- * the presets as all calculations are based on those values.
*/
Q3DCamera::CameraPreset Q3DCamera::cameraPreset() const
{
@@ -674,42 +420,6 @@ void Q3DCamera::setZoomLevel(int zoomLevel)
}
/*!
- * Calculates and returns a position relative to the camera using the given parameters
- * and the current camera viewMatrix property.
- * The relative 3D offset to the current camera position is defined in \a relativePosition.
- * An optional fixed rotation of the calculated point around the data visualization area can be
- * given in \a fixedRotation. The rotation is given in degrees.
- * An optional \a distanceModifier modifies the distance of the calculated point from the data
- * visualization.
- * \return calculated position relative to this camera's position.
- */
-QVector3D Q3DCamera::calculatePositionRelativeToCamera(const QVector3D &relativePosition,
- float fixedRotation,
- float distanceModifier) const
-{
- // Move the position with camera
- GLfloat radiusFactor = cameraDistance * (1.5f + distanceModifier);
- GLfloat xAngle;
- GLfloat yAngle;
- if (!fixedRotation) {
- xAngle = qDegreesToRadians(d_ptr->m_xRotation);
- yAngle = qDegreesToRadians(d_ptr->m_yRotation);
- } else {
- xAngle = qDegreesToRadians(fixedRotation);
- yAngle = 0;
- }
- GLfloat radius = (radiusFactor + relativePosition.y()); // set radius to match the highest height of the position
- GLfloat zPos = radius * qCos(xAngle) * qCos(yAngle);
- GLfloat xPos = radius * qSin(xAngle) * qCos(yAngle);
- GLfloat yPos = (radiusFactor + relativePosition.y()) * qSin(yAngle);
-
- // Keep in the set position in relation to camera
- return QVector3D(-xPos + relativePosition.x(),
- yPos + relativePosition.y(),
- zPos + relativePosition.z());
-}
-
-/*!
* \property Q3DCamera::wrapXRotation
*
* This property determines the behavior of the minimum and maximum limits in the X-rotation.
@@ -809,34 +519,120 @@ void Q3DCameraPrivate::setYRotation(const float rotation)
}
}
-void Q3DCameraPrivate::setMinXRotation(const float rotation)
+/*!
+ * \internal
+ * This property contains the current minimum X-rotation for the camera.
+ * The full circle range is \c{[-180, 180]} and the minimum value is limited to \c -180.
+ * Also the value can't be higher than the maximum, and is adjusted if necessary.
+ *
+ * \sa wrapXRotation, maxXRotation
+ */
+float Q3DCameraPrivate::minXRotation() const
+{
+ return m_minXRotation;
+}
+
+void Q3DCameraPrivate::setMinXRotation(float minRotation)
{
- if (m_minXRotation != rotation) {
- m_minXRotation = rotation;
+ minRotation = qBound(-180.0f, minRotation, 180.0f);
+ if (minRotation > m_maxXRotation)
+ minRotation = m_maxXRotation;
+
+ if (m_minXRotation != minRotation) {
+ m_minXRotation = minRotation;
+ emit minXRotationChanged(minRotation);
+
+ if (m_xRotation < m_minXRotation)
+ setXRotation(m_xRotation);
q_ptr->setDirty(true);
}
}
-void Q3DCameraPrivate::setMinYRotation(const float rotation)
+/*!
+ * \internal
+ * This property contains the current minimum Y-rotation for the camera.
+ * The full Y angle range is \c{[-90, 90]} and the minimum value is limited to \c -90.
+ * Also the value can't be higher than the maximum, and is adjusted if necessary.
+ *
+ * \sa wrapYRotation, maxYRotation
+ */
+float Q3DCameraPrivate::minYRotation() const
+{
+ return m_minYRotation;
+}
+
+void Q3DCameraPrivate::setMinYRotation(float minRotation)
{
- if (m_minYRotation != rotation) {
- m_minYRotation = rotation;
+ minRotation = qBound(-90.0f, minRotation, 90.0f);
+ if (minRotation > m_maxYRotation)
+ minRotation = m_maxYRotation;
+
+ if (m_minYRotation != minRotation) {
+ m_minYRotation = minRotation;
+ emit minYRotationChanged(minRotation);
+
+ if (m_yRotation < m_minYRotation)
+ setYRotation(m_yRotation);
q_ptr->setDirty(true);
}
}
-void Q3DCameraPrivate::setMaxXRotation(const float rotation)
+/*!
+ * \internal
+ * This property contains the current maximum X-rotation for the camera.
+ * The full circle range is \c{[-180, 180]} and the maximum value is limited to \c 180.
+ * Also the value can't be lower than the minimum, and is adjusted if necessary.
+ *
+ * \sa wrapXRotation, minXRotation
+ */
+float Q3DCameraPrivate::maxXRotation() const
{
- if (m_maxXRotation != rotation) {
- m_maxXRotation = rotation;
+ return m_maxXRotation;
+}
+
+void Q3DCameraPrivate::setMaxXRotation(float maxRotation)
+{
+ maxRotation = qBound(-180.0f, maxRotation, 180.0f);
+
+ if (maxRotation < m_minXRotation)
+ maxRotation = m_minXRotation;
+
+ if (m_maxXRotation != maxRotation) {
+ m_maxXRotation = maxRotation;
+ emit maxXRotationChanged(maxRotation);
+
+ if (m_xRotation > m_maxXRotation)
+ setXRotation(m_xRotation);
q_ptr->setDirty(true);
}
}
-void Q3DCameraPrivate::setMaxYRotation(const float rotation)
+/*!
+ * \internal
+ * This property contains the current maximum Y-rotation for the camera.
+ * The full Y angle range is \c{[-90, 90]} and the maximum value is limited to \c 90.
+ * Also the value can't be lower than the minimum, and is adjusted if necessary.
+ *
+ * \sa wrapYRotation, minYRotation
+ */
+float Q3DCameraPrivate::maxYRotation() const
+{
+ return m_maxYRotation;
+}
+
+void Q3DCameraPrivate::setMaxYRotation(float maxRotation)
{
- if (m_maxYRotation != rotation) {
- m_maxYRotation = rotation;
+ maxRotation = qBound(-90.0f, maxRotation, 90.0f);
+
+ if (maxRotation < m_minYRotation)
+ maxRotation = m_minYRotation;
+
+ if (m_maxYRotation != maxRotation) {
+ m_maxYRotation = maxRotation;
+ emit maxYRotationChanged(maxRotation);
+
+ if (m_yRotation > m_maxYRotation)
+ setYRotation(m_yRotation);
q_ptr->setDirty(true);
}
}
@@ -866,7 +662,103 @@ void Q3DCameraPrivate::updateViewMatrix(float zoomAdjustment)
// Compensate for translation (if d_ptr->m_target is off origin)
viewMatrix.translate(-m_target.x(), -m_target.y(), -m_target.z());
- q_ptr->setViewMatrix(viewMatrix);
+ setViewMatrix(viewMatrix);
+}
+
+/*!
+ * \internal
+ * This property contains the view matrix used in the 3D calculations. When the default orbiting
+ * camera behavior is sufficient, there is no need to touch this property. If the default
+ * behavior is insufficient, the view matrix can be set directly.
+ * \note When setting the view matrix directly remember to set viewMatrixAutoUpdateEnabled to
+ * \c false.
+ */
+QMatrix4x4 Q3DCameraPrivate::viewMatrix() const
+{
+ return m_viewMatrix;
+}
+
+void Q3DCameraPrivate::setViewMatrix(const QMatrix4x4 &viewMatrix)
+{
+ if (m_viewMatrix != viewMatrix) {
+ m_viewMatrix = viewMatrix;
+ q_ptr->setDirty(true);
+ emit viewMatrixChanged(m_viewMatrix);
+ }
+}
+
+/*!
+ * \internal
+ * This property determines if view matrix is automatically updated each render cycle using the
+ * current base orientation and rotations. If set to \c false, no automatic recalculation is done
+ * and the view matrix can be set using the viewMatrix property.
+ */
+bool Q3DCameraPrivate::isViewMatrixAutoUpdateEnabled() const
+{
+ return m_isViewMatrixUpdateActive;
+}
+
+void Q3DCameraPrivate::setViewMatrixAutoUpdateEnabled(bool isEnabled)
+{
+ m_isViewMatrixUpdateActive = isEnabled;
+ emit viewMatrixAutoUpdateChanged(isEnabled);
+}
+
+/*!
+ * \internal
+ * Sets the base values for the camera that are used when calculating the camera position using the
+ * rotation values. The base position of the camera is defined by \a basePosition, expectation is
+ * that the x and y values are 0. Look at target point is defined by \a target and the camera
+ * rotates around it. Up direction for the camera is defined by \a baseUp, normally this is a
+ * vector with only y value set to 1.
+ */
+void Q3DCameraPrivate::setBaseOrientation(const QVector3D &basePosition,
+ const QVector3D &target,
+ const QVector3D &baseUp)
+{
+ if (q_ptr->position() != basePosition || m_target != target || m_up != baseUp) {
+ q_ptr->setPosition(basePosition);
+ m_target = target;
+ m_up = baseUp;
+ q_ptr->setDirty(true);
+ }
+}
+
+/*!
+ * \internal
+ * Calculates and returns a position relative to the camera using the given parameters
+ * and the current camera viewMatrix property.
+ * The relative 3D offset to the current camera position is defined in \a relativePosition.
+ * An optional fixed rotation of the calculated point around the data visualization area can be
+ * given in \a fixedRotation. The rotation is given in degrees.
+ * An optional \a distanceModifier modifies the distance of the calculated point from the data
+ * visualization.
+ * \return calculated position relative to this camera's position.
+ */
+QVector3D Q3DCameraPrivate::calculatePositionRelativeToCamera(const QVector3D &relativePosition,
+ float fixedRotation,
+ float distanceModifier) const
+{
+ // Move the position with camera
+ GLfloat radiusFactor = cameraDistance * (1.5f + distanceModifier);
+ GLfloat xAngle;
+ GLfloat yAngle;
+ if (!fixedRotation) {
+ xAngle = qDegreesToRadians(m_xRotation);
+ yAngle = qDegreesToRadians(m_yRotation);
+ } else {
+ xAngle = qDegreesToRadians(fixedRotation);
+ yAngle = 0;
+ }
+ GLfloat radius = (radiusFactor + relativePosition.y()); // set radius to match the highest height of the position
+ GLfloat zPos = radius * qCos(xAngle) * qCos(yAngle);
+ GLfloat xPos = radius * qSin(xAngle) * qCos(yAngle);
+ GLfloat yPos = (radiusFactor + relativePosition.y()) * qSin(yAngle);
+
+ // Keep in the set position in relation to camera
+ return QVector3D(-xPos + relativePosition.x(),
+ yPos + relativePosition.y(),
+ zPos + relativePosition.z());
}
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/engine/q3dcamera.h b/src/datavisualization/engine/q3dcamera.h
index 1a3a3284..44aff452 100644
--- a/src/datavisualization/engine/q3dcamera.h
+++ b/src/datavisualization/engine/q3dcamera.h
@@ -35,14 +35,8 @@ class QT_DATAVISUALIZATION_EXPORT Q3DCamera : public Q3DObject
Q_ENUMS(CameraPreset)
Q_PROPERTY(float xRotation READ xRotation WRITE setXRotation NOTIFY xRotationChanged)
Q_PROPERTY(float yRotation READ yRotation WRITE setYRotation NOTIFY yRotationChanged)
- Q_PROPERTY(float minXRotation READ minXRotation NOTIFY minXRotationChanged)
- Q_PROPERTY(float minYRotation READ minYRotation NOTIFY minYRotationChanged)
- Q_PROPERTY(float maxXRotation READ maxXRotation NOTIFY maxXRotationChanged)
- Q_PROPERTY(float maxYRotation READ maxYRotation NOTIFY maxYRotationChanged)
Q_PROPERTY(int zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged)
- Q_PROPERTY(QMatrix4x4 viewMatrix READ viewMatrix WRITE setViewMatrix NOTIFY viewMatrixChanged)
Q_PROPERTY(CameraPreset cameraPreset READ cameraPreset WRITE setCameraPreset NOTIFY cameraPresetChanged)
- Q_PROPERTY(bool viewMatrixAutoUpdateEnabled READ isViewMatrixAutoUpdateEnabled WRITE setViewMatrixAutoUpdateEnabled NOTIFY viewMatrixAutoUpdateChanged)
Q_PROPERTY(bool wrapXRotation READ wrapXRotation WRITE setWrapXRotation NOTIFY wrapXRotationChanged)
Q_PROPERTY(bool wrapYRotation READ wrapYRotation WRITE setWrapYRotation NOTIFY wrapYRotationChanged)
@@ -84,12 +78,6 @@ public:
float yRotation() const;
void setYRotation(float rotation);
- float minXRotation() const;
- float maxXRotation() const;
-
- float minYRotation() const;
- float maxYRotation() const;
-
bool wrapXRotation() const;
void setWrapXRotation(bool isEnabled);
@@ -98,48 +86,23 @@ public:
virtual void copyValuesFrom(const Q3DObject &source);
- QMatrix4x4 viewMatrix() const;
- void setViewMatrix(const QMatrix4x4 &viewMatrix);
-
- bool isViewMatrixAutoUpdateEnabled() const;
- void setViewMatrixAutoUpdateEnabled(bool isEnabled);
-
CameraPreset cameraPreset() const;
void setCameraPreset(CameraPreset preset);
int zoomLevel() const;
void setZoomLevel(int zoomLevel);
- Q_INVOKABLE void setBaseOrientation(const QVector3D &defaultPosition,
- const QVector3D &defaultTarget,
- const QVector3D &defaultUp);
-
- QVector3D calculatePositionRelativeToCamera(const QVector3D &relativePosition,
- float fixedRotation,
- float distanceModifier) const;
void setCameraPosition(float horizontal, float vertical, float distance = 100.0f);
signals:
void xRotationChanged(float rotation);
void yRotationChanged(float rotation);
- void minXRotationChanged(float rotation);
- void minYRotationChanged(float rotation);
- void maxXRotationChanged(float rotation);
- void maxYRotationChanged(float rotation);
void zoomLevelChanged(int zoomLevel);
- void viewMatrixChanged(QMatrix4x4 viewMatrix);
void cameraPresetChanged(CameraPreset preset);
- void viewMatrixAutoUpdateChanged(bool enabled);
void wrapXRotationChanged(bool isEnabled);
void wrapYRotationChanged(bool isEnabled);
private:
- void setMinXRotation(float rotation);
- void setMinYRotation(float rotation);
- void setMaxXRotation(float rotation);
- void setMaxYRotation(float rotation);
-
-private:
QScopedPointer<Q3DCameraPrivate> d_ptr;
Q_DISABLE_COPY(Q3DCamera)
diff --git a/src/datavisualization/engine/q3dcamera_p.h b/src/datavisualization/engine/q3dcamera_p.h
index b55010c8..1112c87e 100644
--- a/src/datavisualization/engine/q3dcamera_p.h
+++ b/src/datavisualization/engine/q3dcamera_p.h
@@ -36,8 +36,9 @@ QT_BEGIN_NAMESPACE_DATAVISUALIZATION
class Q3DCamera;
-class Q3DCameraPrivate
+class Q3DCameraPrivate : public QObject
{
+ Q_OBJECT
public:
Q3DCameraPrivate(Q3DCamera *q);
~Q3DCameraPrivate();
@@ -47,12 +48,38 @@ public:
void setXRotation(float rotation);
void setYRotation(float rotation);
void setMinXRotation(float rotation);
+ float minXRotation() const;
void setMinYRotation(float rotation);
+ float minYRotation() const;
void setMaxXRotation(float rotation);
+ float maxXRotation() const;
void setMaxYRotation(float rotation);
+ float maxYRotation() const;
void updateViewMatrix(float zoomAdjustment);
+ QMatrix4x4 viewMatrix() const;
+ void setViewMatrix(const QMatrix4x4 &viewMatrix);
+
+ bool isViewMatrixAutoUpdateEnabled() const;
+ void setViewMatrixAutoUpdateEnabled(bool isEnabled);
+
+ void setBaseOrientation(const QVector3D &defaultPosition,
+ const QVector3D &defaultTarget,
+ const QVector3D &defaultUp);
+
+ QVector3D calculatePositionRelativeToCamera(const QVector3D &relativePosition,
+ float fixedRotation,
+ float distanceModifier) const;
+
+signals:
+ void minXRotationChanged(float rotation);
+ void minYRotationChanged(float rotation);
+ void maxXRotationChanged(float rotation);
+ void maxYRotationChanged(float rotation);
+ void viewMatrixChanged(QMatrix4x4 viewMatrix);
+ void viewMatrixAutoUpdateChanged(bool enabled);
+
public:
Q3DCamera *q_ptr;
diff --git a/src/datavisualization/engine/q3dscene.cpp b/src/datavisualization/engine/q3dscene.cpp
index 6ee4e275..f4467f22 100644
--- a/src/datavisualization/engine/q3dscene.cpp
+++ b/src/datavisualization/engine/q3dscene.cpp
@@ -438,23 +438,6 @@ void Q3DScene::setDevicePixelRatio(float pixelRatio)
}
}
-/*!
- * Calculates and sets the light position relative to the currently active camera using the given
- * parameters.
- * The relative 3D offset to the current camera position is defined in \a relativePosition.
- * Optional \a fixedRotation fixes the light rotation around the data visualization area to the
- * given value in degrees.
- * Optional \a distanceModifier modifies the distance of the light from the data visualization.
- */
-void Q3DScene::setLightPositionRelativeToCamera(const QVector3D &relativePosition,
- float fixedRotation, float distanceModifier)
-{
- d_ptr->m_light->setPosition(
- d_ptr->m_camera->calculatePositionRelativeToCamera(relativePosition,
- fixedRotation,
- distanceModifier));
-}
-
Q3DScenePrivate::Q3DScenePrivate(Q3DScene *q) :
QObject(0),
q_ptr(q),
@@ -650,4 +633,21 @@ QRect Q3DScenePrivate::glSecondarySubViewport()
return m_glSecondarySubViewport;
}
+/*!
+ * \internal
+ * Calculates and sets the light position relative to the currently active camera using the given
+ * parameters.
+ * The relative 3D offset to the current camera position is defined in \a relativePosition.
+ * Optional \a fixedRotation fixes the light rotation around the data visualization area to the
+ * given value in degrees.
+ * Optional \a distanceModifier modifies the distance of the light from the data visualization.
+ */
+void Q3DScenePrivate::setLightPositionRelativeToCamera(const QVector3D &relativePosition,
+ float fixedRotation, float distanceModifier)
+{
+ m_light->setPosition(m_camera->d_ptr->calculatePositionRelativeToCamera(relativePosition,
+ fixedRotation,
+ distanceModifier));
+}
+
QT_END_NAMESPACE_DATAVISUALIZATION
diff --git a/src/datavisualization/engine/q3dscene.h b/src/datavisualization/engine/q3dscene.h
index 61a18c9d..9c122c2a 100644
--- a/src/datavisualization/engine/q3dscene.h
+++ b/src/datavisualization/engine/q3dscene.h
@@ -77,9 +77,6 @@ public:
float devicePixelRatio() const;
void setDevicePixelRatio(float pixelRatio);
- Q_INVOKABLE void setLightPositionRelativeToCamera(const QVector3D &relativePosition,
- float fixedRotation = 0.0f,
- float distanceModifier = 0.0f);
signals:
void viewportChanged(QRect viewport);
void primarySubViewportChanged(QRect subViewport);
diff --git a/src/datavisualization/engine/q3dscene_p.h b/src/datavisualization/engine/q3dscene_p.h
index be0d3dc5..b2948c06 100644
--- a/src/datavisualization/engine/q3dscene_p.h
+++ b/src/datavisualization/engine/q3dscene_p.h
@@ -86,6 +86,10 @@ public:
QRect glPrimarySubViewport();
QRect glSecondarySubViewport();
+ void setLightPositionRelativeToCamera(const QVector3D &relativePosition,
+ float fixedRotation = 0.0f,
+ float distanceModifier = 0.0f);
+
signals:
void needRender();
diff --git a/src/datavisualization/engine/scatter3drenderer.cpp b/src/datavisualization/engine/scatter3drenderer.cpp
index cf9dbefe..92c5a619 100644
--- a/src/datavisualization/engine/scatter3drenderer.cpp
+++ b/src/datavisualization/engine/scatter3drenderer.cpp
@@ -225,11 +225,11 @@ void Scatter3DRenderer::updateData()
void Scatter3DRenderer::updateScene(Q3DScene *scene)
{
- scene->activeCamera()->setMinYRotation(-90.0f);
+ scene->activeCamera()->d_ptr->setMinYRotation(-90.0f);
if (m_hasHeightAdjustmentChanged) {
// Set initial camera position. Also update if height adjustment has changed.
- scene->activeCamera()->setBaseOrientation(cameraDistanceVector, zeroVector, upVector);
+ scene->activeCamera()->d_ptr->setBaseOrientation(cameraDistanceVector, zeroVector, upVector);
m_hasHeightAdjustmentChanged = false;
}
@@ -273,7 +273,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
projectionMatrix.perspective(45.0f, viewPortRatio, 0.1f, 100.0f);
// Calculate view matrix
- QMatrix4x4 viewMatrix = activeCamera->viewMatrix();
+ QMatrix4x4 viewMatrix = activeCamera->d_ptr->viewMatrix();
QMatrix4x4 projectionViewMatrix = projectionMatrix * viewMatrix;
int seriesCount = m_visibleSeriesList.size();
@@ -354,7 +354,7 @@ void Scatter3DRenderer::drawScene(const GLuint defaultFboHandle)
// Get the depth view matrix
// It may be possible to hack lightPos here if we want to make some tweaks to shadow
- QVector3D depthLightPos = activeCamera->calculatePositionRelativeToCamera(
+ QVector3D depthLightPos = activeCamera->d_ptr->calculatePositionRelativeToCamera(
zeroVector, 0.0f, 2.5f / m_autoScaleAdjustment);
depthViewMatrix.lookAt(depthLightPos, zeroVector, upVector);
// Set the depth projection matrix
diff --git a/src/datavisualization/engine/selectionpointer.cpp b/src/datavisualization/engine/selectionpointer.cpp
index 9f3f65bc..fc1d7669 100644
--- a/src/datavisualization/engine/selectionpointer.cpp
+++ b/src/datavisualization/engine/selectionpointer.cpp
@@ -21,7 +21,7 @@
#include "shaderhelper_p.h"
#include "objecthelper_p.h"
#include "texturehelper_p.h"
-#include "q3dcamera.h"
+#include "q3dcamera_p.h"
#include "drawer_p.h"
#include "utils_p.h"
#include "q3dlight.h"
@@ -97,7 +97,7 @@ void SelectionPointer::render(GLuint defaultFboHandle)
-sliceUnitsScaled, sliceUnitsScaled,
-1.0f, 4.0f);
} else {
- viewMatrix = camera->viewMatrix();
+ viewMatrix = camera->d_ptr->viewMatrix();
projectionMatrix.perspective(45.0f, (GLfloat)m_mainViewPort.width()
/ (GLfloat)m_mainViewPort.height(), 0.1f, 100.0f);
}
diff --git a/src/datavisualization/engine/surface3drenderer.cpp b/src/datavisualization/engine/surface3drenderer.cpp
index e23af8d4..4dbd48ba 100644
--- a/src/datavisualization/engine/surface3drenderer.cpp
+++ b/src/datavisualization/engine/surface3drenderer.cpp
@@ -535,7 +535,7 @@ void Surface3DRenderer::updateScene(Q3DScene *scene)
// Set initial camera position
// X must be 0 for rotation to work - we can use "setCameraRotation" for setting it later
if (m_hasHeightAdjustmentChanged) {
- scene->activeCamera()->setBaseOrientation(cameraDistanceVector, zeroVector, upVector);
+ scene->activeCamera()->d_ptr->setBaseOrientation(cameraDistanceVector, zeroVector, upVector);
// For now this is used just to make things once. Proper use will come
m_hasHeightAdjustmentChanged = false;
}
@@ -857,7 +857,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
/ (GLfloat)m_primarySubViewport.height(), 0.1f, 100.0f);
// Calculate view matrix
- QMatrix4x4 viewMatrix = m_cachedScene->activeCamera()->viewMatrix();
+ QMatrix4x4 viewMatrix = m_cachedScene->activeCamera()->d_ptr->viewMatrix();
QMatrix4x4 projectionViewMatrix = projectionMatrix * viewMatrix;
@@ -914,7 +914,7 @@ void Surface3DRenderer::drawScene(GLuint defaultFboHandle)
// Get the depth view matrix
// It may be possible to hack lightPos here if we want to make some tweaks to shadow
- QVector3D depthLightPos = m_cachedScene->activeCamera()->calculatePositionRelativeToCamera(
+ QVector3D depthLightPos = m_cachedScene->activeCamera()->d_ptr->calculatePositionRelativeToCamera(
zeroVector, 0.0f, 3.5f / m_autoScaleAdjustment);
depthViewMatrix.lookAt(depthLightPos, zeroVector, upVector);