From ccce6c5d83deb260d06bc525721e31c7c4edcabe Mon Sep 17 00:00:00 2001 From: Roz K Date: Tue, 20 Dec 2022 15:26:53 +0100 Subject: [PATCH] Add vec3_rotate and vec3_mul_vec3. --- __init__.py | 14 ++++++++++++++ cpp/math.cpp | 15 +++++++++++++++ cpp/math.hpp | 11 +++++++++++ 3 files changed, 40 insertions(+) diff --git a/__init__.py b/__init__.py index 5774c5c..122398e 100644 --- a/__init__.py +++ b/__init__.py @@ -105,6 +105,20 @@ def _floatp(x): assert x.typecode == 'f' return x.buffer_info()[0] +vec3_rotate = _lib.rk_vec3_rotate +vec3_rotate.argtypes = ( + _vec3p, # ret + _vec3p, # vec3 + _vec3p, # axis + ctypes.c_float) # angle + + +vec3_mul_vec3 = _lib.rk_vec3_mul_vec3 +vec3_mul_vec3.argtypes = ( + _vec3p, # ret + _vec3p, # a + _vec3p) # b + mat3_rotation = _lib.rk_mat3_rotation mat3_rotation.argtypes = ( _mat3p, # ret diff --git a/cpp/math.cpp b/cpp/math.cpp index ee2da7b..192941b 100644 --- a/cpp/math.cpp +++ b/cpp/math.cpp @@ -15,6 +15,21 @@ #include "math.hpp" +void rk_vec3_rotate( + rk_vec3 & ret, + rk_vec3 const & vec3, + rk_vec3 const & axis, + float const angle) { + ret = glm::angleAxis(angle, axis) * vec3; +} + +void rk_vec3_mul_vec3( + rk_vec3 & ret, + rk_vec3 const & a, + rk_vec3 const & b) { + ret = a * b; +} + void rk_mat3_rotation( rk_mat3 & ret, rk_vec3 const & axis, diff --git a/cpp/math.hpp b/cpp/math.hpp index 7abed16..2bd03ac 100644 --- a/cpp/math.hpp +++ b/cpp/math.hpp @@ -26,6 +26,17 @@ typedef glm::vec4 rk_vec4; typedef glm::mat3 rk_mat3; typedef glm::mat4 rk_mat4; +RK_EXPORT void rk_vec3_rotate( + rk_vec3 & ret, + rk_vec3 const & vec3, + rk_vec3 const & axis, + float const angle); + +RK_EXPORT void rk_vec3_mul_vec3( + rk_vec3 & ret, + rk_vec3 const & a, + rk_vec3 const & b); + RK_EXPORT void rk_mat3_rotation( rk_mat3 & ret, rk_vec3 const & axis,