From 1e56cc1c28d4f9977b55f47566c3c8050f25670c Mon Sep 17 00:00:00 2001 From: Roz K Date: Tue, 29 Nov 2022 03:05:34 +0100 Subject: [PATCH] Add mat4_mul_vec3. --- __init__.py | 11 +++++++++++ cpp/math.cpp | 8 ++++++++ cpp/math.hpp | 6 ++++++ 3 files changed, 25 insertions(+) diff --git a/__init__.py b/__init__.py index a94acfe..d1899f0 100644 --- a/__init__.py +++ b/__init__.py @@ -181,6 +181,17 @@ def mat4_lookat(ret, position, lookat): assert len(ret) == 16 and len(position) == 3 and len(lookat) == 3 _mat4_lookat(_mat4(ret), _vec3(position), _vec3(lookat)) +_mat4_mul_vec3 = _lib.rk_mat4_mul_vec3 +_mat4_mul_vec3.argtypes = ( + _vec3_t, # ret + _mat4_t, # a + _vec3_t, # b + ctypes.c_float) # w + +def mat4_mul_vec3(ret, a, b, w): + assert len(ret) == 3 and len(a) == 16 and len(b) == 3 + _mat4_mul_vec3(_vec3(ret), _mat4(a), _vec3(b), w) + _mat4_mul_vec4 = _lib.rk_mat4_mul_vec4 _mat4_mul_vec4.argtypes = ( _vec4_t, # ret diff --git a/cpp/math.cpp b/cpp/math.cpp index 23cdff3..abaa13d 100644 --- a/cpp/math.cpp +++ b/cpp/math.cpp @@ -54,6 +54,14 @@ void rk_mat4_lookat( ret = glm::lookAtRH(position, lookat, glm::vec3(0.0f, 0.0f, 1.0f)); } +void rk_mat4_mul_vec3( + rk_vec3 & ret, + rk_mat4 const & a, + rk_vec3 const & b, + float const w) { + ret = glm::vec3(a * glm::vec4(b, w)); +} + void rk_mat4_mul_vec4( rk_vec4 & ret, rk_mat4 const & a, diff --git a/cpp/math.hpp b/cpp/math.hpp index db35237..7abed16 100644 --- a/cpp/math.hpp +++ b/cpp/math.hpp @@ -53,6 +53,12 @@ RK_EXPORT void rk_mat4_lookat( rk_vec3 const & position, rk_vec3 const & lookat); +RK_EXPORT void rk_mat4_mul_vec3( + rk_vec3 & ret, + rk_mat4 const & a, + rk_vec3 const & b, + float const w); + RK_EXPORT void rk_mat4_mul_vec4( rk_vec4 & ret, rk_mat4 const & a,