diff options
author | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-04-15 23:21:44 (GMT) |
---|---|---|
committer | Rhys Weatherley <rhys.weatherley@nokia.com> | 2009-04-15 23:25:22 (GMT) |
commit | c57b1a8629b7fa79f48a35eea2f09d923b665dc0 (patch) | |
tree | f17a70d2534cea9b095afa479135b1e5ea79805e /src/gui/math3d/qmatrix4x4.cpp | |
parent | 1cb11b428ef1bee070af72676b7eb1fa325bb980 (diff) | |
download | Qt-c57b1a8629b7fa79f48a35eea2f09d923b665dc0.zip Qt-c57b1a8629b7fa79f48a35eea2f09d923b665dc0.tar.gz Qt-c57b1a8629b7fa79f48a35eea2f09d923b665dc0.tar.bz2 |
Optimize vector normalize for vectors of length 1
If the square of the length is very close to 1, then avoid the qSqrt().
Reviewed-by: trustme
Diffstat (limited to 'src/gui/math3d/qmatrix4x4.cpp')
-rw-r--r-- | src/gui/math3d/qmatrix4x4.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/gui/math3d/qmatrix4x4.cpp b/src/gui/math3d/qmatrix4x4.cpp index e00d772..649532d 100644 --- a/src/gui/math3d/qmatrix4x4.cpp +++ b/src/gui/math3d/qmatrix4x4.cpp @@ -995,8 +995,9 @@ QMatrix4x4& QMatrix4x4::rotate(qreal angle, qreal x, qreal y, qreal z) quick = true; } if (!quick) { - qreal len = qSqrt(x * x + y * y + z * z); - if (len != 0) { + qreal len = x * x + y * y + z * z; + if (!qFuzzyIsNull(len - 1.0f) && !qFuzzyIsNull(len)) { + len = qSqrt(len); x /= len; y /= len; z /= len; |