Add mat4_projection and mat4_lookat.

This commit is contained in:
Roz K 2022-09-20 02:54:59 +02:00
parent 601336f1f9
commit 59df9e8748
Signed by: roz
GPG Key ID: 51FBF4E483E1C822
3 changed files with 50 additions and 0 deletions

View File

@ -163,6 +163,28 @@ def mat3_mul_mat3(ret, a, b):
assert len(ret) == 9 and len(a) == 9 and len(b) == 9 assert len(ret) == 9 and len(a) == 9 and len(b) == 9
_mat3_mul_mat3(_mat3(ret), _mat3(a), _mat3(b)) _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 = _lib.rk_mat4_mul_vec4
_mat4_mul_vec4.argtypes = ( _mat4_mul_vec4.argtypes = (
_vec4_t, # ret _vec4_t, # ret

View File

@ -38,6 +38,22 @@ void rk_mat3_mul_mat3(
ret = a * b; 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( void rk_mat4_mul_vec4(
rk_vec4 & ret, rk_vec4 & ret,
rk_mat4 const & a, rk_mat4 const & a,

View File

@ -41,6 +41,18 @@ RK_EXPORT void rk_mat3_mul_mat3(
rk_mat3 const & a, rk_mat3 const & a,
rk_mat3 const & b); 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_EXPORT void rk_mat4_mul_vec4(
rk_vec4 & ret, rk_vec4 & ret,
rk_mat4 const & a, rk_mat4 const & a,