Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[core] fix transformMat4
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ansis committed Jul 7, 2017
1 parent 6e67dc5 commit 4228c4b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/mbgl/util/mat4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4228c4b

Please sign in to comment.