From 4d575f94e28d0c0e1a31eb1e056356ca4f940f2a Mon Sep 17 00:00:00 2001 From: beomki-yeo Date: Sat, 20 Apr 2024 18:20:50 +0200 Subject: [PATCH] Vectorize the rotate function of cmath transform3 --- .../algebra/math/impl/cmath_transform3.hpp | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/math/cmath/include/algebra/math/impl/cmath_transform3.hpp b/math/cmath/include/algebra/math/impl/cmath_transform3.hpp index 7e7c9f08..fe2d1191 100644 --- a/math/cmath/include/algebra/math/impl/cmath_transform3.hpp +++ b/math/cmath/include/algebra/math/impl/cmath_transform3.hpp @@ -235,15 +235,21 @@ struct transform3 { ALGEBRA_HOST_DEVICE static inline vector3 rotate(const matrix44 &m, const vector3 &v) { - return {matrix_actor().element(m, 0, 0) * v[0] + - matrix_actor().element(m, 0, 1) * v[1] + - matrix_actor().element(m, 0, 2) * v[2], - matrix_actor().element(m, 1, 0) * v[0] + - matrix_actor().element(m, 1, 1) * v[1] + - matrix_actor().element(m, 1, 2) * v[2], - matrix_actor().element(m, 2, 0) * v[0] + - matrix_actor().element(m, 2, 1) * v[1] + - matrix_actor().element(m, 2, 2) * v[2]}; + vector3 ret{0.f, 0.f, 0.f}; + + ret = ret + vector3{matrix_actor().element(m, 0, 0) * v[0], + matrix_actor().element(m, 1, 0) * v[0], + matrix_actor().element(m, 2, 0) * v[0]}; + + ret = ret + vector3{matrix_actor().element(m, 0, 1) * v[1], + matrix_actor().element(m, 1, 1) * v[1], + matrix_actor().element(m, 2, 1) * v[1]}; + + ret = ret + vector3{matrix_actor().element(m, 0, 2) * v[2], + matrix_actor().element(m, 1, 2) * v[2], + matrix_actor().element(m, 2, 2) * v[2]}; + + return ret; } /** This method retrieves the rotation of a transform */