summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnsis Brammanis <brammanis@gmail.com>2017-06-29 12:04:13 -0400
committerAnsis Brammanis <brammanis@gmail.com>2017-07-10 13:09:34 -0400
commit5cfa15e1143aea8d2a6a25625350399c483f10b9 (patch)
tree344f7ce62240794918403db5a99b0b7f819a3c58
parent0a645f6f2162d81f141941ff56e373ab302b45d4 (diff)
downloadqtlocation-mapboxgl-5cfa15e1143aea8d2a6a25625350399c483f10b9.tar.gz
[core] fix transformMat4
It used to overwrite values in the middle of the calculation which would cause problems when `out` and `a` were a reference to the same vector.
-rw-r--r--src/mbgl/util/mat4.cpp9
1 files changed, 5 insertions, 4 deletions
diff --git a/src/mbgl/util/mat4.cpp b/src/mbgl/util/mat4.cpp
index d3d3617b7b..0ad0d371e5 100644
--- a/src/mbgl/util/mat4.cpp
+++ b/src/mbgl/util/mat4.cpp
@@ -336,10 +336,11 @@ void multiply(mat4& out, const mat4& a, const mat4& b) {
}
void transformMat4(vec4& out, const vec4& a, const mat4& m) {
- out[0] = m[0] * a[0] + m[4] * a[1] + m[8] * a[2] + m[12] * a[3];
- out[1] = m[1] * a[0] + m[5] * a[1] + m[9] * a[2] + m[13] * a[3];
- out[2] = m[2] * a[0] + m[6] * a[1] + m[10] * a[2] + m[14] * a[3];
- out[3] = m[3] * a[0] + m[7] * a[1] + m[11] * a[2] + m[15] * a[3];
+ double x = a[0], y = a[1], z = a[2], w = a[3];
+ out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
+ out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
+ out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
+ out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
}
} // namespace matrix