From 29c383767204630a52b258c93da72620cf7b526c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 16 Aug 2021 14:16:43 +0300 Subject: [PATCH 1/5] implement project zo --- include/cglm/call/clipspace/persp_lh_zo.h | 2 +- include/cglm/call/clipspace/project_no.h | 4 +++ include/cglm/call/clipspace/project_zo.h | 4 +++ include/cglm/clipspace/project_no.h | 29 +++++++++++++++++++++ include/cglm/clipspace/project_zo.h | 31 +++++++++++++++++++++++ include/cglm/project.h | 17 ++++--------- src/clipspace/project_no.c | 6 +++++ src/clipspace/project_zo.c | 6 +++++ 8 files changed, 86 insertions(+), 13 deletions(-) diff --git a/include/cglm/call/clipspace/persp_lh_zo.h b/include/cglm/call/clipspace/persp_lh_zo.h index c22deac..53c2c1c 100644 --- a/include/cglm/call/clipspace/persp_lh_zo.h +++ b/include/cglm/call/clipspace/persp_lh_zo.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/project_no.h b/include/cglm/call/clipspace/project_no.h index 858f525..8c26c96 100644 --- a/include/cglm/call/clipspace/project_no.h +++ b/include/cglm/call/clipspace/project_no.h @@ -17,6 +17,10 @@ CGLM_EXPORT void glmc_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); +CGLM_EXPORT +void +glmc_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/call/clipspace/project_zo.h b/include/cglm/call/clipspace/project_zo.h index ccfe64b..d95a5fe 100644 --- a/include/cglm/call/clipspace/project_zo.h +++ b/include/cglm/call/clipspace/project_zo.h @@ -17,6 +17,10 @@ CGLM_EXPORT void glmc_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest); +CGLM_EXPORT +void +glmc_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/clipspace/project_no.h b/include/cglm/clipspace/project_no.h index 4496364..7e74323 100644 --- a/include/cglm/clipspace/project_no.h +++ b/include/cglm/clipspace/project_no.h @@ -54,4 +54,33 @@ glm_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { glm_vec3(v, dest); } +/*! + * @brief map object coordinates to window coordinates + * + * Computing MVP: + * glm_mat4_mul(proj, view, viewProj); + * glm_mat4_mul(viewProj, model, MVP); + * + * @param[in] pos object coordinates + * @param[in] m MVP matrix + * @param[in] vp viewport as [x, y, width, height] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +void +glm_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + CGLM_ALIGN(16) vec4 pos4; + + glm_vec4(pos, 1.0f, pos4); + + glm_mat4_mulv(m, pos4, pos4); + glm_vec4_scale(pos4, 1.0f / pos4[3], pos4); /* pos = pos / pos.w */ + glm_vec4_scale(pos4, 0.5f, pos4); + glm_vec4_adds(pos4, 0.5f, pos4); + + dest[0] = pos4[0] * vp[2] + vp[0]; + dest[1] = pos4[1] * vp[3] + vp[1]; + dest[2] = pos4[2]; +} + #endif /* cglm_project_no_h */ diff --git a/include/cglm/clipspace/project_zo.h b/include/cglm/clipspace/project_zo.h index e23d086..adc3597 100644 --- a/include/cglm/clipspace/project_zo.h +++ b/include/cglm/clipspace/project_zo.h @@ -54,4 +54,35 @@ glm_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { glm_vec3(v, dest); } +/*! + * @brief map object coordinates to window coordinates + * + * Computing MVP: + * glm_mat4_mul(proj, view, viewProj); + * glm_mat4_mul(viewProj, model, MVP); + * + * @param[in] pos object coordinates + * @param[in] m MVP matrix + * @param[in] vp viewport as [x, y, width, height] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +void +glm_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + CGLM_ALIGN(16) vec4 pos4; + + glm_vec4(pos, 1.0f, pos4); + + glm_mat4_mulv(m, pos4, pos4); + glm_vec4_scale(pos4, 1.0f / pos4[3], pos4); /* pos = pos / pos.w */ + + dest[2] = pos4[2]; + + glm_vec4_scale(pos4, 0.5f, pos4); + glm_vec4_adds(pos4, 0.5f, pos4); + + dest[0] = pos4[0] * vp[2] + vp[0]; + dest[1] = pos4[1] * vp[3] + vp[1]; +} + #endif /* cglm_project_zo_h */ diff --git a/include/cglm/project.h b/include/cglm/project.h index b39b6b6..ceeb528 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -107,18 +107,11 @@ glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) { CGLM_INLINE void glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { - CGLM_ALIGN(16) vec4 pos4, vone = GLM_VEC4_ONE_INIT; - - glm_vec4(pos, 1.0f, pos4); - - glm_mat4_mulv(m, pos4, pos4); - glm_vec4_scale(pos4, 1.0f / pos4[3], pos4); /* pos = pos / pos.w */ - glm_vec4_add(pos4, vone, pos4); - glm_vec4_scale(pos4, 0.5f, pos4); - - dest[0] = pos4[0] * vp[2] + vp[0]; - dest[1] = pos4[1] * vp[3] + vp[1]; - dest[2] = pos4[2]; +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT + glm_project_zo(pos, m, vp, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT + glm_project_no(pos, m, vp, dest); +#endif } #endif /* cglm_project_h */ diff --git a/src/clipspace/project_no.c b/src/clipspace/project_no.c index e160a86..ceb8b0b 100644 --- a/src/clipspace/project_no.c +++ b/src/clipspace/project_no.c @@ -12,3 +12,9 @@ void glmc_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { glm_unprojecti_no(pos, invMat, vp, dest); } + +CGLM_EXPORT +void +glmc_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + glm_project_no(pos, m, vp, dest); +} diff --git a/src/clipspace/project_zo.c b/src/clipspace/project_zo.c index 1496986..0d4110b 100644 --- a/src/clipspace/project_zo.c +++ b/src/clipspace/project_zo.c @@ -12,3 +12,9 @@ void glmc_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { glm_unprojecti_zo(pos, invMat, vp, dest); } + +CGLM_EXPORT +void +glmc_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest) { + glm_project_zo(pos, m, vp, dest); +} From 9096fa6bab13c9594086c1e5cca0c3352b6a447e Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 16 Aug 2021 14:27:12 +0300 Subject: [PATCH 2/5] fix include paths --- include/cglm/call/clipspace/ortho_lh_no.h | 2 +- include/cglm/call/clipspace/ortho_lh_zo.h | 2 +- include/cglm/call/clipspace/ortho_rh_no.h | 2 +- include/cglm/call/clipspace/ortho_rh_zo.h | 2 +- include/cglm/call/clipspace/persp_lh_no.h | 2 +- include/cglm/call/clipspace/persp_rh_no.h | 2 +- include/cglm/call/clipspace/persp_rh_zo.h | 2 +- include/cglm/call/clipspace/project_no.h | 2 +- include/cglm/call/clipspace/project_zo.h | 2 +- include/cglm/call/clipspace/view_lh_no.h | 2 +- include/cglm/call/clipspace/view_lh_zo.h | 2 +- include/cglm/call/clipspace/view_rh_no.h | 2 +- include/cglm/call/clipspace/view_rh_zo.h | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/cglm/call/clipspace/ortho_lh_no.h b/include/cglm/call/clipspace/ortho_lh_no.h index c19692c..3e26fa9 100644 --- a/include/cglm/call/clipspace/ortho_lh_no.h +++ b/include/cglm/call/clipspace/ortho_lh_no.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/ortho_lh_zo.h b/include/cglm/call/clipspace/ortho_lh_zo.h index 572182c..dc4c610 100644 --- a/include/cglm/call/clipspace/ortho_lh_zo.h +++ b/include/cglm/call/clipspace/ortho_lh_zo.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/ortho_rh_no.h b/include/cglm/call/clipspace/ortho_rh_no.h index c11acdc..dbba497 100644 --- a/include/cglm/call/clipspace/ortho_rh_no.h +++ b/include/cglm/call/clipspace/ortho_rh_no.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/ortho_rh_zo.h b/include/cglm/call/clipspace/ortho_rh_zo.h index ba8d9ae..e79ae83 100644 --- a/include/cglm/call/clipspace/ortho_rh_zo.h +++ b/include/cglm/call/clipspace/ortho_rh_zo.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/persp_lh_no.h b/include/cglm/call/clipspace/persp_lh_no.h index 25426a7..4bdbcfe 100644 --- a/include/cglm/call/clipspace/persp_lh_no.h +++ b/include/cglm/call/clipspace/persp_lh_no.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/persp_rh_no.h b/include/cglm/call/clipspace/persp_rh_no.h index 7909904..9c0d65d 100644 --- a/include/cglm/call/clipspace/persp_rh_no.h +++ b/include/cglm/call/clipspace/persp_rh_no.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/persp_rh_zo.h b/include/cglm/call/clipspace/persp_rh_zo.h index cf9f7dc..718d4ad 100644 --- a/include/cglm/call/clipspace/persp_rh_zo.h +++ b/include/cglm/call/clipspace/persp_rh_zo.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/project_no.h b/include/cglm/call/clipspace/project_no.h index 8c26c96..c62c37b 100644 --- a/include/cglm/call/clipspace/project_no.h +++ b/include/cglm/call/clipspace/project_no.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/project_zo.h b/include/cglm/call/clipspace/project_zo.h index d95a5fe..a7137bd 100644 --- a/include/cglm/call/clipspace/project_zo.h +++ b/include/cglm/call/clipspace/project_zo.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/view_lh_no.h b/include/cglm/call/clipspace/view_lh_no.h index 56066e8..3b58c84 100644 --- a/include/cglm/call/clipspace/view_lh_no.h +++ b/include/cglm/call/clipspace/view_lh_no.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/view_lh_zo.h b/include/cglm/call/clipspace/view_lh_zo.h index dbc5473..c877367 100644 --- a/include/cglm/call/clipspace/view_lh_zo.h +++ b/include/cglm/call/clipspace/view_lh_zo.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/view_rh_no.h b/include/cglm/call/clipspace/view_rh_no.h index ae16fcc..6303dbf 100644 --- a/include/cglm/call/clipspace/view_rh_no.h +++ b/include/cglm/call/clipspace/view_rh_no.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void diff --git a/include/cglm/call/clipspace/view_rh_zo.h b/include/cglm/call/clipspace/view_rh_zo.h index b70c15c..00b8707 100644 --- a/include/cglm/call/clipspace/view_rh_zo.h +++ b/include/cglm/call/clipspace/view_rh_zo.h @@ -11,7 +11,7 @@ extern "C" { #endif -#include "../cglm.h" +#include "../../cglm.h" CGLM_EXPORT void From 4c8f7f310c3b12f818c217744386e20626d764bd Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 16 Aug 2021 14:27:20 +0300 Subject: [PATCH 3/5] Update project_zo.h --- include/cglm/clipspace/project_zo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/clipspace/project_zo.h b/include/cglm/clipspace/project_zo.h index adc3597..98e58af 100644 --- a/include/cglm/clipspace/project_zo.h +++ b/include/cglm/clipspace/project_zo.h @@ -68,7 +68,7 @@ glm_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { */ CGLM_INLINE void -glm_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) { +glm_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest) { CGLM_ALIGN(16) vec4 pos4; glm_vec4(pos, 1.0f, pos4); From a2bd00df3234800a6342802bb93e072e13c31058 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 16 Aug 2021 15:51:52 +0300 Subject: [PATCH 4/5] fix including headers, and suppress warnings --- include/cglm/clipspace/ortho_lh_no.h | 1 + include/cglm/clipspace/ortho_lh_zo.h | 1 + include/cglm/clipspace/ortho_rh_no.h | 1 + include/cglm/clipspace/ortho_rh_zo.h | 1 + include/cglm/clipspace/persp_lh_no.h | 1 - include/cglm/clipspace/persp_lh_zo.h | 1 - include/cglm/clipspace/persp_rh_no.h | 1 - include/cglm/clipspace/persp_rh_zo.h | 1 - include/cglm/clipspace/view_lh_no.h | 1 + include/cglm/clipspace/view_lh_zo.h | 1 + include/cglm/clipspace/view_rh_no.h | 1 + include/cglm/clipspace/view_rh_zo.h | 1 + include/cglm/struct/quat.h | 2 +- src/clipspace/ortho_lh_no.c | 2 +- src/clipspace/ortho_lh_zo.c | 2 +- src/clipspace/ortho_rh_no.c | 2 +- src/clipspace/ortho_rh_zo.c | 2 +- src/clipspace/persp_lh_no.c | 1 + src/clipspace/persp_lh_zo.c | 1 + src/clipspace/persp_rh_no.c | 1 + src/clipspace/persp_rh_zo.c | 1 + src/clipspace/project_no.c | 1 + src/clipspace/project_zo.c | 1 + src/clipspace/view_lh_no.c | 2 +- src/clipspace/view_lh_zo.c | 2 +- src/clipspace/view_rh_no.c | 2 +- src/clipspace/view_rh_zo.c | 2 +- 27 files changed, 23 insertions(+), 13 deletions(-) diff --git a/include/cglm/clipspace/ortho_lh_no.h b/include/cglm/clipspace/ortho_lh_no.h index 24b0568..76c7a94 100644 --- a/include/cglm/clipspace/ortho_lh_no.h +++ b/include/cglm/clipspace/ortho_lh_no.h @@ -30,6 +30,7 @@ #include "../common.h" #include "../plane.h" +#include "../mat4.h" /*! * @brief set up orthographic projection matrix diff --git a/include/cglm/clipspace/ortho_lh_zo.h b/include/cglm/clipspace/ortho_lh_zo.h index f49f8f0..e45530d 100644 --- a/include/cglm/clipspace/ortho_lh_zo.h +++ b/include/cglm/clipspace/ortho_lh_zo.h @@ -30,6 +30,7 @@ #include "../common.h" #include "../plane.h" +#include "../mat4.h" /*! * @brief set up orthographic projection matrix with a left-hand coordinate diff --git a/include/cglm/clipspace/ortho_rh_no.h b/include/cglm/clipspace/ortho_rh_no.h index 1c833c9..aa7a906 100644 --- a/include/cglm/clipspace/ortho_rh_no.h +++ b/include/cglm/clipspace/ortho_rh_no.h @@ -30,6 +30,7 @@ #include "../common.h" #include "../plane.h" +#include "../mat4.h" /*! * @brief set up orthographic projection matrix diff --git a/include/cglm/clipspace/ortho_rh_zo.h b/include/cglm/clipspace/ortho_rh_zo.h index 9d9602e..7a0876c 100644 --- a/include/cglm/clipspace/ortho_rh_zo.h +++ b/include/cglm/clipspace/ortho_rh_zo.h @@ -30,6 +30,7 @@ #include "../common.h" #include "../plane.h" +#include "../mat4.h" /*! * @brief set up orthographic projection matrix with a right-hand coordinate diff --git a/include/cglm/clipspace/persp_lh_no.h b/include/cglm/clipspace/persp_lh_no.h index 2ab8d01..703530e 100644 --- a/include/cglm/clipspace/persp_lh_no.h +++ b/include/cglm/clipspace/persp_lh_no.h @@ -47,7 +47,6 @@ #define cglm_persp_lh_no_h #include "../common.h" -#include "../plane.h" #include "persp.h" /*! diff --git a/include/cglm/clipspace/persp_lh_zo.h b/include/cglm/clipspace/persp_lh_zo.h index 52a2648..de89643 100644 --- a/include/cglm/clipspace/persp_lh_zo.h +++ b/include/cglm/clipspace/persp_lh_zo.h @@ -47,7 +47,6 @@ #define cglm_persp_lh_zo_h #include "../common.h" -#include "../plane.h" #include "persp.h" /*! diff --git a/include/cglm/clipspace/persp_rh_no.h b/include/cglm/clipspace/persp_rh_no.h index 325e17b..021b7d8 100644 --- a/include/cglm/clipspace/persp_rh_no.h +++ b/include/cglm/clipspace/persp_rh_no.h @@ -47,7 +47,6 @@ #define cglm_persp_rh_no_h #include "../common.h" -#include "../plane.h" #include "persp.h" /*! diff --git a/include/cglm/clipspace/persp_rh_zo.h b/include/cglm/clipspace/persp_rh_zo.h index 0bcc175..ce632b3 100644 --- a/include/cglm/clipspace/persp_rh_zo.h +++ b/include/cglm/clipspace/persp_rh_zo.h @@ -47,7 +47,6 @@ #define cglm_persp_rh_zo_h #include "../common.h" -#include "../plane.h" #include "persp.h" /*! diff --git a/include/cglm/clipspace/view_lh_no.h b/include/cglm/clipspace/view_lh_no.h index 9e8d59c..454d903 100644 --- a/include/cglm/clipspace/view_lh_no.h +++ b/include/cglm/clipspace/view_lh_no.h @@ -15,6 +15,7 @@ #ifndef cglm_view_lh_no_h #define cglm_view_lh_no_h +#include "../common.h" #include "view_lh.h" /*! diff --git a/include/cglm/clipspace/view_lh_zo.h b/include/cglm/clipspace/view_lh_zo.h index 0652906..6b0c4d1 100644 --- a/include/cglm/clipspace/view_lh_zo.h +++ b/include/cglm/clipspace/view_lh_zo.h @@ -15,6 +15,7 @@ #ifndef cglm_view_lh_zo_h #define cglm_view_lh_zo_h +#include "../common.h" #include "view_lh.h" /*! diff --git a/include/cglm/clipspace/view_rh_no.h b/include/cglm/clipspace/view_rh_no.h index 14b8b4c..ca36d30 100644 --- a/include/cglm/clipspace/view_rh_no.h +++ b/include/cglm/clipspace/view_rh_no.h @@ -15,6 +15,7 @@ #ifndef cglm_view_rh_no_h #define cglm_view_rh_no_h +#include "../common.h" #include "view_rh.h" /*! diff --git a/include/cglm/clipspace/view_rh_zo.h b/include/cglm/clipspace/view_rh_zo.h index cbabe64..1ad5c91 100644 --- a/include/cglm/clipspace/view_rh_zo.h +++ b/include/cglm/clipspace/view_rh_zo.h @@ -15,6 +15,7 @@ #ifndef cglm_view_rh_zo_h #define cglm_view_rh_zo_h +#include "../common.h" #include "view_rh.h" /*! diff --git a/include/cglm/struct/quat.h b/include/cglm/struct/quat.h index 68a0929..d69675b 100644 --- a/include/cglm/struct/quat.h +++ b/include/cglm/struct/quat.h @@ -426,7 +426,7 @@ glms_quat_lerpc(versors from, versors to, float t) { * @param[in] from from * @param[in] to to * @param[in] t interpolant (amount) - * @param[out] dest result quaternion + * @returns result quaternion */ CGLM_INLINE versors diff --git a/src/clipspace/ortho_lh_no.c b/src/clipspace/ortho_lh_no.c index e83511d..839926a 100644 --- a/src/clipspace/ortho_lh_no.c +++ b/src/clipspace/ortho_lh_no.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../../include/cglm/cglm.h" #include "../../include/cglm/clipspace/ortho_lh_no.h" +#include "../../include/cglm/call/clipspace/ortho_lh_no.h" CGLM_EXPORT void diff --git a/src/clipspace/ortho_lh_zo.c b/src/clipspace/ortho_lh_zo.c index 155d53e..88291ac 100644 --- a/src/clipspace/ortho_lh_zo.c +++ b/src/clipspace/ortho_lh_zo.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../../include/cglm/cglm.h" #include "../../include/cglm/clipspace/ortho_lh_zo.h" +#include "../../include/cglm/call/clipspace/ortho_lh_zo.h" CGLM_EXPORT void diff --git a/src/clipspace/ortho_rh_no.c b/src/clipspace/ortho_rh_no.c index 7f9c02b..ca30e82 100644 --- a/src/clipspace/ortho_rh_no.c +++ b/src/clipspace/ortho_rh_no.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../../include/cglm/cglm.h" #include "../../include/cglm/clipspace/ortho_rh_no.h" +#include "../../include/cglm/call/clipspace/ortho_rh_no.h" CGLM_EXPORT void diff --git a/src/clipspace/ortho_rh_zo.c b/src/clipspace/ortho_rh_zo.c index 33cb83a..06d119b 100644 --- a/src/clipspace/ortho_rh_zo.c +++ b/src/clipspace/ortho_rh_zo.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../../include/cglm/cglm.h" #include "../../include/cglm/clipspace/ortho_rh_zo.h" +#include "../../include/cglm/call/clipspace/ortho_rh_zo.h" CGLM_EXPORT void diff --git a/src/clipspace/persp_lh_no.c b/src/clipspace/persp_lh_no.c index fe58385..8d6db76 100644 --- a/src/clipspace/persp_lh_no.c +++ b/src/clipspace/persp_lh_no.c @@ -6,6 +6,7 @@ */ #include "../../include/cglm/clipspace/persp_lh_no.h" +#include "../../include/cglm/call/clipspace/persp_lh_no.h" CGLM_EXPORT void diff --git a/src/clipspace/persp_lh_zo.c b/src/clipspace/persp_lh_zo.c index b0d5838..d9fec0c 100644 --- a/src/clipspace/persp_lh_zo.c +++ b/src/clipspace/persp_lh_zo.c @@ -6,6 +6,7 @@ */ #include "../../include/cglm/clipspace/persp_lh_zo.h" +#include "../../include/cglm/call/clipspace/persp_lh_zo.h" CGLM_EXPORT void diff --git a/src/clipspace/persp_rh_no.c b/src/clipspace/persp_rh_no.c index 56bd89b..8fc7735 100644 --- a/src/clipspace/persp_rh_no.c +++ b/src/clipspace/persp_rh_no.c @@ -6,6 +6,7 @@ */ #include "../../include/cglm/clipspace/persp_rh_no.h" +#include "../../include/cglm/call/clipspace/persp_rh_no.h" CGLM_EXPORT void diff --git a/src/clipspace/persp_rh_zo.c b/src/clipspace/persp_rh_zo.c index 03d7ac6..50190f2 100644 --- a/src/clipspace/persp_rh_zo.c +++ b/src/clipspace/persp_rh_zo.c @@ -6,6 +6,7 @@ */ #include "../../include/cglm/clipspace/persp_rh_zo.h" +#include "../../include/cglm/call/clipspace/persp_rh_zo.h" CGLM_EXPORT void diff --git a/src/clipspace/project_no.c b/src/clipspace/project_no.c index ceb8b0b..8352cba 100644 --- a/src/clipspace/project_no.c +++ b/src/clipspace/project_no.c @@ -6,6 +6,7 @@ */ #include "../../include/cglm/clipspace/project_no.h" +#include "../../include/cglm/call/clipspace/project_no.h" CGLM_EXPORT void diff --git a/src/clipspace/project_zo.c b/src/clipspace/project_zo.c index 0d4110b..bc480a0 100644 --- a/src/clipspace/project_zo.c +++ b/src/clipspace/project_zo.c @@ -6,6 +6,7 @@ */ #include "../../include/cglm/clipspace/project_zo.h" +#include "../../include/cglm/call/clipspace/project_zo.h" CGLM_EXPORT void diff --git a/src/clipspace/view_lh_no.c b/src/clipspace/view_lh_no.c index 8bed6a3..39f2a9d 100644 --- a/src/clipspace/view_lh_no.c +++ b/src/clipspace/view_lh_no.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../../include/cglm/cglm.h" #include "../../include/cglm/clipspace/view_lh_no.h" +#include "../../include/cglm/call/clipspace/view_lh_no.h" CGLM_EXPORT void diff --git a/src/clipspace/view_lh_zo.c b/src/clipspace/view_lh_zo.c index cee487c..a8680d9 100644 --- a/src/clipspace/view_lh_zo.c +++ b/src/clipspace/view_lh_zo.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../../include/cglm/cglm.h" #include "../../include/cglm/clipspace/view_lh_zo.h" +#include "../../include/cglm/call/clipspace/view_lh_zo.h" CGLM_EXPORT void diff --git a/src/clipspace/view_rh_no.c b/src/clipspace/view_rh_no.c index 3548ff2..6d60c08 100644 --- a/src/clipspace/view_rh_no.c +++ b/src/clipspace/view_rh_no.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../../include/cglm/cglm.h" #include "../../include/cglm/clipspace/view_rh_no.h" +#include "../../include/cglm/call/clipspace/view_rh_no.h" CGLM_EXPORT void diff --git a/src/clipspace/view_rh_zo.c b/src/clipspace/view_rh_zo.c index 537daee..5133fda 100644 --- a/src/clipspace/view_rh_zo.c +++ b/src/clipspace/view_rh_zo.c @@ -5,8 +5,8 @@ * Full license can be found in the LICENSE file */ -#include "../../include/cglm/cglm.h" #include "../../include/cglm/clipspace/view_rh_zo.h" +#include "../../include/cglm/call/clipspace/view_rh_zo.h" CGLM_EXPORT void From 8427d02a9b0192c216e990a0147cb2daa55730fd Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 16 Aug 2021 16:53:46 +0300 Subject: [PATCH 5/5] pick matrix helper (aka gluPickMatrix) --- CREDITS | 4 ++++ include/cglm/call/project.h | 4 ++++ include/cglm/project.h | 33 +++++++++++++++++++++++++++++++++ include/cglm/struct/project.h | 16 ++++++++++++++++ src/project.c | 6 ++++++ 5 files changed, 63 insertions(+) diff --git a/CREDITS b/CREDITS index c388348..00cc832 100644 --- a/CREDITS +++ b/CREDITS @@ -78,3 +78,7 @@ https://stackoverflow.com/a/57793352/2676533 16. ARM NEON Div http://github.com/microsoft/DirectXMath + +17. Pick Matrix + +glu project -> project.c diff --git a/include/cglm/call/project.h b/include/cglm/call/project.h index 35ac087..991ba1d 100644 --- a/include/cglm/call/project.h +++ b/include/cglm/call/project.h @@ -25,6 +25,10 @@ CGLM_EXPORT void glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest); +CGLM_EXPORT +void +glmc_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest); + #ifdef __cplusplus } #endif diff --git a/include/cglm/project.h b/include/cglm/project.h index ceeb528..45f38a7 100644 --- a/include/cglm/project.h +++ b/include/cglm/project.h @@ -114,4 +114,37 @@ glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { #endif } +/*! + * @brief define a picking region + * + * @param[in] center center [x, y] of a picking region in window coordinates + * @param[in] size size [width, height] of the picking region in window coordinates + * @param[in] vp viewport as [x, y, width, height] + * @param[out] dest projected coordinates + */ +CGLM_INLINE +void +glm_pickmatrix(vec3 center, vec2 size, vec4 vp, mat4 dest) { + mat4 res; + vec3 v; + + if (size[0] <= 0.0f || size[1] <= 0.0f) + return; + + /* Translate and scale the picked region to the entire window */ + v[0] = (vp[2] - 2.0f * (center[0] - vp[0])) / size[0]; + v[1] = (vp[3] - 2.0f * (center[1] - vp[1])) / size[1]; + v[2] = 0.0f; + + glm_translate_make(res, v); + + v[0] = vp[2] / size[0]; + v[1] = vp[3] / size[1]; + v[2] = 1.0f; + + glm_scale(res, v); + + glm_mat4_copy(res, dest); +} + #endif /* cglm_project_h */ diff --git a/include/cglm/struct/project.h b/include/cglm/struct/project.h index 8a2635f..130ff99 100644 --- a/include/cglm/struct/project.h +++ b/include/cglm/struct/project.h @@ -101,4 +101,20 @@ glms_project(vec3s pos, mat4s m, vec4s vp) { return r; } +/*! + * @brief define a picking region + * + * @param[in] center center [x, y] of a picking region in window coordinates + * @param[in] size size [width, height] of the picking region in window coordinates + * @param[in] vp viewport as [x, y, width, height] + * @returns projected coordinates + */ +CGLM_INLINE +mat4s +glms_pickmatrix(vec3s center, vec2s size, vec4s vp) { + mat4s res; + glm_pickmatrix(center.raw, size.raw, vp.raw, res.raw); + return res; +} + #endif /* cglms_projects_h */ diff --git a/src/project.c b/src/project.c index 91c7128..3e09ac6 100644 --- a/src/project.c +++ b/src/project.c @@ -25,3 +25,9 @@ void glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { glm_project(pos, m, vp, dest); } + +CGLM_EXPORT +void +glmc_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest) { + glm_pickmatrix(center, size, vp, dest); +}