Skip to content

Commit

Permalink
Fixed matrix calculation. (#138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ggarra13 committed May 21, 2024
1 parent ca246d8 commit eb2b1ea
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/tlCore/MatrixInline.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,27 +240,23 @@ namespace tl
inline Vector3<T> operator * (const Matrix4x4<T>& a, const Vector3<T>& v)
{
Vector3<T> out;
for (int i = 0; i < 3; ++i)
{
for (int j = 0; j < 3; ++j)
{
out[i] += a.e[i * 4 + j] * v[j];
}
}
T x = T (v[0] * a.e[0] + v[1] * a.e[4] + v[2] * a.e[8] + a.e[12]);
T y = T (v[0] * a.e[1] + v[1] * a.e[5] + v[2] * a.e[9] + a.e[13]);
T z = T (v[0] * a.e[2] + v[1] * a.e[6] + v[2] * a.e[10] + a.e[14]);
T w = T (v[0] * a.e[3] + v[1] * a.e[7] + v[2] * a.e[11] + a.e[15]);

out = Vector3<T> (x / w, y / w, z / w);
return out;
}

template<typename T>
inline Vector4<T> operator * (const Matrix4x4<T>& a, const Vector4<T>& v)
{
Vector4<T> out;
for (int i = 0; i < 4; ++i)
{
for (int j = 0; j < 4; ++j)
{
out[i] += a.e[i * 4 + j] * v[j];
}
}
out.x = T (v[0] * a.e[0] + v[1] * a.e[4] + v[2] * a.e[8] + v[3] * a.e[12]);
out.y = T (v[0] * a.e[1] + v[1] * a.e[5] + v[2] * a.e[9] + v[3] * a.e[13]);
out.z = T (v[0] * a.e[2] + v[1] * a.e[6] + v[2] * a.e[10] + v[3] * a.e[14]);
out.w = T (v[0] * a.e[3] + v[1] * a.e[7] + v[2] * a.e[11] + v[3] * a.e[15]);
return out;
}
};
Expand Down

0 comments on commit eb2b1ea

Please sign in to comment.