diff options
author | Kari Oikarinen <kari.oikarinen@qt.io> | 2020-01-15 19:09:24 +0200 |
---|---|---|
committer | Kari Oikarinen <kari.oikarinen@qt.io> | 2020-01-15 19:09:24 +0200 |
commit | 5aedae5aa9251e1216d7bc1652cb1f451dd047c1 (patch) | |
tree | 1e3c00ccac6cb4082d8bd3e52f047f8cbc058b61 /src/render/frontend/qcamera.cpp | |
parent | 532e108a3abf56aa0ef709af5049ce3b2161ed84 (diff) | |
parent | df5a63b059956e8a717db9110327cc86612cc934 (diff) |
Merge 5.14 into 5.14.1v5.14.1
Change-Id: Ia93046662955494eccd3f4da80f015fe5148b026
Diffstat (limited to 'src/render/frontend/qcamera.cpp')
-rw-r--r-- | src/render/frontend/qcamera.cpp | 32 |
1 files changed, 24 insertions, 8 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 ¢er, 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 ¢er, 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) |