summaryrefslogtreecommitdiffstats
path: root/src/render
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-07-11 16:19:28 +0200
committerPaul Lemire <paul.lemire@kdab.com>2019-07-15 12:11:43 +0200
commitc9eb1f347a501c6915595bfb705af3aecc2fbadd (patch)
tree65330563084c5818cd2c342e06f089285c4104af /src/render
parent69f112354dc09645a21db75f0630140c4480d809 (diff)
QRay3D: normalize the direction vector internally
It can be created with a non normalized dir vector but we should always perform the computations with a normalized dir vector for correct results. Change-Id: Ie9108de7ed2092f6b979a70ad9391267fe6c4696 Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/render')
-rw-r--r--src/render/raycasting/qray3d.cpp8
1 files changed, 4 insertions, 4 deletions
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