summaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorVolker Enderlein <volker.enderlein@ifm-chemnitz.de>2020-01-09 15:07:50 +0100
committerVolker Enderlein <volker.enderlein@ifm-chemnitz.de>2020-01-10 15:59:16 +0100
commit709b3039b74f9afca135b9416253164fc0e8d853 (patch)
tree1b1ea9575ce47cff2076e9ccc0877e67207aa32d /src/render
parent56009681f926a3e27258c4355c5d52e9f776d508 (diff)
Add viewAll support for orthographic projection mode
- viewAll was not supported for orthographic projection mode - Fix viewAll for perspective projection mode - the bounding volume was not fully visible in the render view after applying viewAll Task-number: QTBUG-80078 Change-Id: Ibf7486e41b02997b6b7426bde9a86b2d6c0d2e06 Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'src/render')
-rw-r--r--src/render/frontend/qcamera.cpp32
-rw-r--r--src/render/frontend/qcameralens.cpp4
2 files changed, 26 insertions, 10 deletions
diff --git a/src/render/frontend/qcamera.cpp b/src/render/frontend/qcamera.cpp
index b0fd16182..4d4e5bf4d 100644
--- a/src/render/frontend/qcamera.cpp
+++ b/src/render/frontend/qcamera.cpp
@@ -227,7 +227,7 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit)
* Rotates and moves the camera so that it's viewCenter is the center of the scene's bounding volume
* and the entire scene fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
@@ -237,7 +237,7 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit)
* Rotates and moves the camera so that it's viewCenter is the center of the entity's bounding volume
* and the entire \a entity fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
@@ -247,7 +247,7 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit)
* Rotates and moves the camera so that it's viewCenter is \a center
* and a sphere of \a radius fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
@@ -823,7 +823,7 @@ void QCamera::rotateAboutViewCenter(const QQuaternion& q)
* Rotates and moves the camera so that it's viewCenter is the center of the scene's bounding volume
* and the entire scene fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
void QCamera::viewAll()
@@ -836,15 +836,31 @@ void QCamera::viewAll()
* Rotates and moves the camera so that it's viewCenter is \a center
* and a sphere of \a radius fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa Qt3D.Render::Camera::projectionType
*/
void QCamera::viewSphere(const QVector3D &center, float radius)
{
Q_D(QCamera);
- if (d->m_lens->projectionType() != QCameraLens::PerspectiveProjection || radius <= 0.f)
+ if ((d->m_lens->projectionType() != QCameraLens::PerspectiveProjection &&
+ d->m_lens->projectionType() != QCameraLens::OrthographicProjection) ||
+ radius <= 0.f)
return;
- double dist = radius / std::tan(qDegreesToRadians(d->m_lens->fieldOfView()) / 2.0f);
+
+ // Ensure the sphere fits in the view port even if aspect ratio < 1 (i.e. width < height)
+ float height = (1.05f * radius) / (d->m_lens->aspectRatio() < 1.0f ? d->m_lens->aspectRatio() : 1.0f);
+ float dist = 1.0f;
+ if (d->m_lens->projectionType() == QCameraLens::PerspectiveProjection) {
+ dist = height / std::sin(qDegreesToRadians(d->m_lens->fieldOfView()) / 2.0f);
+ }
+ else if (d->m_lens->projectionType() == QCameraLens::OrthographicProjection) {
+ d->m_lens->setOrthographicProjection(-height * d->m_lens->aspectRatio(), height * d->m_lens->aspectRatio(), -height, height,
+ nearPlane(), farPlane());
+ dist = height / std::sin(qDegreesToRadians(d->m_lens->fieldOfView()) / 2.0f);
+ }
+ else {
+ dist = (d->m_viewCenter - d->m_position).length();
+ }
QVector3D dir = (d->m_viewCenter - d->m_position).normalized();
QVector3D newPos = center - (dir * dist);
setViewCenter(center);
@@ -855,7 +871,7 @@ void QCamera::viewSphere(const QVector3D &center, float radius)
* Rotates and moves the camera so that it's viewCenter is the center of the
* \a {entity}'s bounding volume and the entire entity fits in the view port.
*
- * \note Only works if the lens is in perspective projection mode.
+ * \note Only works if the lens is in perspective or orthographic projection mode.
* \sa {Qt3D.Render::Camera::projectionType}{Camera.projectionType}
*/
void QCamera::viewEntity(Qt3DCore::QEntity *entity)
diff --git a/src/render/frontend/qcameralens.cpp b/src/render/frontend/qcameralens.cpp
index cf30b714a..868ee9abf 100644
--- a/src/render/frontend/qcameralens.cpp
+++ b/src/render/frontend/qcameralens.cpp
@@ -232,7 +232,7 @@ QCameraLensPrivate::QCameraLensPrivate()
void QCameraLens::viewAll(Qt3DCore::QNodeId cameraId)
{
Q_D(QCameraLens);
- if (d->m_projectionType == PerspectiveProjection) {
+ if (d->m_projectionType == PerspectiveProjection || d->m_projectionType == OrthographicProjection) {
QVariant v;
v.setValue(cameraId);
d->m_pendingViewAllCommand = {QLatin1String("QueryRootBoundingVolume"),
@@ -245,7 +245,7 @@ void QCameraLens::viewAll(Qt3DCore::QNodeId cameraId)
void QCameraLens::viewEntity(Qt3DCore::QNodeId entityId, Qt3DCore::QNodeId cameraId)
{
Q_D(QCameraLens);
- if (d->m_projectionType == PerspectiveProjection) {
+ if (d->m_projectionType == PerspectiveProjection || d->m_projectionType == OrthographicProjection) {
QVector<Qt3DCore::QNodeId> ids = {entityId, cameraId};
QVariant v;
v.setValue(ids);