diff options
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) |