Add mat4_orbit.
This commit is contained in:
parent
269d7821c8
commit
33abfd834a
@ -182,6 +182,14 @@ mat4_lookat.argtypes = (
|
||||
_vec3_p, # position
|
||||
_vec3_p) # lookat
|
||||
|
||||
mat4_orbit = _engine.rk_mat4_orbit
|
||||
mat4_orbit.argtypes = (
|
||||
_mat4_p, # ret
|
||||
_vec3_p, # origin
|
||||
ctypes.c_float, # yaw
|
||||
ctypes.c_float, # pitch
|
||||
ctypes.c_float) # distance
|
||||
|
||||
mat4_mul_vec3 = _engine.rk_mat4_mul_vec3
|
||||
mat4_mul_vec3.argtypes = (
|
||||
_vec3_p, # ret
|
||||
|
14
cpp/math.cpp
14
cpp/math.cpp
@ -64,7 +64,19 @@ 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));
|
||||
ret = glm::lookAtRH(position, lookat, vec3_up);
|
||||
}
|
||||
|
||||
void rk_mat4_orbit(
|
||||
rk_mat4 & ret,
|
||||
rk_vec3 const & origin,
|
||||
float const yaw,
|
||||
float const pitch,
|
||||
float const distance) {
|
||||
ret = glm::translate(
|
||||
glm::lookAtRH(glm::vec3(0.f, -distance, 0.f), vec3_origin, vec3_up) *
|
||||
glm::mat4(glm::angleAxis(pitch, vec3_right) * glm::angleAxis(yaw, vec3_up)),
|
||||
origin);
|
||||
}
|
||||
|
||||
void rk_mat4_mul_vec3(
|
||||
|
12
cpp/math.hpp
12
cpp/math.hpp
@ -26,6 +26,11 @@ typedef glm::vec4 rk_vec4;
|
||||
typedef glm::mat3 rk_mat3;
|
||||
typedef glm::mat4 rk_mat4;
|
||||
|
||||
#define vec3_right (rk_vec3(1.f, 0.f, 0.f))
|
||||
#define vec3_forward (rk_vec3(0.f, 1.f, 0.f))
|
||||
#define vec3_up (rk_vec3(0.f, 0.f, 1.f))
|
||||
#define vec3_origin (rk_vec3(0.f, 0.f, 0.f))
|
||||
|
||||
RK_EXPORT void rk_vec3_rotate(
|
||||
rk_vec3 & ret,
|
||||
rk_vec3 const & vec3,
|
||||
@ -64,6 +69,13 @@ RK_EXPORT void rk_mat4_lookat(
|
||||
rk_vec3 const & position,
|
||||
rk_vec3 const & lookat);
|
||||
|
||||
RK_EXPORT void rk_mat4_orbit(
|
||||
rk_mat4 & ret,
|
||||
rk_vec3 const & origin,
|
||||
float const yaw,
|
||||
float const pitch,
|
||||
float const distance);
|
||||
|
||||
RK_EXPORT void rk_mat4_mul_vec3(
|
||||
rk_vec3 & ret,
|
||||
rk_mat4 const & a,
|
||||
|
Loading…
Reference in New Issue
Block a user