diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-07-16 03:01:10 +0200 |
---|---|---|
committer | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-07-16 03:01:16 +0200 |
commit | bd09583403b27dedb3d6a7c7c737b0c1a49432e1 (patch) | |
tree | d0a54a8cafacdef71176c1be37356bdb5b5d33a7 | |
parent | eacf5d4302aa161cf146df68bf18bb4093b13574 (diff) | |
parent | 8b74455c1fb52852b3eb2401385d28cd0f4e9a6f (diff) |
Merge "Merge remote-tracking branch 'origin/5.12' into 5.13"
-rw-r--r-- | src/animation/backend/animationutils.cpp | 37 | ||||
-rw-r--r-- | src/animation/backend/fcurve.cpp | 11 | ||||
-rw-r--r-- | src/animation/backend/fcurve_p.h | 2 | ||||
-rw-r--r-- | src/doc/src/qmlextramaterials.qdoc | 20 | ||||
-rw-r--r-- | src/extras/defaults/qdiffusemapmaterial.cpp | 3 | ||||
-rw-r--r-- | src/extras/defaults/qdiffusespecularmapmaterial.cpp | 4 | ||||
-rw-r--r-- | src/extras/defaults/qdiffusespecularmaterial.cpp | 8 | ||||
-rw-r--r-- | src/extras/defaults/qmetalroughmaterial.cpp | 8 | ||||
-rw-r--r-- | src/extras/defaults/qnormaldiffusemapmaterial.cpp | 4 | ||||
-rw-r--r-- | src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp | 4 | ||||
-rw-r--r-- | src/render/backend/managers.cpp | 6 | ||||
-rw-r--r-- | src/render/backend/managers_p.h | 1 | ||||
-rw-r--r-- | src/render/framegraph/qclearbuffers.cpp | 2 | ||||
-rw-r--r-- | src/render/frontend/qcamera.cpp | 103 | ||||
-rw-r--r-- | src/render/geometry/joint.cpp | 1 | ||||
-rw-r--r-- | src/render/raycasting/qray3d.cpp | 8 | ||||
-rw-r--r-- | tests/auto/render/qray3d/tst_qray3d.cpp | 36 |
17 files changed, 208 insertions, 50 deletions
diff --git a/src/animation/backend/animationutils.cpp b/src/animation/backend/animationutils.cpp index 29de69df6..92e614236 100644 --- a/src/animation/backend/animationutils.cpp +++ b/src/animation/backend/animationutils.cpp @@ -55,6 +55,10 @@ QT_BEGIN_NAMESPACE +namespace { +const auto slerpThreshold = 0.01f; +} + namespace Qt3DAnimation { namespace Animation { @@ -270,17 +274,38 @@ ClipResults evaluateClipAtLocalTime(AnimationClip *clip, float localTime) const int lowerKeyframeBound = channel.channelComponents[0].fcurve.lowerKeyframeBound(localTime); const auto lowerQuat = quaternionFromChannel(lowerKeyframeBound); const auto higherQuat = quaternionFromChannel(lowerKeyframeBound + 1); - const float omega = std::acos(qBound(-1.0f, QQuaternion::dotProduct(lowerQuat, higherQuat), 1.0f)); - - if (qFuzzyIsNull(omega)) { - // If the two keyframe quaternions are equal, just return the first one as the interpolated value. + auto cosHalfTheta = QQuaternion::dotProduct(lowerQuat, higherQuat); + // If the two keyframe quaternions are equal, just return the first one as the interpolated value. + if (std::abs(cosHalfTheta) >= 1.0f) { channelResults[i++] = lowerQuat.scalar(); channelResults[i++] = lowerQuat.x(); channelResults[i++] = lowerQuat.y(); channelResults[i++] = lowerQuat.z(); } else { - for (const auto &channelComponent : qAsConst(channel.channelComponents)) - channelResults[i++] = channelComponent.fcurve.evaluateAtTimeAsSlerp(localTime, lowerKeyframeBound, omega); + const auto sinHalfTheta = std::sqrt(1.0f - std::pow(cosHalfTheta,2.0f)); + if (std::abs(sinHalfTheta) < ::slerpThreshold) { + auto initial_i = i; + for (const auto &channelComponent : qAsConst(channel.channelComponents)) + channelResults[i++] = channelComponent.fcurve.evaluateAtTime(localTime, lowerKeyframeBound); + + // Normalize the resulting quaternion + QQuaternion quat{channelResults[initial_i], channelResults[initial_i+1], channelResults[initial_i+2], channelResults[initial_i+3]}; + quat.normalize(); + channelResults[initial_i+0] = quat.scalar(); + channelResults[initial_i+1] = quat.x(); + channelResults[initial_i+2] = quat.y(); + channelResults[initial_i+3] = quat.z(); + } else { + const auto reverseQ1 = cosHalfTheta < 0 ? -1.0f : 1.0f; + cosHalfTheta *= reverseQ1; + const auto halfTheta = std::acos(cosHalfTheta); + for (const auto &channelComponent : qAsConst(channel.channelComponents)) + channelResults[i++] = channelComponent.fcurve.evaluateAtTimeAsSlerp(localTime, + lowerKeyframeBound, + halfTheta, + sinHalfTheta, + reverseQ1); + } } } } diff --git a/src/animation/backend/fcurve.cpp b/src/animation/backend/fcurve.cpp index 490866d54..18f1f427e 100644 --- a/src/animation/backend/fcurve.cpp +++ b/src/animation/backend/fcurve.cpp @@ -97,7 +97,7 @@ float FCurve::evaluateAtTime(float localTime, int lowerBound) const return m_keyframes.first().value; } -float FCurve::evaluateAtTimeAsSlerp(float localTime, int lowerBound, float omega) const +float FCurve::evaluateAtTimeAsSlerp(float localTime, int lowerBound, float halfTheta, float sinHalfTheta, float reverseQ1) const { // TODO: Implement extrapolation beyond first/last keyframes if (localTime < m_localTimes.first()) @@ -119,10 +119,11 @@ float FCurve::evaluateAtTimeAsSlerp(float localTime, int lowerBound, float omega return keyframe0.value; case QKeyFrame::LinearInterpolation: if (localTime >= t0 && localTime <= t1 && t1 > t0) { - const float t = (localTime - t0) / (t1 - t0); - const float div = 1.0f / std::sin(omega); - return std::sin((1 - t) * omega) * div * keyframe0.value + - std::sin(t * omega) * div * keyframe1.value; + const auto t = (localTime - t0) / (t1 - t0); + + const auto A = std::sin((1.0f-t) * halfTheta) / sinHalfTheta; + const auto B = std::sin(t * halfTheta) / sinHalfTheta; + return A * keyframe0.value + reverseQ1 * B * keyframe1.value; } break; case QKeyFrame::BezierInterpolation: diff --git a/src/animation/backend/fcurve_p.h b/src/animation/backend/fcurve_p.h index 337eb615d..935db5922 100644 --- a/src/animation/backend/fcurve_p.h +++ b/src/animation/backend/fcurve_p.h @@ -84,7 +84,7 @@ public: float evaluateAtTime(float localTime) const; float evaluateAtTime(float localTime, int lowerBound) const; - float evaluateAtTimeAsSlerp(float localTime, int lowerBound, float omega) const; + float evaluateAtTimeAsSlerp(float localTime, int lowerBound, float halfTheta, float sinHalfTheta, float reverseQ1) const; int lowerKeyframeBound(float localTime) const; void read(const QJsonObject &json); diff --git a/src/doc/src/qmlextramaterials.qdoc b/src/doc/src/qmlextramaterials.qdoc index c54cc948b..e0a2e9edf 100644 --- a/src/doc/src/qmlextramaterials.qdoc +++ b/src/doc/src/qmlextramaterials.qdoc @@ -69,6 +69,10 @@ Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with WrapMode.Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ /*! \qmlproperty TextureImage DiffuseMapMaterial::diffuse @@ -152,6 +156,10 @@ Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with WrapMode.Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ /*! @@ -292,6 +300,10 @@ Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with WrapMode.Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ /*! @@ -366,6 +378,10 @@ Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with WrapMode.Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ /*! @@ -449,6 +465,10 @@ Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with WrapMode.Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ /*! diff --git a/src/extras/defaults/qdiffusemapmaterial.cpp b/src/extras/defaults/qdiffusemapmaterial.cpp index d5e729b8e..83eec26a8 100644 --- a/src/extras/defaults/qdiffusemapmaterial.cpp +++ b/src/extras/defaults/qdiffusemapmaterial.cpp @@ -296,6 +296,9 @@ QAbstractTexture *QDiffuseMapMaterial::diffuse() const Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + When used in conjunction with QTextureWrapMode::Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ float QDiffuseMapMaterial::textureScale() const { diff --git a/src/extras/defaults/qdiffusespecularmapmaterial.cpp b/src/extras/defaults/qdiffusespecularmapmaterial.cpp index e1d23622c..9a1092fbc 100644 --- a/src/extras/defaults/qdiffusespecularmapmaterial.cpp +++ b/src/extras/defaults/qdiffusespecularmapmaterial.cpp @@ -314,6 +314,10 @@ float QDiffuseSpecularMapMaterial::shininess() const Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with QTextureWrapMode::Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ float QDiffuseSpecularMapMaterial::textureScale() const { diff --git a/src/extras/defaults/qdiffusespecularmaterial.cpp b/src/extras/defaults/qdiffusespecularmaterial.cpp index be187b46a..8938ce19a 100644 --- a/src/extras/defaults/qdiffusespecularmaterial.cpp +++ b/src/extras/defaults/qdiffusespecularmaterial.cpp @@ -385,12 +385,20 @@ QVariant QDiffuseSpecularMaterial::normal() const Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with QTextureWrapMode::Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ /*! \qmlproperty real DiffuseSpecularMaterial::textureScale Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with WrapMode.Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ float QDiffuseSpecularMaterial::textureScale() const { diff --git a/src/extras/defaults/qmetalroughmaterial.cpp b/src/extras/defaults/qmetalroughmaterial.cpp index d404f03de..572bfecfd 100644 --- a/src/extras/defaults/qmetalroughmaterial.cpp +++ b/src/extras/defaults/qmetalroughmaterial.cpp @@ -306,12 +306,20 @@ QVariant QMetalRoughMaterial::normal() const Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with QTextureWrapMode::Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ /*! \qmlproperty real Qt3D.Extras::MetalRoughMaterial::textureScale Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with WrapMode.Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ float QMetalRoughMaterial::textureScale() const { diff --git a/src/extras/defaults/qnormaldiffusemapmaterial.cpp b/src/extras/defaults/qnormaldiffusemapmaterial.cpp index 7c8260084..9d41ddb32 100644 --- a/src/extras/defaults/qnormaldiffusemapmaterial.cpp +++ b/src/extras/defaults/qnormaldiffusemapmaterial.cpp @@ -338,6 +338,10 @@ float QNormalDiffuseMapMaterial::shininess() const Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with QTextureWrapMode::Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ float QNormalDiffuseMapMaterial::textureScale() const { diff --git a/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp b/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp index 5fb2b7e9e..a76d9856b 100644 --- a/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp +++ b/src/extras/defaults/qnormaldiffusespecularmapmaterial.cpp @@ -355,6 +355,10 @@ float QNormalDiffuseSpecularMapMaterial::shininess() const Holds the current texture scale. It is applied as a multiplier to texture coordinates at render time. Defaults to 1.0. + + When used in conjunction with QTextureWrapMode::Repeat, textureScale provides a simple + way to tile a texture across a surface. For example, a texture scale of \c 4.0 + would result in 16 (4x4) tiles. */ float QNormalDiffuseSpecularMapMaterial::textureScale() const { diff --git a/src/render/backend/managers.cpp b/src/render/backend/managers.cpp index 26fd68600..aa7dbb741 100644 --- a/src/render/backend/managers.cpp +++ b/src/render/backend/managers.cpp @@ -110,6 +110,12 @@ void JointManager::addDirtyJoint(Qt3DCore::QNodeId jointId) m_dirtyJoints.push_back(jointHandle); } +void JointManager::removeDirtyJoint(Qt3DCore::QNodeId jointId) +{ + const HJoint jointHandle = lookupHandle(jointId); + m_dirtyJoints.removeAll(jointHandle); +} + QVector<HJoint> JointManager::dirtyJoints() { return std::move(m_dirtyJoints); diff --git a/src/render/backend/managers_p.h b/src/render/backend/managers_p.h index eb219fd1e..f28dbe768 100644 --- a/src/render/backend/managers_p.h +++ b/src/render/backend/managers_p.h @@ -433,6 +433,7 @@ class JointManager : public Qt3DCore::QResourceManager< { public: void addDirtyJoint(Qt3DCore::QNodeId jointId); + void removeDirtyJoint(Qt3DCore::QNodeId jointId); QVector<HJoint> dirtyJoints(); private: diff --git a/src/render/framegraph/qclearbuffers.cpp b/src/render/framegraph/qclearbuffers.cpp index 67773a6b7..4cc4c98b6 100644 --- a/src/render/framegraph/qclearbuffers.cpp +++ b/src/render/framegraph/qclearbuffers.cpp @@ -220,7 +220,7 @@ void QClearBuffers::setClearStencilValue(int clearStencilValue) ColorBuffer flag is set, all color buffers will be cleared. */ /*! - \qmlproperty RenderTargetOutput Qt3D.Render::ClearBuffers::colorbuffer + \qmlproperty RenderTargetOutput Qt3D.Render::ClearBuffers::colorBuffer Specifies a specific color buffer to clear. If set to NULL (default), and ColorBuffer flag is set, all color buffers will be cleared. */ diff --git a/src/render/frontend/qcamera.cpp b/src/render/frontend/qcamera.cpp index 274b555f6..29703878d 100644 --- a/src/render/frontend/qcamera.cpp +++ b/src/render/frontend/qcamera.cpp @@ -254,11 +254,14 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit) /*! * \qmlproperty enumeration Qt3D.Render::Camera::projectionType * - * Holds the type of the camera projection. + * Holds the type of the camera projection. The default value is + * CameraLens.PerspectiveProjection. * * \list - * \li CameraLens.OrthographicProjection - * \li CameraLens.PerspectiveProjection + * \li CameraLens.OrthographicProjection - Parallel lines appear parallel. Objects appear + * the same size regardless of distance. + * \li CameraLens.PerspectiveProjection - Parallel lines appear to meet in the distance. + * Objects appear to shrink the farther they are from the camera. * \li CameraLens.FrustumProjection * \li CameraLens.CustomProjection * \endlist @@ -267,17 +270,28 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit) /*! * \qmlproperty real Qt3D.Render::Camera::nearPlane - * Holds the current camera near plane of the camera. + * Holds the current camera near plane of the camera. Objects that + * are closer to the camera than the nearPlane will not be rendered. */ /*! * \qmlproperty real Qt3D.Render::Camera::farPlane - * Holds the current camera far plane of the camera. + * Holds the current camera far plane of the camera. Objects that + * are farther from the camera than the farPlane will not be rendered. */ /*! * \qmlproperty real Qt3D.Render::Camera::fieldOfView - * Holds the current field of view of the camera in degrees. + * Holds the current vertical field of view of the camera in degrees. + * + * Along with \l aspectRatio, this property determines how much of + * the scene is visible to the camera. In that respect you might + * think of it as analogous to choosing a wide angle (wide horizontal + * field of view) or telephoto (narrow horizontal field of view) lens, + * depending on how much of a scene you want to capture. + * + * fieldOfView is only relevant when \l projectionType is + * CameraLens.PerspectiveProjection. */ /*! @@ -288,21 +302,33 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit) /*! *\qmlproperty real Qt3D.Render::Camera::left * Holds the current left of the camera. + * + * This property is only relevant when \l projectionType is + * CameraLens.OrthographicProjection. */ /*! * \qmlproperty real Qt3D.Render::Camera::right * Holds the current right of the camera. + * + * This property is only relevant when \l projectionType is + * CameraLens.OrthographicProjection. */ /*! * \qmlproperty real Qt3D.Render::Camera::bottom * Holds the current bottom of the camera. + * + * This property is only relevant when \l projectionType is + * CameraLens.OrthographicProjection. */ /*! * \qmlproperty real Qt3D.Render::Camera::top * Holds the current top of the camera. + * + * This property is only relevant when \l projectionType is + * CameraLens.OrthographicProjection. */ /*! @@ -321,19 +347,29 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit) * \qmlproperty vector3d Qt3D.Render::Camera::upVector * Holds the current up vector of the camera in coordinates relative to * the parent entity. + * + * The up vector indicates which direction the top of the camera is + * facing. Think of taking a picture: after positioning yourself + * and pointing the camera at your target, you might rotate the camera + * left or right, giving you a portrait or landscape (or angled!) + * shot. upVector allows you to control this type of movement. */ /*! * \qmlproperty vector3d Qt3D.Render::Camera::viewCenter * Holds the current view center of the camera in coordinates relative to * the parent entity. - * \readonly + * + * Intuitively, the viewCenter is the location the camera is pointing at. */ /*! * \qmlproperty vector3d Qt3D.Render::Camera::viewVector * Holds the camera's view vector in coordinates relative to * the parent entity. + * + * This vector decribes the displacement from the camera (\l position) + * to its target (\l viewCenter). * \readonly */ @@ -348,30 +384,44 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit) /*! * \property QCamera::projectionType * - * Holds the type of the camera projection. + * Holds the type of the camera projection. The default value is + * QCameraLens::PerspectiveProjection. * * \list - * \li CameraLens.OrthographicProjection - * \li CameraLens.PerspectiveProjection - * \li CameraLens.FrustumProjection - * \li CameraLens.CustomProjection + * \li QCameraLens::OrthographicProjection - Parallel lines appear parallel. Objects appear + * the same size regardless of distance. + * \li QCameraLens::PerspectiveProjection - Parallel lines appear to meet in the distance. + * Objects appear to shrink the farther they are from the camera. + * \li QCameraLens::FrustumProjection + * \li QCameraLens::CustomProjection * \endlist * \sa Qt3DRender::QCameraLens::ProjectionType */ /*! * \property QCamera::nearPlane - * Holds the current camera near plane. + * Holds the current camera near plane. Objects that are closer to the + * camera than the nearPlane will not be rendered. */ /*! * \property QCamera::farPlane - * Holds the current camera far plane. + * Holds the current camera far plane. Objects that are farther from the + * camera than the farPlane will not be rendered. */ /*! * \property QCamera::fieldOfView - * Holds the current field of view in degrees. + * Holds the current vertical field of view in degrees. + * + * Along with \l aspectRatio, this property determines how much of + * the scene is visible to the camera. In that respect you might + * think of it as analogous to choosing a wide angle (wide horizontal + * field of view) or telephoto (narrow horizontal field of view) lens + * depending on how much of a scene you want to capture. + * + * fieldOfView is only relevant when \l projectionType is + * QCameraLens::PerspectiveProjection. */ /*! @@ -382,21 +432,33 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit) /*! *\property QCamera::left * Holds the current left of the camera. + * + * This property is only relevant when \l projectionType is + * QCameraLens::OrthographicProjection. */ /*! * \property QCamera::right * Holds the current right of the camera. + * + * This property is only relevant when \l projectionType is + * QCameraLens::OrthographicProjection. */ /*! * \property QCamera::bottom * Holds the current bottom of the camera. + * + * This property is only relevant when \l projectionType is + * QCameraLens::OrthographicProjection. */ /*! * \property QCamera::top * Holds the current top of the camera. + * + * This property is only relevant when \l projectionType is + * QCameraLens::OrthographicProjection. */ /*! @@ -419,18 +481,29 @@ void QCameraPrivate::updateViewMatrixAndTransform(bool doEmit) * \property QCamera::upVector * Holds the camera's up vector in coordinates relative to * the parent entity. + * + * The up vector indicates which direction the top of the camera is + * facing. Think of taking a picture: after positioning yourself + * and pointing the camera at your target, you might rotate the camera + * left or right, giving you a portrait or landscape (or angled!) + * shot. upVector allows you to control this type of movement. */ /*! * \property QCamera::viewCenter * Holds the camera's view center in coordinates relative to * the parent entity. + * + * Intuitively, the viewCenter is the location the camera is pointing at. */ /*! * \property QCamera::viewVector * Holds the camera's view vector in coordinates relative to * the parent entity. + * + * This vector decribes the displacement from the camera (\l position) + * to its target (\l viewCenter). */ /*! diff --git a/src/render/geometry/joint.cpp b/src/render/geometry/joint.cpp index 9c53b8ef8..c770564f9 100644 --- a/src/render/geometry/joint.cpp +++ b/src/render/geometry/joint.cpp @@ -153,6 +153,7 @@ Qt3DCore::QBackendNode *JointFunctor::get(Qt3DCore::QNodeId id) const void JointFunctor::destroy(Qt3DCore::QNodeId id) const { + m_jointManager->removeDirtyJoint(id); m_jointManager->releaseResource(id); } diff --git a/src/render/raycasting/qray3d.cpp b/src/render/raycasting/qray3d.cpp index d8ad25b50..18dd9a40a 100644 --- a/src/render/raycasting/qray3d.cpp +++ b/src/render/raycasting/qray3d.cpp @@ -101,7 +101,7 @@ QRay3D::QRay3D() */ QRay3D::QRay3D(const Vector3D &origin, const Vector3D &direction, float distance) : m_origin(origin) - , m_direction(direction) + , m_direction(direction.normalized()) , m_distance(distance) {} @@ -157,7 +157,7 @@ void QRay3D::setDirection(const Vector3D &value) if (value.isNull()) return; - m_direction = value; + m_direction = value.normalized(); } float QRay3D::distance() const @@ -178,14 +178,14 @@ Vector3D QRay3D::point(float t) const QRay3D &QRay3D::transform(const Matrix4x4 &matrix) { m_origin = matrix * m_origin; - m_direction = matrix.mapVector(m_direction); + m_direction = matrix.mapVector(m_direction).normalized(); return *this; } QRay3D QRay3D::transformed(const Matrix4x4 &matrix) const { - return QRay3D(matrix * m_origin, matrix.mapVector(m_direction)); + return QRay3D(matrix * m_origin, matrix.mapVector(m_direction).normalized()); } bool QRay3D::operator==(const QRay3D &other) const diff --git a/tests/auto/render/qray3d/tst_qray3d.cpp b/tests/auto/render/qray3d/tst_qray3d.cpp index e9d4d3033..008b89aca 100644 --- a/tests/auto/render/qray3d/tst_qray3d.cpp +++ b/tests/auto/render/qray3d/tst_qray3d.cpp @@ -108,23 +108,23 @@ void tst_QRay3D::create_data() // non-normalized direction vectors QTest::newRow("line on x-axis from origin - B") << Vector3D() - << Vector3D(2.0f, 0.0f, 0.0f); + << Vector3D(2.0f, 0.0f, 0.0f).normalized(); QTest::newRow("line parallel -z-axis from 3,3,3 - B") << Vector3D(3.0f, 3.0f, 3.0f) - << Vector3D(0.0f, 0.0f, -0.7f); + << Vector3D(0.0f, 0.0f, -0.7f).normalized(); QTest::newRow("vertical line (parallel to y-axis) - B") << Vector3D(0.5f, 0.0f, 0.5f) - << Vector3D(0.0f, 5.3f, 0.0f); + << Vector3D(0.0f, 5.3f, 0.0f).normalized(); QTest::newRow("equidistant from all 3 axes - B") << Vector3D(0.5f, 0.0f, 0.5f) - << Vector3D(1.0f, 1.0f, 1.0f); + << Vector3D(1.0f, 1.0f, 1.0f).normalized(); QTest::newRow("negative direction") << Vector3D(-3.0f, -3.0f, -3.0f) - << Vector3D(-1.2f, -1.8f, -2.4f); + << Vector3D(-1.2f, -1.8f, -2.4f).normalized(); } void tst_QRay3D::create() @@ -203,32 +203,32 @@ void tst_QRay3D::point_data() QTest::newRow("line on x-axis from origin") << Vector3D() << Vector3D(2.0f, 0.0f, 0.0f) - << Vector3D(1.2f, 0.0f, 0.0f) - << Vector3D(-14.4f, 0.0f, 0.0f); + << Vector3D(0.6f, 0.0f, 0.0f) + << Vector3D(-7.2f, 0.0f, 0.0f); QTest::newRow("line parallel -z-axis from 3,3,3") << Vector3D(3.0f, 3.0f, 3.0f) << Vector3D(0.0f, 0.0f, -0.7f) - << Vector3D(3.0f, 3.0f, 2.58f) - << Vector3D(3.0f, 3.0f, 8.04f); + << Vector3D(3.0f, 3.0f, 2.4f) + << Vector3D(3.0f, 3.0f, 10.2f); QTest::newRow("vertical line (parallel to y-axis)") << Vector3D(0.5f, 0.0f, 0.5f) << Vector3D(0.0f, 5.3f, 0.0f) - << Vector3D(0.5f, 3.18f, 0.5f) - << Vector3D(0.5f, -38.16f, 0.5f); + << Vector3D(0.5f, 0.6f, 0.5f) + << Vector3D(0.5f, -7.2f, 0.5f); QTest::newRow("equidistant from all 3 axes") << Vector3D(0.5f, 0.0f, 0.5f) << Vector3D(1.0f, 1.0f, 1.0f) - << Vector3D(1.1f, 0.6f, 1.1f) - << Vector3D(-6.7f, -7.2f, -6.7f); + << Vector3D(0.84641f, 0.34641f, 0.84641f) + << Vector3D(-3.65692f, -4.15692f, -3.65692f); QTest::newRow("negative direction") << Vector3D(-3.0f, -3.0f, -3.0f) << Vector3D(-1.2f, -1.8f, -2.4f) - << Vector3D(-3.72f, -4.08f, -4.44f) - << Vector3D(5.64f, 9.96f, 14.28f); + << Vector3D(-3.22283f, -3.33425f, -3.44567f) + << Vector3D(-0.325987f, 1.01102f, 2.34803f); } void tst_QRay3D::point() @@ -475,7 +475,7 @@ void tst_QRay3D::transform() QVERIFY(fuzzyCompare(ray1.direction(), ray3.direction())); QVERIFY(fuzzyCompare(ray1.origin(), m * point)); - QVERIFY(fuzzyCompare(ray1.direction(), m.mapVector(direction))); + QVERIFY(fuzzyCompare(ray1.direction(), m.mapVector(direction).normalized())); } class tst_QRay3DProperties : public QObject @@ -503,7 +503,7 @@ void tst_QRay3D::properties() Qt3DRender::RayCasting::QRay3D r = qvariant_cast<Qt3DRender::RayCasting::QRay3D>(obj.property("ray")); QCOMPARE(r.origin(), Vector3D(1, 2, 3)); - QCOMPARE(r.direction(), Vector3D(4, 5, 6)); + QCOMPARE(r.direction(), Vector3D(4, 5, 6).normalized()); obj.setProperty("ray", qVariantFromValue @@ -511,7 +511,7 @@ void tst_QRay3D::properties() r = qvariant_cast<Qt3DRender::RayCasting::QRay3D>(obj.property("ray")); QCOMPARE(r.origin(), Vector3D(-1, -2, -3)); - QCOMPARE(r.direction(), Vector3D(-4, -5, -6)); + QCOMPARE(r.direction(), Vector3D(-4, -5, -6).normalized()); } void tst_QRay3D::metaTypes() |