diff --git a/__init__.py b/__init__.py index 8b64bf4..ad194d6 100644 --- a/__init__.py +++ b/__init__.py @@ -163,6 +163,28 @@ def mat3_mul_mat3(ret, a, b): assert len(ret) == 9 and len(a) == 9 and len(b) == 9 _mat3_mul_mat3(_mat3(ret), _mat3(a), _mat3(b)) +_mat4_projection = _lib.rk_mat4_projection +_mat4_projection.argtypes = ( + _mat4_t, # ret + ctypes.c_float, # hfov + ctypes.c_float, # ratio + ctypes.c_float, # near + ctypes.c_float) # far + +def mat4_projection(ret, hfov, ratio, near, far): + assert len(ret) == 16 + _mat4_projection(_mat4(ret), hfov, ratio, near, far) + +_mat4_lookat = _lib.rk_mat4_lookat +_mat4_lookat.argtypes = ( + _mat4_t, # ret + _vec3_t, # position + _vec3_t) # lookat + +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_vec4 = _lib.rk_mat4_mul_vec4 _mat4_mul_vec4.argtypes = ( _vec4_t, # ret diff --git a/cpp/math.cpp b/cpp/math.cpp index 2d34ff3..23cdff3 100644 --- a/cpp/math.cpp +++ b/cpp/math.cpp @@ -38,6 +38,22 @@ void rk_mat3_mul_mat3( ret = a * b; } +void rk_mat4_projection( + rk_mat4 & ret, + float hfov, + float ratio, + float near, + float far) { + ret = glm::perspectiveRH(hfov, ratio, near, far); +} + +void rk_mat4_lookat( + rk_mat4 & ret, + rk_vec3 const & position, + rk_vec3 const & lookat) { + ret = glm::lookAtRH(position, lookat, glm::vec3(0.0f, 0.0f, 1.0f)); +} + void rk_mat4_mul_vec4( rk_vec4 & ret, rk_mat4 const & a, diff --git a/cpp/math.hpp b/cpp/math.hpp index 0d82ee3..db35237 100644 --- a/cpp/math.hpp +++ b/cpp/math.hpp @@ -41,6 +41,18 @@ RK_EXPORT void rk_mat3_mul_mat3( rk_mat3 const & a, rk_mat3 const & b); +RK_EXPORT void rk_mat4_projection( + rk_mat4 & ret, + float hfov, + float ratio, + float near, + float far); + +RK_EXPORT void rk_mat4_lookat( + rk_mat4 & ret, + rk_vec3 const & position, + rk_vec3 const & lookat); + RK_EXPORT void rk_mat4_mul_vec4( rk_vec4 & ret, rk_mat4 const & a,