Skip to content

Commit

Permalink
Vectorize the rotate function of cmath transform3
Browse files Browse the repository at this point in the history
  • Loading branch information
beomki-yeo committed Apr 20, 2024
1 parent ee9cf86 commit 4d575f9
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions math/cmath/include/algebra/math/impl/cmath_transform3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 4d575f9

Please sign in to comment.