From 1bce62c3716b1c20aeeac00c677031e905380f27 Mon Sep 17 00:00:00 2001 From: michaelg Date: Wed, 28 Apr 2021 23:15:51 +0100 Subject: [PATCH 01/13] Add function glm_perspective_lh_zo This commit adds the function `glm_perspective_lh_zo`, modelled on the implementation of glm_perspective, but amended to provide a left-hand coordinate system expected by DirectX, Metal and Vulkan (per the GLM project's `glm/detail/setup.hpp`). It uses a clip-space of zero-to-one. The function is tested against a longhand version of the algorithm it seeks to implement as well as against the output of the GLM project's `glm::perspectiveLH_ZO` function. This commit adds a new subdirectory `test/glm_cmp` which contains a basic CMake file and `main.cpp`. An interested user should link or copy or clone the GLM project into this directory. The `main` function can be used to print the reference data used so others can verify behaviour in the future, or add new literal reference values. --- .gitignore | 2 ++ README.md | 4 ++++ include/cglm/cam.h | 33 +++++++++++++++++++++++++++++++++ test/glm_cmp/.gitignore | 1 + test/glm_cmp/CMakeLists.txt | 12 ++++++++++++ test/glm_cmp/README.md | 8 ++++++++ test/glm_cmp/src/main.cpp | 24 ++++++++++++++++++++++++ test/src/test_cam.c | 34 ++++++++++++++++++++++++++++++++++ test/tests.h | 2 ++ 9 files changed, 120 insertions(+) create mode 100644 test/glm_cmp/.gitignore create mode 100644 test/glm_cmp/CMakeLists.txt create mode 100644 test/glm_cmp/README.md create mode 100644 test/glm_cmp/src/main.cpp diff --git a/.gitignore b/.gitignore index cfc01aa..24b3094 100644 --- a/.gitignore +++ b/.gitignore @@ -76,3 +76,5 @@ build/ conftest.dir/* confdefs.h *.xcuserdatad +.idea +cmake-build-debug diff --git a/README.md b/README.md index 76f1c51..a0f9c3d 100644 --- a/README.md +++ b/README.md @@ -394,6 +394,10 @@ You can pass matrices the same way to other APIs e.g. Vulkan, DX... - This library uses float types only, does not support Integers, Double... yet - If headers are not working properly with your compiler, IDE please open an issue, because I'm using GCC and clang to test it maybe sometimes MSVC +## Comparing cglm with glm results + +Contributors who wish to generate test results using the GLM library are pointed at the simple application in `test/glm_cmp`. A single file `test/glm_cmp/src/main.cpp` exists to which further functions can be added to print additional reference values. This is deliberately not part of the standard build. + **TODO:** - [ ] Unit tests (In Progress) - [ ] Unit tests for comparing cglm with glm results diff --git a/include/cglm/cam.h b/include/cglm/cam.h index e8f6595..610c06d 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -248,6 +248,39 @@ glm_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) { dest[3][2] = 2.0f * nearZ * farZ * fn; } +/*! + * @brief set up perspective projection matrix with a left-hand coordinate + * system (suitable for DirectX, Metal and Vulkan) and a clip-space with + * depth values from zero to one. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_lh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + /* Impl follows glm::perspectiveLH_ZO in glm/ext/matrix_clip_space.inl */ + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (farVal - nearVal); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] = farVal * fn; + dest[2][3] = 1.0f; + dest[3][2] = -(farVal * nearVal * fn); +} + /*! * @brief extend perspective projection matrix's far distance * diff --git a/test/glm_cmp/.gitignore b/test/glm_cmp/.gitignore new file mode 100644 index 0000000..671b764 --- /dev/null +++ b/test/glm_cmp/.gitignore @@ -0,0 +1 @@ +glm diff --git a/test/glm_cmp/CMakeLists.txt b/test/glm_cmp/CMakeLists.txt new file mode 100644 index 0000000..d0de862 --- /dev/null +++ b/test/glm_cmp/CMakeLists.txt @@ -0,0 +1,12 @@ +cmake_minimum_required(VERSION 3.17) +project(glm_cmp LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 14) +set(CMP_MAIN glmcmp) + +add_subdirectory(glm) + +add_executable(${CMP_MAIN} src/main.cpp) + +target_link_libraries(${CMP_MAIN} PRIVATE glm) + diff --git a/test/glm_cmp/README.md b/test/glm_cmp/README.md new file mode 100644 index 0000000..1c0c2ac --- /dev/null +++ b/test/glm_cmp/README.md @@ -0,0 +1,8 @@ +### Simple GLM app for quick generation of reference values + +#### Usage +1. Clone, link or copy the GLM library's root directory to `test/glm_cmp/glm`. +1. Ensuring your current directory is `test/glm_cmp`: + `mkdir build && cd build && cmake .. && make && ./glmcmp` + +Please do not delete prior reference-data-producing functions as it may be necessary to return to these to examine future bugs or assumptions. By all means remove or comment-out the call site from the `main` function, though, to focus on what you're working on. diff --git a/test/glm_cmp/src/main.cpp b/test/glm_cmp/src/main.cpp new file mode 100644 index 0000000..3d1ab8b --- /dev/null +++ b/test/glm_cmp/src/main.cpp @@ -0,0 +1,24 @@ +#include + +#include "glm/glm.hpp" +#include "glm/mat4x4.hpp" +#include + +static void outputForPerspectiveLH_ZO() { + const float fovy = glm::radians(45.0f); + const float aspect = 640/480.0f; + const float near = 0.1f; + const float far = 100.0f; + glm::mat4 cmp = glm::perspectiveLH_ZO(fovy, aspect, near, far); + puts("mat4 cmp = {0};"); + printf("cmp[0][0] = %0.7ff;\n", cmp[0][0]); + printf("cmp[1][1] = %0.7ff;\n", cmp[1][1]); + printf("cmp[2][2] = %0.7ff;\n", cmp[2][2]); + printf("cmp[2][3] = %0.7ff;\n", cmp[2][3]); + printf("cmp[3][2] = %0.7ff;\n", cmp[3][2]); +} + +int main(int argc, char** argv) { + outputForPerspectiveLH_ZO(); + return 0; +} diff --git a/test/src/test_cam.c b/test/src/test_cam.c index b5fbf2b..38a87fd 100644 --- a/test/src/test_cam.c +++ b/test/src/test_cam.c @@ -7,6 +7,40 @@ #include "test_common.h" +TEST_IMPL(perspective_lh_zo) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float near = 0.1f; + const float far = 100.0f; + + glm_perspective_lh_zo(fovy, aspect, near, far, dst); + + /* Sanity mk. I */ + /* Longhand version of what the above function _should_ be doing */ + ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], far / (far - near))) + ASSERT(test_eq(dst[2][3], 1.0f)) + ASSERT(test_eq(dst[3][2], -1 * far * near / (far - near))) + + /* Sanity mk. II */ + /* "Reference values" generated by GLM's glm::perspectiveLH_ZO */ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = 1.0010010f; + cmp[2][3] = 1.0000000f; + cmp[3][2] = -0.1001001f; + + for (uint32_t i = 0 ; i < 16 ; i++) { + uint32_t r = i%4, c = i/4; + ASSERT(fabsf(dst[r][c] - cmp[r][c]) < GLM_FLT_EPSILON) + } + + TEST_SUCCESS +} + TEST_IMPL(camera_lookat) { mat4 view1, view2; vec3 center, diff --git a/test/tests.h b/test/tests.h index be8d5d1..79795a7 100644 --- a/test/tests.h +++ b/test/tests.h @@ -223,6 +223,7 @@ TEST_DECLARE(glmc_mat2_swap_row) TEST_DECLARE(glmc_mat2_rmc) /* camera */ +TEST_DECLARE(perspective_lh_zo) TEST_DECLARE(camera_lookat) TEST_DECLARE(camera_decomp) @@ -947,6 +948,7 @@ TEST_LIST { TEST_ENTRY(glmc_mat2_rmc) /* camera */ + TEST_ENTRY(perspective_lh_zo) TEST_ENTRY(camera_lookat) TEST_ENTRY(camera_decomp) From b3a18b8a1573baaec7f5d4362354ddd452de3501 Mon Sep 17 00:00:00 2001 From: michaelg Date: Thu, 29 Apr 2021 23:48:13 +0100 Subject: [PATCH 02/13] Add glm_perspective_rh_zo function + tests This commit adds the RH/ZO perspective function. It does so in the new file `cam_rh_zo.h` and further refactors the LH variant into new file `cam_lh_zo.h`. This creates some churn in the tests and configuration files as new test files were added as well, and all these changes found their way into the build files. Tests passing on Linux. --- CMakeLists.txt | 2 ++ Makefile.am | 6 ++++ include/cglm/cam.h | 33 ---------------------- include/cglm/cam_lh_zo.h | 57 ++++++++++++++++++++++++++++++++++++++ include/cglm/cam_rh_zo.h | 58 +++++++++++++++++++++++++++++++++++++++ include/cglm/cglm.h | 2 ++ src/cam_lh_zo.c | 24 ++++++++++++++++ src/cam_rh_zo.c | 24 ++++++++++++++++ test/CMakeLists.txt | 2 ++ test/glm_cmp/src/main.cpp | 17 +++++++++++- test/src/test_cam.c | 34 ----------------------- test/src/test_cam_lh_zo.c | 37 +++++++++++++++++++++++++ test/src/test_cam_rh_zo.c | 37 +++++++++++++++++++++++++ test/tests.h | 6 ++-- 14 files changed, 269 insertions(+), 70 deletions(-) create mode 100644 include/cglm/cam_lh_zo.h create mode 100644 include/cglm/cam_rh_zo.h create mode 100644 src/cam_lh_zo.c create mode 100644 src/cam_rh_zo.c create mode 100644 test/src/test_cam_lh_zo.c create mode 100644 test/src/test_cam_rh_zo.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 206da0c..e2048ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,8 @@ add_library(${PROJECT_NAME} src/io.c src/quat.c src/cam.c + src/cam_lh_zo.c + src/cam_rh_zo.c src/vec2.c src/vec3.c src/vec4.c diff --git a/Makefile.am b/Makefile.am index e85faa4..f0e2afb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,6 +41,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/call.h \ include/cglm/struct.h \ include/cglm/cam.h \ + include/cglm/cam_lh_zo.h \ + include/cglm/cam_rh_zo.h \ include/cglm/io.h \ include/cglm/mat4.h \ include/cglm/mat3.h \ @@ -144,6 +146,8 @@ libcglm_la_SOURCES=\ src/io.c \ src/quat.c \ src/cam.c \ + src/cam_lh_zo.c \ + src/cam_rh_zo.c \ src/vec2.c \ src/vec3.c \ src/vec4.c \ @@ -166,6 +170,8 @@ test_tests_SOURCES=\ test/src/test_common.c \ test/src/tests.c \ test/src/test_cam.c \ + test/src/test_cam_lh_zo.c \ + test/src/test_cam_rh_zo.c \ test/src/test_clamp.c \ test/src/test_euler.c \ test/src/test_bezier.c \ diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 610c06d..e8f6595 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -248,39 +248,6 @@ glm_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) { dest[3][2] = 2.0f * nearZ * farZ * fn; } -/*! - * @brief set up perspective projection matrix with a left-hand coordinate - * system (suitable for DirectX, Metal and Vulkan) and a clip-space with - * depth values from zero to one. - * - * @param[in] fovy field of view angle - * @param[in] aspect aspect ratio ( width / height ) - * @param[in] nearVal near clipping plane - * @param[in] farVal far clipping planes - * @param[out] dest result matrix - */ -CGLM_INLINE -void -glm_perspective_lh_zo(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - /* Impl follows glm::perspectiveLH_ZO in glm/ext/matrix_clip_space.inl */ - float f, fn; - - glm_mat4_zero(dest); - - f = 1.0f / tanf(fovy * 0.5f); - fn = 1.0f / (farVal - nearVal); - - dest[0][0] = f / aspect; - dest[1][1] = f; - dest[2][2] = farVal * fn; - dest[2][3] = 1.0f; - dest[3][2] = -(farVal * nearVal * fn); -} - /*! * @brief extend perspective projection matrix's far distance * diff --git a/include/cglm/cam_lh_zo.h b/include/cglm/cam_lh_zo.h new file mode 100644 index 0000000..ca71ac3 --- /dev/null +++ b/include/cglm/cam_lh_zo.h @@ -0,0 +1,57 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_perspective_lh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) + */ + +#ifndef cglm_cam_lh_zo_h +#define cglm_cam_lh_zo_h + +#include "common.h" +#include "plane.h" + + +/*! + * @brief set up perspective projection matrix with a left-hand coordinate + * system (suitable, apparently, for DirectX and Metal) and a clip-space with + * depth values from zero to one. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_lh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + /* Impl follows glm::perspectiveLH_ZO in glm/ext/matrix_clip_space.inl */ + float fl, fn; + + glm_mat4_zero(dest); + + fl = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (farVal - nearVal); + + dest[0][0] = fl / aspect; + dest[1][1] = fl; + dest[2][2] = farVal * fn; + dest[2][3] = 1.0f; + dest[3][2] = -(farVal * nearVal * fn); +} + +#endif /*cglm_cam_lh_zo_h*/ diff --git a/include/cglm/cam_rh_zo.h b/include/cglm/cam_rh_zo.h new file mode 100644 index 0000000..5f8a81d --- /dev/null +++ b/include/cglm/cam_rh_zo.h @@ -0,0 +1,58 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_perspective_rh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) + */ + +#ifndef cglm_cam_rh_zo_h +#define cglm_cam_rh_zo_h + +#include "common.h" +#include "plane.h" + +/*! + * @brief set up perspective projection matrix with a right-hand coordinate + * system (suitable for Vulkan) and a clip-space with depth values from zero + * to one. + * + * https://github.com/godlikepanos/anki-3d-engine/blob/317cb379ff3a7b09f9034f49c7bdab0f96a1c0b3/AnKi/Math/Mat.h#L1254 + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_rh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + /* Impl follows glm::perspectiveRH_ZO in glm/ext/matrix_clip_space.inl */ + float fl, fn; + + glm_mat4_zero(dest); + + fl = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (farVal - nearVal); + + dest[0][0] = fl / aspect; + dest[1][1] = fl; + dest[2][2] = -farVal * fn; + dest[2][3] = -1.0f; + dest[3][2] = -farVal * nearVal * fn; +} + +#endif /*cglm_cam_lh_zo_h*/ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 5ff3421..b069d1d 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -17,6 +17,8 @@ #include "mat2.h" #include "affine.h" #include "cam.h" +#include "cam_lh_zo.h" +#include "cam_rh_zo.h" #include "frustum.h" #include "quat.h" #include "euler.h" diff --git a/src/cam_lh_zo.c b/src/cam_lh_zo.c new file mode 100644 index 0000000..50f0ca7 --- /dev/null +++ b/src/cam_lh_zo.c @@ -0,0 +1,24 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/cam_lh_zo.h" + +CGLM_EXPORT +void +glmc_perspective_lh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_lh_zo(fovy, + aspect, + nearVal, + farVal, + dest); +} + diff --git a/src/cam_rh_zo.c b/src/cam_rh_zo.c new file mode 100644 index 0000000..8c5712f --- /dev/null +++ b/src/cam_rh_zo.c @@ -0,0 +1,24 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/cam_rh_zo.h" + +CGLM_EXPORT +void +glmc_perspective_rh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_rh_zo(fovy, + aspect, + nearVal, + farVal, + dest); +} + diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b2a4fdc..2bf26a1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -6,6 +6,8 @@ set(TESTFILES src/test_euler.c src/test_bezier.c src/test_cam.c + src/test_cam_lh_zo.c + src/test_cam_rh_zo.c src/test_struct.c src/test_clamp.c src/test_common.c diff --git a/test/glm_cmp/src/main.cpp b/test/glm_cmp/src/main.cpp index 3d1ab8b..c594c02 100644 --- a/test/glm_cmp/src/main.cpp +++ b/test/glm_cmp/src/main.cpp @@ -10,6 +10,21 @@ static void outputForPerspectiveLH_ZO() { const float near = 0.1f; const float far = 100.0f; glm::mat4 cmp = glm::perspectiveLH_ZO(fovy, aspect, near, far); + puts("/*reference test data for glm_perspective_lh_zo*/"); + puts("mat4 cmp = {0};"); + printf("cmp[0][0] = %0.7ff;\n", cmp[0][0]); + printf("cmp[1][1] = %0.7ff;\n", cmp[1][1]); + printf("cmp[2][2] = %0.7ff;\n", cmp[2][2]); + printf("cmp[2][3] = %0.7ff;\n", cmp[2][3]); + printf("cmp[3][2] = %0.7ff;\n", cmp[3][2]); +} +static void outputForPerspectiveRH_ZO() { + const float fovy = glm::radians(45.0f); + const float aspect = 640/480.0f; + const float near = 0.1f; + const float far = 100.0f; + glm::mat4 cmp = glm::perspectiveRH_ZO(fovy, aspect, near, far); + puts("/*reference test data for glm_perspective_rh_zo*/"); puts("mat4 cmp = {0};"); printf("cmp[0][0] = %0.7ff;\n", cmp[0][0]); printf("cmp[1][1] = %0.7ff;\n", cmp[1][1]); @@ -19,6 +34,6 @@ static void outputForPerspectiveLH_ZO() { } int main(int argc, char** argv) { - outputForPerspectiveLH_ZO(); + outputForPerspectiveRH_ZO(); return 0; } diff --git a/test/src/test_cam.c b/test/src/test_cam.c index 38a87fd..b5fbf2b 100644 --- a/test/src/test_cam.c +++ b/test/src/test_cam.c @@ -7,40 +7,6 @@ #include "test_common.h" -TEST_IMPL(perspective_lh_zo) { - mat4 dst; - const float fovy = glm_rad(45.0f); - const float aspect = 640/480.0f; - const float near = 0.1f; - const float far = 100.0f; - - glm_perspective_lh_zo(fovy, aspect, near, far, dst); - - /* Sanity mk. I */ - /* Longhand version of what the above function _should_ be doing */ - ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect))) - ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2))) - ASSERT(test_eq(dst[2][2], far / (far - near))) - ASSERT(test_eq(dst[2][3], 1.0f)) - ASSERT(test_eq(dst[3][2], -1 * far * near / (far - near))) - - /* Sanity mk. II */ - /* "Reference values" generated by GLM's glm::perspectiveLH_ZO */ - mat4 cmp = {0}; - cmp[0][0] = 1.8106601f; - cmp[1][1] = 2.4142134f; - cmp[2][2] = 1.0010010f; - cmp[2][3] = 1.0000000f; - cmp[3][2] = -0.1001001f; - - for (uint32_t i = 0 ; i < 16 ; i++) { - uint32_t r = i%4, c = i/4; - ASSERT(fabsf(dst[r][c] - cmp[r][c]) < GLM_FLT_EPSILON) - } - - TEST_SUCCESS -} - TEST_IMPL(camera_lookat) { mat4 view1, view2; vec3 center, diff --git a/test/src/test_cam_lh_zo.c b/test/src/test_cam_lh_zo.c new file mode 100644 index 0000000..418229b --- /dev/null +++ b/test/src/test_cam_lh_zo.c @@ -0,0 +1,37 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(perspective_lh_zo) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_lh_zo(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I */ + /* Longhand version of what the above function _should_ be doing */ + ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], zFarVal / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], 1.0f)) + ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /* "Reference values" generated by GLM's glm::perspectiveLH_ZO */ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = 1.0010010f; + cmp[2][3] = 1.0000000f; + cmp[3][2] = -0.1001001f; + + return (test_assert_mat4_eq(dst, cmp)); +} diff --git a/test/src/test_cam_rh_zo.c b/test/src/test_cam_rh_zo.c new file mode 100644 index 0000000..c2cb5ba --- /dev/null +++ b/test/src/test_cam_rh_zo.c @@ -0,0 +1,37 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(perspective_rh_zo) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_rh_zo(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + float focal_len = 1 / tanf(fovy / 2); + ASSERT(test_eq(dst[0][0], focal_len / aspect)) + ASSERT(test_eq(dst[1][1], focal_len)) + ASSERT(test_eq(dst[2][2], zFarVal / (zNearVal - zFarVal))) + ASSERT(test_eq(dst[2][3], -1.0f)) + ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_rh_zo*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = -1.0010010f; + cmp[2][3] = -1.0000000f; + cmp[3][2] = -0.1001001f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/test/tests.h b/test/tests.h index 79795a7..137d38d 100644 --- a/test/tests.h +++ b/test/tests.h @@ -222,8 +222,9 @@ TEST_DECLARE(glmc_mat2_swap_col) TEST_DECLARE(glmc_mat2_swap_row) TEST_DECLARE(glmc_mat2_rmc) -/* camera */ +/* camera (incl [LR]H cross [NZ]O) */ TEST_DECLARE(perspective_lh_zo) +TEST_DECLARE(perspective_rh_zo) TEST_DECLARE(camera_lookat) TEST_DECLARE(camera_decomp) @@ -947,8 +948,9 @@ TEST_LIST { TEST_ENTRY(glmc_mat2_swap_row) TEST_ENTRY(glmc_mat2_rmc) - /* camera */ + /* camera (incl [LR]H cross [NZ]O) */ TEST_ENTRY(perspective_lh_zo) + TEST_ENTRY(perspective_rh_zo) TEST_ENTRY(camera_lookat) TEST_ENTRY(camera_decomp) From c013bd462cf4ade3432e7373cb96aeb855412f15 Mon Sep 17 00:00:00 2001 From: michaelg Date: Fri, 30 Apr 2021 21:53:17 +0100 Subject: [PATCH 03/13] Add LH & RH_NO perspective functions This commit adds functions `glm_perspective_lh_no` and `glm_perspective_rh_no` to the code. Unit tests are added and this commit follows the new pattern of adding the a new file per coordinate-system and clip-space tuple. . Makefile.am updated . removed test/glm_cmp project stub . unit tests include naive implementations to as well as magic number ref-data generated by the corresponding GLM functions. No tests run yet on Windows or Mac. --- CMakeLists.txt | 2 ++ Makefile.am | 6 ++++ include/cglm/cam_lh_no.h | 55 +++++++++++++++++++++++++++++++++++++ include/cglm/cam_lh_zo.h | 11 ++++---- include/cglm/cam_rh_no.h | 55 +++++++++++++++++++++++++++++++++++++ include/cglm/cam_rh_zo.h | 8 ++---- include/cglm/cglm.h | 2 ++ src/cam_lh_no.c | 23 ++++++++++++++++ src/cam_lh_zo.c | 1 - src/cam_rh_no.c | 23 ++++++++++++++++ src/cam_rh_zo.c | 1 - test/CMakeLists.txt | 2 ++ test/glm_cmp/.gitignore | 1 - test/glm_cmp/CMakeLists.txt | 12 -------- test/glm_cmp/README.md | 8 ------ test/glm_cmp/src/main.cpp | 39 -------------------------- test/src/test_cam_lh_no.c | 36 ++++++++++++++++++++++++ test/src/test_cam_lh_zo.c | 21 +++++++------- test/src/test_cam_rh_no.c | 36 ++++++++++++++++++++++++ test/src/test_cam_rh_zo.c | 9 +++--- test/tests.h | 4 +++ 21 files changed, 266 insertions(+), 89 deletions(-) create mode 100644 include/cglm/cam_lh_no.h create mode 100644 include/cglm/cam_rh_no.h create mode 100644 src/cam_lh_no.c create mode 100644 src/cam_rh_no.c delete mode 100644 test/glm_cmp/.gitignore delete mode 100644 test/glm_cmp/CMakeLists.txt delete mode 100644 test/glm_cmp/README.md delete mode 100644 test/glm_cmp/src/main.cpp create mode 100644 test/src/test_cam_lh_no.c create mode 100644 test/src/test_cam_rh_no.c diff --git a/CMakeLists.txt b/CMakeLists.txt index e2048ae..2359131 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,8 @@ add_library(${PROJECT_NAME} src/cam.c src/cam_lh_zo.c src/cam_rh_zo.c + src/cam_lh_no.c + src/cam_rh_no.c src/vec2.c src/vec3.c src/vec4.c diff --git a/Makefile.am b/Makefile.am index f0e2afb..5aaec3b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -43,6 +43,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/cam.h \ include/cglm/cam_lh_zo.h \ include/cglm/cam_rh_zo.h \ + include/cglm/cam_lh_no.h \ + include/cglm/cam_rh_no.h \ include/cglm/io.h \ include/cglm/mat4.h \ include/cglm/mat3.h \ @@ -148,6 +150,8 @@ libcglm_la_SOURCES=\ src/cam.c \ src/cam_lh_zo.c \ src/cam_rh_zo.c \ + src/cam_lh_no.c \ + src/cam_rh_no.c \ src/vec2.c \ src/vec3.c \ src/vec4.c \ @@ -172,6 +176,8 @@ test_tests_SOURCES=\ test/src/test_cam.c \ test/src/test_cam_lh_zo.c \ test/src/test_cam_rh_zo.c \ + test/src/test_cam_lh_no.c \ + test/src/test_cam_rh_no.c \ test/src/test_clamp.c \ test/src/test_euler.c \ test/src/test_bezier.c \ diff --git a/include/cglm/cam_lh_no.h b/include/cglm/cam_lh_no.h new file mode 100644 index 0000000..2c6a6ab --- /dev/null +++ b/include/cglm/cam_lh_no.h @@ -0,0 +1,55 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_perspective_lh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) + */ + +#ifndef cglm_cam_lh_no_h +#define cglm_cam_lh_no_h + +#include "common.h" +#include "plane.h" + +/*! + * @brief set up perspective projection matrix with a left-hand coordinate + * system and a clip-space of [-1, 1] + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_lh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + /* Impl follows glm::perspectiveLH_NO in glm/ext/matrix_clip_space.inl */ + float fl, fn; + + glm_mat4_zero(dest); + + fl = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (farVal - nearVal); + + dest[0][0] = fl / aspect; + dest[1][1] = fl; + dest[2][2] = (farVal + nearVal) * fn; + dest[2][3] = 1.0f; + dest[3][2] = -2.0f * farVal * nearVal * fn; +} + +#endif /*cglm_cam_lh_no_h*/ diff --git a/include/cglm/cam_lh_zo.h b/include/cglm/cam_lh_zo.h index ca71ac3..e800ff6 100644 --- a/include/cglm/cam_lh_zo.h +++ b/include/cglm/cam_lh_zo.h @@ -20,7 +20,6 @@ #include "common.h" #include "plane.h" - /*! * @brief set up perspective projection matrix with a left-hand coordinate * system (suitable, apparently, for DirectX and Metal) and a clip-space with @@ -47,11 +46,11 @@ glm_perspective_lh_zo(float fovy, fl = 1.0f / tanf(fovy * 0.5f); fn = 1.0f / (farVal - nearVal); - dest[0][0] = fl / aspect; - dest[1][1] = fl; - dest[2][2] = farVal * fn; - dest[2][3] = 1.0f; - dest[3][2] = -(farVal * nearVal * fn); + dest[0][0] = fl / aspect; + dest[1][1] = fl; + dest[2][2] = farVal * fn; + dest[2][3] = 1.0f; + dest[3][2] = -farVal * nearVal * fn; } #endif /*cglm_cam_lh_zo_h*/ diff --git a/include/cglm/cam_rh_no.h b/include/cglm/cam_rh_no.h new file mode 100644 index 0000000..71a99ad --- /dev/null +++ b/include/cglm/cam_rh_no.h @@ -0,0 +1,55 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_perspective_rh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) + */ + +#ifndef cglm_cam_rh_no_h +#define cglm_cam_rh_no_h + +#include "common.h" +#include "plane.h" + +/*! + * @brief set up perspective projection matrix with a right-hand coordinate + * system and a clip space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearVal near clipping plane + * @param[in] farVal far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_rh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + /* Impl follows glm::perspectiveRH_NO in glm/ext/matrix_clip_space.inl */ + float fl, fn; + + glm_mat4_zero(dest); + + fl = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (farVal - nearVal); + + dest[0][0] = fl / aspect; + dest[1][1] = fl; + dest[2][2] = -(farVal + nearVal) * fn; + dest[2][3] = -1.0f; + dest[3][2] = -2.0f * farVal * nearVal * fn; +} + +#endif /*cglm_cam_rh_no_h*/ diff --git a/include/cglm/cam_rh_zo.h b/include/cglm/cam_rh_zo.h index 5f8a81d..bdb08c2 100644 --- a/include/cglm/cam_rh_zo.h +++ b/include/cglm/cam_rh_zo.h @@ -25,8 +25,6 @@ * system (suitable for Vulkan) and a clip-space with depth values from zero * to one. * - * https://github.com/godlikepanos/anki-3d-engine/blob/317cb379ff3a7b09f9034f49c7bdab0f96a1c0b3/AnKi/Math/Mat.h#L1254 - * * @param[in] fovy field of view angle * @param[in] aspect aspect ratio ( width / height ) * @param[in] nearVal near clipping plane @@ -48,11 +46,11 @@ glm_perspective_rh_zo(float fovy, fl = 1.0f / tanf(fovy * 0.5f); fn = 1.0f / (farVal - nearVal); - dest[0][0] = fl / aspect; - dest[1][1] = fl; + dest[0][0] = fl / aspect; + dest[1][1] = fl; dest[2][2] = -farVal * fn; dest[2][3] = -1.0f; dest[3][2] = -farVal * nearVal * fn; } -#endif /*cglm_cam_lh_zo_h*/ +#endif /*cglm_cam_rh_zo_h*/ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index b069d1d..c6c2805 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -19,6 +19,8 @@ #include "cam.h" #include "cam_lh_zo.h" #include "cam_rh_zo.h" +#include "cam_lh_no.h" +#include "cam_rh_no.h" #include "frustum.h" #include "quat.h" #include "euler.h" diff --git a/src/cam_lh_no.c b/src/cam_lh_no.c new file mode 100644 index 0000000..4354373 --- /dev/null +++ b/src/cam_lh_no.c @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" + +CGLM_EXPORT +void +glmc_perspective_lh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_lh_no(fovy, + aspect, + nearVal, + farVal, + dest); +} + diff --git a/src/cam_lh_zo.c b/src/cam_lh_zo.c index 50f0ca7..a64dcd4 100644 --- a/src/cam_lh_zo.c +++ b/src/cam_lh_zo.c @@ -6,7 +6,6 @@ */ #include "../include/cglm/cglm.h" -#include "../include/cglm/cam_lh_zo.h" CGLM_EXPORT void diff --git a/src/cam_rh_no.c b/src/cam_rh_no.c new file mode 100644 index 0000000..3d7d4a8 --- /dev/null +++ b/src/cam_rh_no.c @@ -0,0 +1,23 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" + +CGLM_EXPORT +void +glmc_perspective_rh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_rh_no(fovy, + aspect, + nearVal, + farVal, + dest); +} + diff --git a/src/cam_rh_zo.c b/src/cam_rh_zo.c index 8c5712f..949a506 100644 --- a/src/cam_rh_zo.c +++ b/src/cam_rh_zo.c @@ -6,7 +6,6 @@ */ #include "../include/cglm/cglm.h" -#include "../include/cglm/cam_rh_zo.h" CGLM_EXPORT void diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 2bf26a1..26fef9c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -8,6 +8,8 @@ set(TESTFILES src/test_cam.c src/test_cam_lh_zo.c src/test_cam_rh_zo.c + src/test_cam_lh_no.c + src/test_cam_rh_no.c src/test_struct.c src/test_clamp.c src/test_common.c diff --git a/test/glm_cmp/.gitignore b/test/glm_cmp/.gitignore deleted file mode 100644 index 671b764..0000000 --- a/test/glm_cmp/.gitignore +++ /dev/null @@ -1 +0,0 @@ -glm diff --git a/test/glm_cmp/CMakeLists.txt b/test/glm_cmp/CMakeLists.txt deleted file mode 100644 index d0de862..0000000 --- a/test/glm_cmp/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -cmake_minimum_required(VERSION 3.17) -project(glm_cmp LANGUAGES CXX) - -set(CMAKE_CXX_STANDARD 14) -set(CMP_MAIN glmcmp) - -add_subdirectory(glm) - -add_executable(${CMP_MAIN} src/main.cpp) - -target_link_libraries(${CMP_MAIN} PRIVATE glm) - diff --git a/test/glm_cmp/README.md b/test/glm_cmp/README.md deleted file mode 100644 index 1c0c2ac..0000000 --- a/test/glm_cmp/README.md +++ /dev/null @@ -1,8 +0,0 @@ -### Simple GLM app for quick generation of reference values - -#### Usage -1. Clone, link or copy the GLM library's root directory to `test/glm_cmp/glm`. -1. Ensuring your current directory is `test/glm_cmp`: - `mkdir build && cd build && cmake .. && make && ./glmcmp` - -Please do not delete prior reference-data-producing functions as it may be necessary to return to these to examine future bugs or assumptions. By all means remove or comment-out the call site from the `main` function, though, to focus on what you're working on. diff --git a/test/glm_cmp/src/main.cpp b/test/glm_cmp/src/main.cpp deleted file mode 100644 index c594c02..0000000 --- a/test/glm_cmp/src/main.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include - -#include "glm/glm.hpp" -#include "glm/mat4x4.hpp" -#include - -static void outputForPerspectiveLH_ZO() { - const float fovy = glm::radians(45.0f); - const float aspect = 640/480.0f; - const float near = 0.1f; - const float far = 100.0f; - glm::mat4 cmp = glm::perspectiveLH_ZO(fovy, aspect, near, far); - puts("/*reference test data for glm_perspective_lh_zo*/"); - puts("mat4 cmp = {0};"); - printf("cmp[0][0] = %0.7ff;\n", cmp[0][0]); - printf("cmp[1][1] = %0.7ff;\n", cmp[1][1]); - printf("cmp[2][2] = %0.7ff;\n", cmp[2][2]); - printf("cmp[2][3] = %0.7ff;\n", cmp[2][3]); - printf("cmp[3][2] = %0.7ff;\n", cmp[3][2]); -} -static void outputForPerspectiveRH_ZO() { - const float fovy = glm::radians(45.0f); - const float aspect = 640/480.0f; - const float near = 0.1f; - const float far = 100.0f; - glm::mat4 cmp = glm::perspectiveRH_ZO(fovy, aspect, near, far); - puts("/*reference test data for glm_perspective_rh_zo*/"); - puts("mat4 cmp = {0};"); - printf("cmp[0][0] = %0.7ff;\n", cmp[0][0]); - printf("cmp[1][1] = %0.7ff;\n", cmp[1][1]); - printf("cmp[2][2] = %0.7ff;\n", cmp[2][2]); - printf("cmp[2][3] = %0.7ff;\n", cmp[2][3]); - printf("cmp[3][2] = %0.7ff;\n", cmp[3][2]); -} - -int main(int argc, char** argv) { - outputForPerspectiveRH_ZO(); - return 0; -} diff --git a/test/src/test_cam_lh_no.c b/test/src/test_cam_lh_no.c new file mode 100644 index 0000000..33a285a --- /dev/null +++ b/test/src/test_cam_lh_no.c @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(perspective_lh_no) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_lh_no(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], (zFarVal + zNearVal) / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], 1.0f)) + ASSERT(test_eq(dst[3][2], -2 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_lh_no*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = 1.0020020f; + cmp[2][3] = 1.0000000f; + cmp[3][2] = -0.2002002f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/test/src/test_cam_lh_zo.c b/test/src/test_cam_lh_zo.c index 418229b..f5f50af 100644 --- a/test/src/test_cam_lh_zo.c +++ b/test/src/test_cam_lh_zo.c @@ -16,22 +16,21 @@ TEST_IMPL(perspective_lh_zo) { glm_perspective_lh_zo(fovy, aspect, zNearVal, zFarVal, dst); - /* Sanity mk. I */ - /* Longhand version of what the above function _should_ be doing */ - ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect))) - ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2))) - ASSERT(test_eq(dst[2][2], zFarVal / (zFarVal - zNearVal))) - ASSERT(test_eq(dst[2][3], 1.0f)) + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], zFarVal / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], 1.0f)) ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) /* Sanity mk. II */ /* "Reference values" generated by GLM's glm::perspectiveLH_ZO */ mat4 cmp = {0}; - cmp[0][0] = 1.8106601f; - cmp[1][1] = 2.4142134f; - cmp[2][2] = 1.0010010f; - cmp[2][3] = 1.0000000f; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = 1.0010010f; + cmp[2][3] = 1.0000000f; cmp[3][2] = -0.1001001f; - return (test_assert_mat4_eq(dst, cmp)); + return test_assert_mat4_eq(dst, cmp); } diff --git a/test/src/test_cam_rh_no.c b/test/src/test_cam_rh_no.c new file mode 100644 index 0000000..2bcadcd --- /dev/null +++ b/test/src/test_cam_rh_no.c @@ -0,0 +1,36 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "test_common.h" + +TEST_IMPL(perspective_rh_no) { + mat4 dst; + const float fovy = glm_rad(45.0f); + const float aspect = 640/480.0f; + const float zNearVal = 0.1f; + const float zFarVal = 100.0f; + + glm_perspective_rh_no(fovy, aspect, zNearVal, zFarVal, dst); + + /* Sanity mk. I: longhand version */ + ASSERT(test_eq(dst[0][0], 1.0f / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1.0f / tanf(fovy / 2))) + ASSERT(test_eq(dst[2][2], -1.0f * (zFarVal + zNearVal) / (zFarVal - zNearVal))) + ASSERT(test_eq(dst[2][3], -1.0f)) + ASSERT(test_eq(dst[3][2], -2 * zFarVal * zNearVal / (zFarVal - zNearVal))) + + /* Sanity mk. II */ + /*reference test data for glm_perspective_rh_no*/ + mat4 cmp = {0}; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; + cmp[2][2] = -1.0020020f; + cmp[2][3] = -1.0000000f; + cmp[3][2] = -0.2002002f; + + return test_assert_mat4_eq(dst, cmp); +} diff --git a/test/src/test_cam_rh_zo.c b/test/src/test_cam_rh_zo.c index c2cb5ba..95281a7 100644 --- a/test/src/test_cam_rh_zo.c +++ b/test/src/test_cam_rh_zo.c @@ -17,9 +17,8 @@ TEST_IMPL(perspective_rh_zo) { glm_perspective_rh_zo(fovy, aspect, zNearVal, zFarVal, dst); /* Sanity mk. I: longhand version */ - float focal_len = 1 / tanf(fovy / 2); - ASSERT(test_eq(dst[0][0], focal_len / aspect)) - ASSERT(test_eq(dst[1][1], focal_len)) + ASSERT(test_eq(dst[0][0], 1 / (tanf(fovy / 2) * aspect))) + ASSERT(test_eq(dst[1][1], 1 / tanf(fovy / 2))) ASSERT(test_eq(dst[2][2], zFarVal / (zNearVal - zFarVal))) ASSERT(test_eq(dst[2][3], -1.0f)) ASSERT(test_eq(dst[3][2], -1 * zFarVal * zNearVal / (zFarVal - zNearVal))) @@ -27,8 +26,8 @@ TEST_IMPL(perspective_rh_zo) { /* Sanity mk. II */ /*reference test data for glm_perspective_rh_zo*/ mat4 cmp = {0}; - cmp[0][0] = 1.8106601f; - cmp[1][1] = 2.4142134f; + cmp[0][0] = 1.8106601f; + cmp[1][1] = 2.4142134f; cmp[2][2] = -1.0010010f; cmp[2][3] = -1.0000000f; cmp[3][2] = -0.1001001f; diff --git a/test/tests.h b/test/tests.h index 137d38d..d5688e2 100644 --- a/test/tests.h +++ b/test/tests.h @@ -225,6 +225,8 @@ TEST_DECLARE(glmc_mat2_rmc) /* camera (incl [LR]H cross [NZ]O) */ TEST_DECLARE(perspective_lh_zo) TEST_DECLARE(perspective_rh_zo) +TEST_DECLARE(perspective_lh_no) +TEST_DECLARE(perspective_rh_no) TEST_DECLARE(camera_lookat) TEST_DECLARE(camera_decomp) @@ -951,6 +953,8 @@ TEST_LIST { /* camera (incl [LR]H cross [NZ]O) */ TEST_ENTRY(perspective_lh_zo) TEST_ENTRY(perspective_rh_zo) + TEST_ENTRY(perspective_lh_no) + TEST_ENTRY(perspective_rh_no) TEST_ENTRY(camera_lookat) TEST_ENTRY(camera_decomp) From db46ea110a1cd08a860d95ff36016b5b375bfe6a Mon Sep 17 00:00:00 2001 From: michaelg Date: Fri, 30 Apr 2021 22:01:50 +0100 Subject: [PATCH 04/13] Updated README.md to remove ref to `glm_cmp` stub --- README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/README.md b/README.md index a0f9c3d..76f1c51 100644 --- a/README.md +++ b/README.md @@ -394,10 +394,6 @@ You can pass matrices the same way to other APIs e.g. Vulkan, DX... - This library uses float types only, does not support Integers, Double... yet - If headers are not working properly with your compiler, IDE please open an issue, because I'm using GCC and clang to test it maybe sometimes MSVC -## Comparing cglm with glm results - -Contributors who wish to generate test results using the GLM library are pointed at the simple application in `test/glm_cmp`. A single file `test/glm_cmp/src/main.cpp` exists to which further functions can be added to print additional reference values. This is deliberately not part of the standard build. - **TODO:** - [ ] Unit tests (In Progress) - [ ] Unit tests for comparing cglm with glm results From 7065011bf393dc298f52d1e414c99fbe6a07113a Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Wed, 5 May 2021 05:13:47 +0200 Subject: [PATCH 05/13] clipspace: add initial implementations LH, RH and NO, ZO Add the initial implementations of the left-handed and right-handed coordinate systems as well as clipspace depth values of [-1, 0] and [0, 1]. --- CMakeLists.txt | 17 +- Makefile.am | 21 +- include/cglm/call/clipspace/ortho_lh_no.h | 46 +++ include/cglm/call/clipspace/ortho_lh_zo.h | 46 +++ include/cglm/call/clipspace/ortho_rh_no.h | 46 +++ include/cglm/call/clipspace/ortho_rh_zo.h | 46 +++ include/cglm/call/clipspace/persp_lh_no.h | 87 +++++ include/cglm/call/clipspace/persp_lh_zo.h | 87 +++++ include/cglm/call/clipspace/persp_rh_no.h | 87 +++++ include/cglm/call/clipspace/persp_rh_zo.h | 87 +++++ include/cglm/call/clipspace/view_lh_no.h | 31 ++ include/cglm/call/clipspace/view_lh_zo.h | 31 ++ include/cglm/call/clipspace/view_rh_no.h | 31 ++ include/cglm/call/clipspace/view_rh_zo.h | 31 ++ include/cglm/cam.h | 424 +++++++++++----------- include/cglm/cam_lh_no.h | 55 --- include/cglm/cam_lh_zo.h | 56 --- include/cglm/cam_rh_no.h | 55 --- include/cglm/cam_rh_zo.h | 56 --- include/cglm/cglm.h | 4 - include/cglm/clipspace/ortho_lh_no.h | 182 ++++++++++ include/cglm/clipspace/ortho_lh_zo.h | 180 +++++++++ include/cglm/clipspace/ortho_rh_no.h | 182 ++++++++++ include/cglm/clipspace/ortho_rh_zo.h | 180 +++++++++ include/cglm/clipspace/persp.h | 48 +++ include/cglm/clipspace/persp_lh_no.h | 396 ++++++++++++++++++++ include/cglm/clipspace/persp_lh_zo.h | 388 ++++++++++++++++++++ include/cglm/clipspace/persp_rh_no.h | 396 ++++++++++++++++++++ include/cglm/clipspace/persp_rh_zo.h | 390 ++++++++++++++++++++ include/cglm/clipspace/view_lh.h | 99 +++++ include/cglm/clipspace/view_lh_no.h | 73 ++++ include/cglm/clipspace/view_lh_zo.h | 73 ++++ include/cglm/clipspace/view_rh.h | 99 +++++ include/cglm/clipspace/view_rh_no.h | 73 ++++ include/cglm/clipspace/view_rh_zo.h | 73 ++++ include/cglm/common.h | 31 ++ include/cglm/plane.h | 1 + meson.build | 14 +- src/cam_lh_no.c | 23 -- src/cam_lh_zo.c | 23 -- src/cam_rh_no.c | 23 -- src/cam_rh_zo.c | 23 -- src/clipspace/ortho_lh_no.c | 51 +++ src/clipspace/ortho_lh_zo.c | 51 +++ src/clipspace/ortho_rh_no.c | 51 +++ src/clipspace/ortho_rh_zo.c | 51 +++ src/clipspace/persp_lh_no.c | 109 ++++++ src/clipspace/persp_lh_zo.c | 109 ++++++ src/clipspace/persp_rh_no.c | 109 ++++++ src/clipspace/persp_rh_zo.c | 109 ++++++ src/clipspace/view_lh_no.c | 27 ++ src/clipspace/view_lh_zo.c | 27 ++ src/clipspace/view_rh_no.c | 27 ++ src/clipspace/view_rh_zo.c | 27 ++ test/include/common.h | 4 + win/cglm.vcxproj | 29 +- 56 files changed, 4558 insertions(+), 537 deletions(-) create mode 100644 include/cglm/call/clipspace/ortho_lh_no.h create mode 100644 include/cglm/call/clipspace/ortho_lh_zo.h create mode 100644 include/cglm/call/clipspace/ortho_rh_no.h create mode 100644 include/cglm/call/clipspace/ortho_rh_zo.h create mode 100644 include/cglm/call/clipspace/persp_lh_no.h create mode 100644 include/cglm/call/clipspace/persp_lh_zo.h create mode 100644 include/cglm/call/clipspace/persp_rh_no.h create mode 100644 include/cglm/call/clipspace/persp_rh_zo.h create mode 100644 include/cglm/call/clipspace/view_lh_no.h create mode 100644 include/cglm/call/clipspace/view_lh_zo.h create mode 100644 include/cglm/call/clipspace/view_rh_no.h create mode 100644 include/cglm/call/clipspace/view_rh_zo.h delete mode 100644 include/cglm/cam_lh_no.h delete mode 100644 include/cglm/cam_lh_zo.h delete mode 100644 include/cglm/cam_rh_no.h delete mode 100644 include/cglm/cam_rh_zo.h create mode 100644 include/cglm/clipspace/ortho_lh_no.h create mode 100644 include/cglm/clipspace/ortho_lh_zo.h create mode 100644 include/cglm/clipspace/ortho_rh_no.h create mode 100644 include/cglm/clipspace/ortho_rh_zo.h create mode 100644 include/cglm/clipspace/persp.h create mode 100644 include/cglm/clipspace/persp_lh_no.h create mode 100644 include/cglm/clipspace/persp_lh_zo.h create mode 100644 include/cglm/clipspace/persp_rh_no.h create mode 100644 include/cglm/clipspace/persp_rh_zo.h create mode 100644 include/cglm/clipspace/view_lh.h create mode 100644 include/cglm/clipspace/view_lh_no.h create mode 100644 include/cglm/clipspace/view_lh_zo.h create mode 100644 include/cglm/clipspace/view_rh.h create mode 100644 include/cglm/clipspace/view_rh_no.h create mode 100644 include/cglm/clipspace/view_rh_zo.h delete mode 100644 src/cam_lh_no.c delete mode 100644 src/cam_lh_zo.c delete mode 100644 src/cam_rh_no.c delete mode 100644 src/cam_rh_zo.c create mode 100644 src/clipspace/ortho_lh_no.c create mode 100644 src/clipspace/ortho_lh_zo.c create mode 100644 src/clipspace/ortho_rh_no.c create mode 100644 src/clipspace/ortho_rh_zo.c create mode 100644 src/clipspace/persp_lh_no.c create mode 100644 src/clipspace/persp_lh_zo.c create mode 100644 src/clipspace/persp_rh_no.c create mode 100644 src/clipspace/persp_rh_zo.c create mode 100644 src/clipspace/view_lh_no.c create mode 100644 src/clipspace/view_lh_zo.c create mode 100644 src/clipspace/view_rh_no.c create mode 100644 src/clipspace/view_rh_zo.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2359131..a6e27fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,10 +57,7 @@ add_library(${PROJECT_NAME} src/io.c src/quat.c src/cam.c - src/cam_lh_zo.c - src/cam_rh_zo.c - src/cam_lh_no.c - src/cam_rh_no.c + src/vec2.c src/vec2.c src/vec3.c src/vec4.c @@ -77,6 +74,18 @@ add_library(${PROJECT_NAME} src/bezier.c src/ray.c src/affine2d.c + src/clipspace/persp_lh_zo.c + src/clipspace/persp_rh_zo.c + src/clipspace/persp_lh_no.c + src/clipspace/persp_rh_no.c + src/clipspace/ortho_lh_zo.c + src/clipspace/ortho_rh_zo.c + src/clipspace/ortho_lh_no.c + src/clipspace/ortho_rh_no.c + src/clipspace/view_lh_zo.c + src/clipspace/view_rh_zo.c + src/clipspace/view_lh_no.c + src/clipspace/view_rh_no.c ) if(CGLM_SHARED) diff --git a/Makefile.am b/Makefile.am index 5aaec3b..a2b8a41 100644 --- a/Makefile.am +++ b/Makefile.am @@ -41,10 +41,6 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/call.h \ include/cglm/struct.h \ include/cglm/cam.h \ - include/cglm/cam_lh_zo.h \ - include/cglm/cam_rh_zo.h \ - include/cglm/cam_lh_no.h \ - include/cglm/cam_rh_no.h \ include/cglm/io.h \ include/cglm/mat4.h \ include/cglm/mat3.h \ @@ -73,6 +69,23 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/ray.h \ include/cglm/affine2d.h +cglm_clipspacedir=$(includedir)/cglm/clipspace +cglm_clipspace_HEADERS = include/cglm/clipspace/persp.h \ + include/cglm/clipspace/persp_lh_zo.h \ + include/cglm/clipspace/persp_rh_zo.h \ + include/cglm/clipspace/persp_lh_no.h \ + include/cglm/clipspace/persp_rh_no.h \ + include/cglm/clipspace/ortho_lh_zo.h \ + include/cglm/clipspace/ortho_rh_zo.h \ + include/cglm/clipspace/ortho_lh_no.h \ + include/cglm/clipspace/ortho_rh_no.h \ + include/cglm/clipspace/view_lh.h \ + include/cglm/clipspace/view_rh.h \ + include/cglm/clipspace/view_lh_zo.h \ + include/cglm/clipspace/view_rh_zo.h \ + include/cglm/clipspace/view_lh_no.h \ + include/cglm/clipspace/view_rh_no.h + cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/mat3.h \ diff --git a/include/cglm/call/clipspace/ortho_lh_no.h b/include/cglm/call/clipspace/ortho_lh_no.h new file mode 100644 index 0000000..3fc72a1 --- /dev/null +++ b/include/cglm/call/clipspace/ortho_lh_no.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ortho_lh_no_h +#define cglmc_ortho_lh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_lh_no(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p_lh_no(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_lh_no(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_lh_no(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s_lh_no(float aspect, float size, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ortho_lh_no_h */ diff --git a/include/cglm/call/clipspace/ortho_lh_zo.h b/include/cglm/call/clipspace/ortho_lh_zo.h new file mode 100644 index 0000000..81af396 --- /dev/null +++ b/include/cglm/call/clipspace/ortho_lh_zo.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ortho_lh_zo_h +#define cglmc_ortho_lh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_lh_zo(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_lh_zo(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s_lh_zo(float aspect, float size, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ortho_lh_zo_h */ diff --git a/include/cglm/call/clipspace/ortho_rh_no.h b/include/cglm/call/clipspace/ortho_rh_no.h new file mode 100644 index 0000000..8ffd9de --- /dev/null +++ b/include/cglm/call/clipspace/ortho_rh_no.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ortho_rh_no_h +#define cglmc_ortho_rh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_rh_no(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_rh_no(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s_rh_no(float aspect, float size, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ortho_rh_no_h */ diff --git a/include/cglm/call/clipspace/ortho_rh_zo.h b/include/cglm/call/clipspace/ortho_rh_zo.h new file mode 100644 index 0000000..98572a3 --- /dev/null +++ b/include/cglm/call/clipspace/ortho_rh_zo.h @@ -0,0 +1,46 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_ortho_rh_zo_h +#define cglmc_ortho_rh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_rh_zo(vec3 box[2], mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_p_rh_zo(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_rh_zo(vec3 box[2], float padding, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_rh_zo(float aspect, mat4 dest); + +CGLM_EXPORT +void +glmc_ortho_default_s_rh_zo(float aspect, float size, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_ortho_rh_zo_h */ diff --git a/include/cglm/call/clipspace/persp_lh_no.h b/include/cglm/call/clipspace/persp_lh_no.h new file mode 100644 index 0000000..badd081 --- /dev/null +++ b/include/cglm/call/clipspace/persp_lh_no.h @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_persp_lh_no_h +#define cglmc_persp_lh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_lh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far_lh_no(mat4 proj, float deltaFar); + +CGLM_EXPORT +void +glmc_persp_decomp_lh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv_lh_no(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x_lh_no(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y_lh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ); + +CGLM_EXPORT +void +glmc_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest); + +CGLM_EXPORT +float +glmc_persp_fovy_lh_no(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect_lh_no(mat4 proj); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_persp_lh_no_h */ diff --git a/include/cglm/call/clipspace/persp_lh_zo.h b/include/cglm/call/clipspace/persp_lh_zo.h new file mode 100644 index 0000000..cbe79d9 --- /dev/null +++ b/include/cglm/call/clipspace/persp_lh_zo.h @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_persp_lh_zo_h +#define cglmc_persp_lh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_lh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar); + +CGLM_EXPORT +void +glmc_persp_decomp_lh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv_lh_zo(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x_lh_zo(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y_lh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ); + +CGLM_EXPORT +void +glmc_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest); + +CGLM_EXPORT +float +glmc_persp_fovy_lh_zo(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect_lh_zo(mat4 proj); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_persp_lh_zo_h */ diff --git a/include/cglm/call/clipspace/persp_rh_no.h b/include/cglm/call/clipspace/persp_rh_no.h new file mode 100644 index 0000000..b4537ef --- /dev/null +++ b/include/cglm/call/clipspace/persp_rh_no.h @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_persp_rh_no_h +#define cglmc_persp_rh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_rh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far_rh_no(mat4 proj, float deltaFar); + +CGLM_EXPORT +void +glmc_persp_decomp_rh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv_rh_no(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x_rh_no(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y_rh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ); + +CGLM_EXPORT +void +glmc_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest); + +CGLM_EXPORT +float +glmc_persp_fovy_rh_no(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect_rh_no(mat4 proj); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_persp_rh_no_h */ diff --git a/include/cglm/call/clipspace/persp_rh_zo.h b/include/cglm/call/clipspace/persp_rh_zo.h new file mode 100644 index 0000000..4ea0945 --- /dev/null +++ b/include/cglm/call/clipspace/persp_rh_zo.h @@ -0,0 +1,87 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_persp_rh_zo_h +#define cglmc_persp_rh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest); + +CGLM_EXPORT +void +glmc_perspective_rh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest); + +CGLM_EXPORT +void +glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar); + +CGLM_EXPORT +void +glmc_persp_decomp_rh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decompv_rh_zo(mat4 proj, float dest[6]); + +CGLM_EXPORT +void +glmc_persp_decomp_x_rh_zo(mat4 proj, + float * __restrict left, + float * __restrict right); + +CGLM_EXPORT +void +glmc_persp_decomp_y_rh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom); + +CGLM_EXPORT +void +glmc_persp_decomp_z_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ); + +CGLM_EXPORT +void +glmc_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ); + +CGLM_EXPORT +void +glmc_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest); + +CGLM_EXPORT +float +glmc_persp_fovy_rh_zo(mat4 proj); + +CGLM_EXPORT +float +glmc_persp_aspect_rh_zo(mat4 proj); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_persp_rh_zo_h */ diff --git a/include/cglm/call/clipspace/view_lh_no.h b/include/cglm/call/clipspace/view_lh_no.h new file mode 100644 index 0000000..56066e8 --- /dev/null +++ b/include/cglm/call/clipspace/view_lh_no.h @@ -0,0 +1,31 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_view_lh_no_h +#define cglmc_view_lh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_view_lh_no_h */ diff --git a/include/cglm/call/clipspace/view_lh_zo.h b/include/cglm/call/clipspace/view_lh_zo.h new file mode 100644 index 0000000..dbc5473 --- /dev/null +++ b/include/cglm/call/clipspace/view_lh_zo.h @@ -0,0 +1,31 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_view_lh_zo_h +#define cglmc_view_lh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_view_lh_zo_h */ diff --git a/include/cglm/call/clipspace/view_rh_no.h b/include/cglm/call/clipspace/view_rh_no.h new file mode 100644 index 0000000..ae16fcc --- /dev/null +++ b/include/cglm/call/clipspace/view_rh_no.h @@ -0,0 +1,31 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_view_rh_no_h +#define cglmc_view_rh_no_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_view_rh_no_h */ diff --git a/include/cglm/call/clipspace/view_rh_zo.h b/include/cglm/call/clipspace/view_rh_zo.h new file mode 100644 index 0000000..b70c15c --- /dev/null +++ b/include/cglm/call/clipspace/view_rh_zo.h @@ -0,0 +1,31 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_view_rh_zo_h +#define cglmc_view_rh_zo_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +void +glmc_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest); + +CGLM_EXPORT +void +glmc_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest); + +#ifdef __cplusplus +} +#endif +#endif /* cglmc_view_rh_zo_h */ diff --git a/include/cglm/cam.h b/include/cglm/cam.h index e8f6595..8dfac93 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -45,12 +45,47 @@ CGLM_INLINE void glm_persp_sizes(mat4 proj, float fovy, vec4 dest) */ -#ifndef cglm_vcam_h -#define cglm_vcam_h +#ifndef cglm_cam_h +#define cglm_cam_h #include "common.h" #include "plane.h" +#include "clipspace/persp.h" + +#ifndef CGLM_CLIPSPACE_INCLUDE_ALL +# if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO +# include "clipspace/ortho_lh_zo.h" +# include "clipspace/persp_lh_zo.h" +# include "clipspace/view_lh_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO +# include "clipspace/ortho_lh_no.h" +# include "clipspace/persp_lh_no.h" +# include "clipspace/view_lh_no.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO +# include "clipspace/ortho_rh_zo.h" +# include "clipspace/persp_rh_zo.h" +# include "clipspace/view_rh_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO +# include "clipspace/ortho_rh_no.h" +# include "clipspace/persp_rh_no.h" +# include "clipspace/view_rh_no.h" +# endif +#else +# include "clipspace/ortho_lh_zo.h" +# include "clipspace/persp_lh_zo.h" +# include "clipspace/ortho_lh_no.h" +# include "clipspace/persp_lh_no.h" +# include "clipspace/ortho_rh_zo.h" +# include "clipspace/persp_rh_zo.h" +# include "clipspace/ortho_rh_no.h" +# include "clipspace/persp_rh_no.h" +# include "clipspace/view_lh_zo.h" +# include "clipspace/view_lh_no.h" +# include "clipspace/view_rh_zo.h" +# include "clipspace/view_rh_no.h" +#endif + /*! * @brief set up perspective peprojection matrix * @@ -68,22 +103,15 @@ glm_frustum(float left, float right, float bottom, float top, float nearZ, float farZ, mat4 dest) { - float rl, tb, fn, nv; - - glm_mat4_zero(dest); - - rl = 1.0f / (right - left); - tb = 1.0f / (top - bottom); - fn =-1.0f / (farZ - nearZ); - nv = 2.0f * nearZ; - - dest[0][0] = nv * rl; - dest[1][1] = nv * tb; - dest[2][0] = (right + left) * rl; - dest[2][1] = (top + bottom) * tb; - dest[2][2] = (farZ + nearZ) * fn; - dest[2][3] =-1.0f; - dest[3][2] = farZ * nv * fn; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_frustum_lh_zo(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_frustum_lh_no(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_frustum_rh_zo(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_frustum_rh_no(left, right, bottom, top, nearZ, farZ, dest); +#endif } /*! @@ -103,21 +131,15 @@ glm_ortho(float left, float right, float bottom, float top, float nearZ, float farZ, mat4 dest) { - float rl, tb, fn; - - glm_mat4_zero(dest); - - rl = 1.0f / (right - left); - tb = 1.0f / (top - bottom); - fn =-1.0f / (farZ - nearZ); - - dest[0][0] = 2.0f * rl; - dest[1][1] = 2.0f * tb; - dest[2][2] = 2.0f * fn; - dest[3][0] =-(right + left) * rl; - dest[3][1] =-(top + bottom) * tb; - dest[3][2] = (farZ + nearZ) * fn; - dest[3][3] = 1.0f; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_lh_zo(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_lh_no(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_rh_zo(left, right, bottom, top, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_rh_no(left, right, bottom, top, nearZ, farZ, dest); +#endif } /*! @@ -131,10 +153,15 @@ glm_ortho(float left, float right, CGLM_INLINE void glm_ortho_aabb(vec3 box[2], mat4 dest) { - glm_ortho(box[0][0], box[1][0], - box[0][1], box[1][1], - -box[1][2], -box[0][2], - dest); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_aabb_lh_zo(box, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_aabb_lh_no(box, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_aabb_rh_zo(box, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_aabb_rh_no(box, dest); +#endif } /*! @@ -149,10 +176,15 @@ glm_ortho_aabb(vec3 box[2], mat4 dest) { CGLM_INLINE void glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { - glm_ortho(box[0][0] - padding, box[1][0] + padding, - box[0][1] - padding, box[1][1] + padding, - -(box[1][2] + padding), -(box[0][2] - padding), - dest); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_aabb_p_lh_zo(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_aabb_p_lh_no(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_aabb_p_rh_zo(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_aabb_p_rh_no(box, padding, dest); +#endif } /*! @@ -167,10 +199,15 @@ glm_ortho_aabb_p(vec3 box[2], float padding, mat4 dest) { CGLM_INLINE void glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { - glm_ortho(box[0][0], box[1][0], - box[0][1], box[1][1], - -(box[1][2] + padding), -(box[0][2] - padding), - dest); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_aabb_pz_lh_zo(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_aabb_pz_lh_no(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_aabb_pz_rh_zo(box, padding, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_aabb_pz_rh_no(box, padding, dest); +#endif } /*! @@ -182,14 +219,15 @@ glm_ortho_aabb_pz(vec3 box[2], float padding, mat4 dest) { CGLM_INLINE void glm_ortho_default(float aspect, mat4 dest) { - if (aspect >= 1.0f) { - glm_ortho(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); - return; - } - - aspect = 1.0f / aspect; - - glm_ortho(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_default_lh_zo(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_default_lh_no(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_default_rh_zo(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_default_rh_no(aspect, dest); +#endif } /*! @@ -202,24 +240,15 @@ glm_ortho_default(float aspect, mat4 dest) { CGLM_INLINE void glm_ortho_default_s(float aspect, float size, mat4 dest) { - if (aspect >= 1.0f) { - glm_ortho(-size * aspect, - size * aspect, - -size, - size, - -size - 100.0f, - size + 100.0f, - dest); - return; - } - - glm_ortho(-size, - size, - -size / aspect, - size / aspect, - -size - 100.0f, - size + 100.0f, - dest); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_ortho_default_s_lh_zo(aspect, size, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_ortho_default_s_lh_no(aspect, size, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_ortho_default_s_rh_zo(aspect, size, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_ortho_default_s_rh_no(aspect, size, dest); +#endif } /*! @@ -234,18 +263,15 @@ glm_ortho_default_s(float aspect, float size, mat4 dest) { CGLM_INLINE void glm_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) { - float f, fn; - - glm_mat4_zero(dest); - - f = 1.0f / tanf(fovy * 0.5f); - fn = 1.0f / (nearZ - farZ); - - dest[0][0] = f / aspect; - dest[1][1] = f; - dest[2][2] = (nearZ + farZ) * fn; - dest[2][3] =-1.0f; - dest[3][2] = 2.0f * nearZ * farZ * fn; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_perspective_lh_zo(fovy, aspect, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_perspective_lh_no(fovy, aspect, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_perspective_rh_zo(fovy, aspect, nearZ, farZ, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_perspective_rh_no(fovy, aspect, nearZ, farZ, dest); +#endif } /*! @@ -259,17 +285,15 @@ glm_perspective(float fovy, float aspect, float nearZ, float farZ, mat4 dest) { CGLM_INLINE void glm_persp_move_far(mat4 proj, float deltaFar) { - float fn, farZ, nearZ, p22, p32; - - p22 = proj[2][2]; - p32 = proj[3][2]; - - nearZ = p32 / (p22 - 1.0f); - farZ = p32 / (p22 + 1.0f) + deltaFar; - fn = 1.0f / (nearZ - farZ); - - proj[2][2] = (nearZ + farZ) * fn; - proj[3][2] = 2.0f * nearZ * farZ * fn; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_move_far_lh_zo(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_move_far_lh_no(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_move_far_rh_zo(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_move_far_rh_no(proj, deltaFar); +#endif } /*! @@ -282,7 +306,15 @@ glm_persp_move_far(mat4 proj, float deltaFar) { CGLM_INLINE void glm_perspective_default(float aspect, mat4 dest) { - glm_perspective(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_perspective_default_lh_zo(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_perspective_default_lh_no(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_perspective_default_rh_zo(aspect, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_perspective_default_rh_no(aspect, dest); +#endif } /*! @@ -316,28 +348,11 @@ glm_perspective_resize(float aspect, mat4 proj) { CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) { - CGLM_ALIGN(8) vec3 f, u, s; - - glm_vec3_sub(center, eye, f); - glm_vec3_normalize(f); - - glm_vec3_crossn(f, up, s); - glm_vec3_cross(s, f, u); - - dest[0][0] = s[0]; - dest[0][1] = u[0]; - dest[0][2] =-f[0]; - dest[1][0] = s[1]; - dest[1][1] = u[1]; - dest[1][2] =-f[1]; - dest[2][0] = s[2]; - dest[2][1] = u[2]; - dest[2][2] =-f[2]; - dest[3][0] =-glm_vec3_dot(s, eye); - dest[3][1] =-glm_vec3_dot(u, eye); - dest[3][2] = glm_vec3_dot(f, eye); - dest[0][3] = dest[1][3] = dest[2][3] = 0.0f; - dest[3][3] = 1.0f; +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH + glm_lookat_lh(eye, center, up, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH + glm_lookat_rh(eye, center, up, dest); +#endif } /*! @@ -357,9 +372,11 @@ glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) { CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { - CGLM_ALIGN(8) vec3 target; - glm_vec3_add(eye, dir, target); - glm_lookat(eye, target, up, dest); +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH + glm_look_lh(eye, dir, up, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH + glm_look_rh(eye, dir, up, dest); +#endif } /*! @@ -375,9 +392,11 @@ glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { CGLM_INLINE void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { - CGLM_ALIGN(8) vec3 up; - glm_vec3_ortho(dir, up); - glm_look(eye, dir, up, dest); +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH + glm_look_anyup_lh(eye, dir, dest); +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH + glm_look_anyup_rh(eye, dir, dest); +#endif } /*! @@ -397,28 +416,15 @@ glm_persp_decomp(mat4 proj, float * __restrict nearZ, float * __restrict farZ, float * __restrict top, float * __restrict bottom, float * __restrict left, float * __restrict right) { - float m00, m11, m20, m21, m22, m32, n, f; - float n_m11, n_m00; - - m00 = proj[0][0]; - m11 = proj[1][1]; - m20 = proj[2][0]; - m21 = proj[2][1]; - m22 = proj[2][2]; - m32 = proj[3][2]; - - n = m32 / (m22 - 1.0f); - f = m32 / (m22 + 1.0f); - - n_m11 = n / m11; - n_m00 = n / m00; - - *nearZ = n; - *farZ = f; - *bottom = n_m11 * (m21 - 1.0f); - *top = n_m11 * (m21 + 1.0f); - *left = n_m00 * (m20 - 1.0f); - *right = n_m00 * (m20 + 1.0f); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_lh_zo(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_lh_no(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_rh_zo(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_rh_no(proj, nearZ, farZ, top, bottom, left, right); +#endif } /*! @@ -431,8 +437,15 @@ glm_persp_decomp(mat4 proj, CGLM_INLINE void glm_persp_decompv(mat4 proj, float dest[6]) { - glm_persp_decomp(proj, &dest[0], &dest[1], &dest[2], - &dest[3], &dest[4], &dest[5]); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decompv_lh_zo(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decompv_lh_no(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decompv_rh_zo(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decompv_rh_no(proj, dest); +#endif } /*! @@ -448,14 +461,15 @@ void glm_persp_decomp_x(mat4 proj, float * __restrict left, float * __restrict right) { - float nearZ, m20, m00; - - m00 = proj[0][0]; - m20 = proj[2][0]; - - nearZ = proj[3][2] / (proj[3][3] - 1.0f); - *left = nearZ * (m20 - 1.0f) / m00; - *right = nearZ * (m20 + 1.0f) / m00; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_x_lh_zo(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_x_lh_no(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_x_rh_zo(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_x_rh_no(proj, left, right); +#endif } /*! @@ -471,14 +485,15 @@ void glm_persp_decomp_y(mat4 proj, float * __restrict top, float * __restrict bottom) { - float nearZ, m21, m11; - - m21 = proj[2][1]; - m11 = proj[1][1]; - - nearZ = proj[3][2] / (proj[3][3] - 1.0f); - *bottom = nearZ * (m21 - 1) / m11; - *top = nearZ * (m21 + 1) / m11; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_y_lh_zo(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_y_lh_no(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_y_rh_zo(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_y_rh_no(proj, top, bottom); +#endif } /*! @@ -492,13 +507,15 @@ glm_persp_decomp_y(mat4 proj, CGLM_INLINE void glm_persp_decomp_z(mat4 proj, float * __restrict nearZ, float * __restrict farZ) { - float m32, m22; - - m32 = proj[3][2]; - m22 = proj[2][2]; - - *nearZ = m32 / (m22 - 1.0f); - *farZ = m32 / (m22 + 1.0f); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_z_lh_zo(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_z_lh_no(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_z_rh_zo(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_z_rh_no(proj, nearZ, farZ); +#endif } /*! @@ -510,7 +527,15 @@ glm_persp_decomp_z(mat4 proj, float * __restrict nearZ, float * __restrict farZ) CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float * __restrict farZ) { - *farZ = proj[3][2] / (proj[2][2] + 1.0f); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_far_lh_zo(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_far_lh_no(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_far_rh_zo(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_far_rh_no(proj, farZ); +#endif } /*! @@ -522,32 +547,15 @@ glm_persp_decomp_far(mat4 proj, float * __restrict farZ) { CGLM_INLINE void glm_persp_decomp_near(mat4 proj, float * __restrict nearZ) { - *nearZ = proj[3][2] / (proj[2][2] - 1.0f); -} - -/*! - * @brief returns field of view angle along the Y-axis (in radians) - * - * if you need to degrees, use glm_deg to convert it or use this: - * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) - * - * @param[in] proj perspective projection matrix - */ -CGLM_INLINE -float -glm_persp_fovy(mat4 proj) { - return 2.0f * atanf(1.0f / proj[1][1]); -} - -/*! - * @brief returns aspect ratio of perspective projection - * - * @param[in] proj perspective projection matrix - */ -CGLM_INLINE -float -glm_persp_aspect(mat4 proj) { - return proj[1][1] / proj[0][0]; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_decomp_near_lh_zo(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_decomp_near_lh_no(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_decomp_near_rh_zo(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_decomp_near_rh_no(proj, nearZ); +#endif } /*! @@ -560,17 +568,15 @@ glm_persp_aspect(mat4 proj) { CGLM_INLINE void glm_persp_sizes(mat4 proj, float fovy, vec4 dest) { - float t, a, nearZ, farZ; - - t = 2.0f * tanf(fovy * 0.5f); - a = glm_persp_aspect(proj); - - glm_persp_decomp_z(proj, &nearZ, &farZ); - - dest[1] = t * nearZ; - dest[3] = t * farZ; - dest[0] = a * dest[1]; - dest[2] = a * dest[3]; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glm_persp_sizes_lh_zo(proj, fovy, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glm_persp_sizes_lh_no(proj, fovy, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glm_persp_sizes_rh_zo(proj, fovy, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glm_persp_sizes_rh_no(proj, fovy, dest); +#endif } -#endif /* cglm_vcam_h */ +#endif /* cglm_cam_h */ diff --git a/include/cglm/cam_lh_no.h b/include/cglm/cam_lh_no.h deleted file mode 100644 index 2c6a6ab..0000000 --- a/include/cglm/cam_lh_no.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -/* - Functions: - CGLM_INLINE void glm_perspective_lh_no(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) - */ - -#ifndef cglm_cam_lh_no_h -#define cglm_cam_lh_no_h - -#include "common.h" -#include "plane.h" - -/*! - * @brief set up perspective projection matrix with a left-hand coordinate - * system and a clip-space of [-1, 1] - * - * @param[in] fovy field of view angle - * @param[in] aspect aspect ratio ( width / height ) - * @param[in] nearVal near clipping plane - * @param[in] farVal far clipping planes - * @param[out] dest result matrix - */ -CGLM_INLINE -void -glm_perspective_lh_no(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - /* Impl follows glm::perspectiveLH_NO in glm/ext/matrix_clip_space.inl */ - float fl, fn; - - glm_mat4_zero(dest); - - fl = 1.0f / tanf(fovy * 0.5f); - fn = 1.0f / (farVal - nearVal); - - dest[0][0] = fl / aspect; - dest[1][1] = fl; - dest[2][2] = (farVal + nearVal) * fn; - dest[2][3] = 1.0f; - dest[3][2] = -2.0f * farVal * nearVal * fn; -} - -#endif /*cglm_cam_lh_no_h*/ diff --git a/include/cglm/cam_lh_zo.h b/include/cglm/cam_lh_zo.h deleted file mode 100644 index e800ff6..0000000 --- a/include/cglm/cam_lh_zo.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -/* - Functions: - CGLM_INLINE void glm_perspective_lh_zo(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) - */ - -#ifndef cglm_cam_lh_zo_h -#define cglm_cam_lh_zo_h - -#include "common.h" -#include "plane.h" - -/*! - * @brief set up perspective projection matrix with a left-hand coordinate - * system (suitable, apparently, for DirectX and Metal) and a clip-space with - * depth values from zero to one. - * - * @param[in] fovy field of view angle - * @param[in] aspect aspect ratio ( width / height ) - * @param[in] nearVal near clipping plane - * @param[in] farVal far clipping planes - * @param[out] dest result matrix - */ -CGLM_INLINE -void -glm_perspective_lh_zo(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - /* Impl follows glm::perspectiveLH_ZO in glm/ext/matrix_clip_space.inl */ - float fl, fn; - - glm_mat4_zero(dest); - - fl = 1.0f / tanf(fovy * 0.5f); - fn = 1.0f / (farVal - nearVal); - - dest[0][0] = fl / aspect; - dest[1][1] = fl; - dest[2][2] = farVal * fn; - dest[2][3] = 1.0f; - dest[3][2] = -farVal * nearVal * fn; -} - -#endif /*cglm_cam_lh_zo_h*/ diff --git a/include/cglm/cam_rh_no.h b/include/cglm/cam_rh_no.h deleted file mode 100644 index 71a99ad..0000000 --- a/include/cglm/cam_rh_no.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -/* - Functions: - CGLM_INLINE void glm_perspective_rh_no(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) - */ - -#ifndef cglm_cam_rh_no_h -#define cglm_cam_rh_no_h - -#include "common.h" -#include "plane.h" - -/*! - * @brief set up perspective projection matrix with a right-hand coordinate - * system and a clip space of [-1, 1]. - * - * @param[in] fovy field of view angle - * @param[in] aspect aspect ratio ( width / height ) - * @param[in] nearVal near clipping plane - * @param[in] farVal far clipping planes - * @param[out] dest result matrix - */ -CGLM_INLINE -void -glm_perspective_rh_no(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - /* Impl follows glm::perspectiveRH_NO in glm/ext/matrix_clip_space.inl */ - float fl, fn; - - glm_mat4_zero(dest); - - fl = 1.0f / tanf(fovy * 0.5f); - fn = 1.0f / (farVal - nearVal); - - dest[0][0] = fl / aspect; - dest[1][1] = fl; - dest[2][2] = -(farVal + nearVal) * fn; - dest[2][3] = -1.0f; - dest[3][2] = -2.0f * farVal * nearVal * fn; -} - -#endif /*cglm_cam_rh_no_h*/ diff --git a/include/cglm/cam_rh_zo.h b/include/cglm/cam_rh_zo.h deleted file mode 100644 index bdb08c2..0000000 --- a/include/cglm/cam_rh_zo.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -/* - Functions: - CGLM_INLINE void glm_perspective_rh_zo(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) - */ - -#ifndef cglm_cam_rh_zo_h -#define cglm_cam_rh_zo_h - -#include "common.h" -#include "plane.h" - -/*! - * @brief set up perspective projection matrix with a right-hand coordinate - * system (suitable for Vulkan) and a clip-space with depth values from zero - * to one. - * - * @param[in] fovy field of view angle - * @param[in] aspect aspect ratio ( width / height ) - * @param[in] nearVal near clipping plane - * @param[in] farVal far clipping planes - * @param[out] dest result matrix - */ -CGLM_INLINE -void -glm_perspective_rh_zo(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - /* Impl follows glm::perspectiveRH_ZO in glm/ext/matrix_clip_space.inl */ - float fl, fn; - - glm_mat4_zero(dest); - - fl = 1.0f / tanf(fovy * 0.5f); - fn = 1.0f / (farVal - nearVal); - - dest[0][0] = fl / aspect; - dest[1][1] = fl; - dest[2][2] = -farVal * fn; - dest[2][3] = -1.0f; - dest[3][2] = -farVal * nearVal * fn; -} - -#endif /*cglm_cam_rh_zo_h*/ diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index c6c2805..5ff3421 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -17,10 +17,6 @@ #include "mat2.h" #include "affine.h" #include "cam.h" -#include "cam_lh_zo.h" -#include "cam_rh_zo.h" -#include "cam_lh_no.h" -#include "cam_rh_no.h" #include "frustum.h" #include "quat.h" #include "euler.h" diff --git a/include/cglm/clipspace/ortho_lh_no.h b/include/cglm/clipspace/ortho_lh_no.h new file mode 100644 index 0000000..24b0568 --- /dev/null +++ b/include/cglm/clipspace/ortho_lh_no.h @@ -0,0 +1,182 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_lh_no(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p_lh_no(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz_lh_no(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_default_lh_no(float aspect, + mat4 dest) + CGLM_INLINE void glm_ortho_default_s_lh_no(float aspect, + float size, + mat4 dest) + */ + +#ifndef cglm_ortho_lh_no_h +#define cglm_ortho_lh_no_h + +#include "../common.h" +#include "../plane.h" + +/*! + * @brief set up orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] =-2.0f * fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = (farZ + nearZ) * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_lh_no(vec3 box[2], mat4 dest) { + glm_ortho_lh_no(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p_lh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_lh_no(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz_lh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_lh_no(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up unit orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_lh_no(float aspect, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_lh_no(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); + return; + } + + aspect = 1.0f / aspect; + + glm_ortho_lh_no(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s_lh_no(float aspect, float size, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_lh_no(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho_lh_no(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +#endif /*cglm_ortho_lh_no_h*/ diff --git a/include/cglm/clipspace/ortho_lh_zo.h b/include/cglm/clipspace/ortho_lh_zo.h new file mode 100644 index 0000000..c88322a --- /dev/null +++ b/include/cglm/clipspace/ortho_lh_zo.h @@ -0,0 +1,180 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_lh_zo(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p_lh_zo(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz_lh_zo(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_default_lh_zo(float aspect, + mat4 dest) + CGLM_INLINE void glm_ortho_default_s_lh_zo(float aspect, + float size, + mat4 dest) + */ + +#ifndef cglm_ortho_lh_zo_h +#define cglm_ortho_lh_zo_h + +#include "../common.h" +#include "../plane.h" + +/*! + * @brief set up orthographic projection matrix with a left-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] =-fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = nearZ * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_lh_zo(vec3 box[2], mat4 dest) { + glm_ortho_lh_zo(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_lh_zo(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_lh_zo(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up unit orthographic projection matrix with a left-hand + * coordinate system and a clip-space of [0, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_lh_zo(float aspect, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_lh_zo(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); + return; + } + + aspect = 1.0f / aspect; + + glm_ortho_lh_zo(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a left-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s_lh_zo(float aspect, float size, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_lh_zo(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho_lh_zo(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +#endif /*cglm_ortho_lh_zo_h*/ diff --git a/include/cglm/clipspace/ortho_rh_no.h b/include/cglm/clipspace/ortho_rh_no.h new file mode 100644 index 0000000..1c833c9 --- /dev/null +++ b/include/cglm/clipspace/ortho_rh_no.h @@ -0,0 +1,182 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_rh_no(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p_rh_no(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz_rh_no(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_default_rh_no(float aspect, + mat4 dest) + CGLM_INLINE void glm_ortho_default_s_rh_no(float aspect, + float size, + mat4 dest) + */ + +#ifndef cglm_ortho_rh_no_h +#define cglm_ortho_rh_no_h + +#include "../common.h" +#include "../plane.h" + +/*! + * @brief set up orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] = 2.0f * fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = (farZ + nearZ) * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_rh_no(vec3 box[2], mat4 dest) { + glm_ortho_rh_no(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_rh_no(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_rh_no(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up unit orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_rh_no(float aspect, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_rh_no(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); + return; + } + + aspect = 1.0f / aspect; + + glm_ortho_rh_no(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s_rh_no(float aspect, float size, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_rh_no(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho_rh_no(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +#endif /*cglm_ortho_rh_no_h*/ diff --git a/include/cglm/clipspace/ortho_rh_zo.h b/include/cglm/clipspace/ortho_rh_zo.h new file mode 100644 index 0000000..9d9602e --- /dev/null +++ b/include/cglm/clipspace/ortho_rh_zo.h @@ -0,0 +1,180 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_rh_zo(vec3 box[2], mat4 dest) + CGLM_INLINE void glm_ortho_aabb_p_rh_zo(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_aabb_pz_rh_zo(vec3 box[2], + float padding, + mat4 dest) + CGLM_INLINE void glm_ortho_default_rh_zo(float aspect, + mat4 dest) + CGLM_INLINE void glm_ortho_default_s_rh_zo(float aspect, + float size, + mat4 dest) + */ + +#ifndef cglm_ortho_rh_zo_h +#define cglm_ortho_rh_zo_h + +#include "../common.h" +#include "../plane.h" + +/*! + * @brief set up orthographic projection matrix with a right-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + + dest[0][0] = 2.0f * rl; + dest[1][1] = 2.0f * tb; + dest[2][2] = fn; + dest[3][0] =-(right + left) * rl; + dest[3][1] =-(top + bottom) * tb; + dest[3][2] = nearZ * fn; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_rh_zo(vec3 box[2], mat4 dest) { + glm_ortho_rh_zo(box[0][0], box[1][0], + box[0][1], box[1][1], + -box[1][2], -box[0][2], + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_p_rh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_rh_zo(box[0][0] - padding, box[1][0] + padding, + box[0][1] - padding, box[1][1] + padding, + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_aabb_pz_rh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_rh_zo(box[0][0], box[1][0], + box[0][1], box[1][1], + -(box[1][2] + padding), -(box[0][2] - padding), + dest); +} + +/*! + * @brief set up unit orthographic projection matrix with a right-hand + * coordinate system and a clip-space of [0, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_rh_zo(float aspect, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_rh_zo(-aspect, aspect, -1.0f, 1.0f, -100.0f, 100.0f, dest); + return; + } + + aspect = 1.0f / aspect; + + glm_ortho_rh_zo(-1.0f, 1.0f, -aspect, aspect, -100.0f, 100.0f, dest); +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a right-hand coordinate system and a clip-space with depth + * values from zero to one. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_ortho_default_s_rh_zo(float aspect, float size, mat4 dest) { + if (aspect >= 1.0f) { + glm_ortho_rh_zo(-size * aspect, + size * aspect, + -size, + size, + -size - 100.0f, + size + 100.0f, + dest); + return; + } + + glm_ortho_rh_zo(-size, + size, + -size / aspect, + size / aspect, + -size - 100.0f, + size + 100.0f, + dest); +} + +#endif /*cglm_ortho_rh_zo_h*/ diff --git a/include/cglm/clipspace/persp.h b/include/cglm/clipspace/persp.h new file mode 100644 index 0000000..15aa715 --- /dev/null +++ b/include/cglm/clipspace/persp.h @@ -0,0 +1,48 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_persp_decomp_far(mat4 proj, float *farZ) + CGLM_INLINE float glm_persp_fovy(mat4 proj) + CGLM_INLINE float glm_persp_aspect(mat4 proj) + CGLM_INLINE void glm_persp_sizes(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_h +#define cglm_persp_h + +#include "../common.h" +#include "../plane.h" +#include "../mat4.h" + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_fovy(mat4 proj) { + return 2.0f * atanf(1.0f / proj[1][1]); +} + +/*! + * @brief returns aspect ratio of perspective projection + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect(mat4 proj) { + return proj[1][1] / proj[0][0]; +} + +#endif /* cglm_persp_h */ diff --git a/include/cglm/clipspace/persp_lh_no.h b/include/cglm/clipspace/persp_lh_no.h new file mode 100644 index 0000000..2ab8d01 --- /dev/null +++ b/include/cglm/clipspace/persp_lh_no.h @@ -0,0 +1,396 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_lh_no(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_default_lh_no(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize_lh_no(float aspect, mat4 proj) + CGLM_INLINE void glm_persp_move_far_lh_no(mat4 proj, + float deltaFar) + CGLM_INLINE void glm_persp_decomp_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decompv_lh_no(mat4 proj, + float dest[6]) + CGLM_INLINE void glm_persp_decomp_x_lh_no(mat4 proj, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decomp_y_lh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) + CGLM_INLINE void glm_persp_decomp_z_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ) + CGLM_INLINE void glm_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_lh_no_h +#define cglm_persp_lh_no_h + +#include "../common.h" +#include "../plane.h" +#include "persp.h" + +/*! + * @brief set up perspective peprojection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn, nv; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + nv = 2.0f * nearZ; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] =-(farZ + nearZ) * fn; + dest[2][3] = 1.0f; + dest[3][2] = farZ * nv * fn; +} + +/*! + * @brief set up perspective projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_lh_no(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) { + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearZ - farZ); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] =-(nearZ + farZ) * fn; + dest[2][3] = 1.0f; + dest[3][2] = 2.0f * nearZ * farZ * fn; + +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default_lh_no(float aspect, mat4 dest) { + glm_perspective_lh_no(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * resized with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize_lh_no(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glm_persp_move_far_lh_no(mat4 proj, float deltaFar) { + float fn, farZ, nearZ, p22, p32; + + p22 = -proj[2][2]; + p32 = proj[3][2]; + + nearZ = p32 / (p22 - 1.0f); + farZ = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearZ - farZ); + + proj[2][2] = -(farZ + nearZ) * fn; + proj[3][2] = 2.0f * nearZ * farZ * fn; +} + +/*! + * @brief decomposes frustum values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_lh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + float m00, m11, m20, m21, m22, m32, n, f; + float n_m11, n_m00; + + m00 = proj[0][0]; + m11 = proj[1][1]; + m20 = proj[2][0]; + m21 = proj[2][1]; + m22 =-proj[2][2]; + m32 = proj[3][2]; + + n = m32 / (m22 - 1.0f); + f = m32 / (m22 + 1.0f); + + n_m11 = n / m11; + n_m00 = n / m00; + + *nearZ = n; + *farZ = f; + *bottom = n_m11 * (m21 - 1.0f); + *top = n_m11 * (m21 + 1.0f); + *left = n_m00 * (m20 - 1.0f); + *right = n_m00 * (m20 + 1.0f); +} + +/*! + * @brief decomposes frustum values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv_lh_no(mat4 proj, float dest[6]) { + glm_persp_decomp_lh_no(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_x_lh_no(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearZ, m20, m00, m22; + + m00 = proj[0][0]; + m20 = proj[2][0]; + m22 =-proj[2][2]; + + nearZ = proj[3][2] / (m22 - 1.0f); + *left = nearZ * (m20 - 1.0f) / m00; + *right = nearZ * (m20 + 1.0f) / m00; +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * y stands for y axis (top / botom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glm_persp_decomp_y_lh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearZ, m21, m11, m22; + + m21 = proj[2][1]; + m11 = proj[1][1]; + m22 =-proj[2][2]; + + nearZ = proj[3][2] / (m22 - 1.0f); + *bottom = nearZ * (m21 - 1.0f) / m11; + *top = nearZ * (m21 + 1.0f) / m11; +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + float m32, m22; + + m32 = proj[3][2]; + m22 =-proj[2][2]; + + *nearZ = m32 / (m22 - 1.0f); + *farZ = m32 / (m22 + 1.0f); +} + +/*! + * @brief decomposes far value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ) { + *farZ = proj[3][2] / (-proj[2][2] + 1.0f); +} + +/*! + * @brief decomposes near value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ) { + *nearZ = proj[3][2] / (-proj[2][2] - 1.0f); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest) { + float t, a, nearZ, farZ; + + t = 2.0f * tanf(fovy * 0.5f); + a = glm_persp_aspect(proj); + + glm_persp_decomp_z_lh_no(proj, &nearZ, &farZ); + + dest[1] = t * nearZ; + dest[3] = t * farZ; + dest[0] = a * dest[1]; + dest[2] = a * dest[3]; +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a left-hand coordinate system and a clip-space of [-1, 1]. + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_fovy_lh_no(mat4 proj) { + return glm_persp_fovy(proj); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a left-hand coordinate system and a clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect_lh_no(mat4 proj) { + return glm_persp_aspect(proj); +} + +#endif /*cglm_cam_lh_no_h*/ diff --git a/include/cglm/clipspace/persp_lh_zo.h b/include/cglm/clipspace/persp_lh_zo.h new file mode 100644 index 0000000..52a2648 --- /dev/null +++ b/include/cglm/clipspace/persp_lh_zo.h @@ -0,0 +1,388 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_lh_zo(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_default_lh_zo(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize_lh_zo(float aspect, mat4 proj) + CGLM_INLINE void glm_persp_move_far_lh_zo(mat4 proj, + float deltaFar) + CGLM_INLINE void glm_persp_decomp_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decompv_lh_zo(mat4 proj, + float dest[6]) + CGLM_INLINE void glm_persp_decomp_x_lh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decomp_y_lh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) + CGLM_INLINE void glm_persp_decomp_z_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ) + CGLM_INLINE void glm_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_lh_zo_h +#define cglm_persp_lh_zo_h + +#include "../common.h" +#include "../plane.h" +#include "persp.h" + +/*! + * @brief set up perspective peprojection matrix with a left-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn, nv; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + nv = 2.0f * nearZ; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] =-farZ * fn; + dest[2][3] = 1.0f; + dest[3][2] = farZ * nearZ * fn; +} + +/*! + * @brief set up perspective projection matrix with a left-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_lh_zo(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) { + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearZ - farZ); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] =-farZ * fn; + dest[2][3] = 1.0f; + dest[3][2] = nearZ * farZ * fn; +} + +/*! + * @brief extend perspective projection matrix's far distance with a + * left-hand coordinate system and a clip-space with depth values + * from zero to one. + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glm_persp_move_far_lh_zo(mat4 proj, float deltaFar) { + float fn, farZ, nearZ, p22, p32; + + p22 = -proj[2][2]; + p32 = proj[3][2]; + + nearZ = p32 / p22; + farZ = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearZ - farZ); + + proj[2][2] = -farZ * fn; + proj[3][2] = nearZ * farZ * fn; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default_lh_zo(float aspect, mat4 dest) { + glm_perspective_lh_zo(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize_lh_zo(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief decomposes frustum values of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_lh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + float m00, m11, m20, m21, m22, m32, n, f; + float n_m11, n_m00; + + m00 = proj[0][0]; + m11 = proj[1][1]; + m20 = proj[2][0]; + m21 = proj[2][1]; + m22 =-proj[2][2]; + m32 = proj[3][2]; + + n = m32 / m22; + f = m32 / (m22 + 1.0f); + + n_m11 = n / m11; + n_m00 = n / m00; + + *nearZ = n; + *farZ = f; + *bottom = n_m11 * (m21 - 1.0f); + *top = n_m11 * (m21 + 1.0f); + *left = n_m00 * (m20 - 1.0f); + *right = n_m00 * (m20 + 1.0f); +} + +/*! + * @brief decomposes frustum values of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv_lh_zo(mat4 proj, float dest[6]) { + glm_persp_decomp_lh_zo(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection (ZO). + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_x_lh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearZ, m20, m00; + + m00 = proj[0][0]; + m20 = proj[2][0]; + + nearZ = proj[3][2] / (proj[3][3]); + *left = nearZ * (m20 - 1.0f) / m00; + *right = nearZ * (m20 + 1.0f) / m00; +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * y stands for y axis (top / bottom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glm_persp_decomp_y_lh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearZ, m21, m11; + + m21 = proj[2][1]; + m11 = proj[1][1]; + + nearZ = proj[3][2] / (proj[3][3]); + *bottom = nearZ * (m21 - 1) / m11; + *top = nearZ * (m21 + 1) / m11; +} + +/*! + * @brief decomposes near and far values of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + float m32, m22; + + m32 = proj[3][2]; + m22 = -proj[2][2]; + + *nearZ = m32 / m22; + *farZ = m32 / (m22 + 1.0f); +} + +/*! + * @brief decomposes far value of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ) { + *farZ = proj[3][2] / (-proj[2][2] + 1.0f); +} + +/*! + * @brief decomposes near value of perspective projection + * with angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ) { + *nearZ = proj[3][2] / -proj[2][2]; +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest) { + float t, a, nearZ, farZ; + + t = 2.0f * tanf(fovy * 0.5f); + a = glm_persp_aspect(proj); + + glm_persp_decomp_z_lh_zo(proj, &nearZ, &farZ); + + dest[1] = t * nearZ; + dest[3] = t * farZ; + dest[0] = a * dest[1]; + dest[2] = a * dest[3]; +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_fovy_lh_zo(mat4 proj) { + return glm_persp_fovy(proj); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a left-hand coordinate system and a clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect_lh_zo(mat4 proj) { + return glm_persp_aspect(proj); +} + +#endif /*cglm_persp_lh_zo_h*/ diff --git a/include/cglm/clipspace/persp_rh_no.h b/include/cglm/clipspace/persp_rh_no.h new file mode 100644 index 0000000..325e17b --- /dev/null +++ b/include/cglm/clipspace/persp_rh_no.h @@ -0,0 +1,396 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_rh_no(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_default_rh_no(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize_rh_no(float aspect, mat4 proj) + CGLM_INLINE void glm_persp_move_far_rh_no(mat4 proj, + float deltaFar) + CGLM_INLINE void glm_persp_decomp_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decompv_rh_no(mat4 proj, + float dest[6]) + CGLM_INLINE void glm_persp_decomp_x_rh_no(mat4 proj, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decomp_y_rh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) + CGLM_INLINE void glm_persp_decomp_z_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ) + CGLM_INLINE void glm_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_rh_no_h +#define cglm_persp_rh_no_h + +#include "../common.h" +#include "../plane.h" +#include "persp.h" + +/*! + * @brief set up perspective peprojection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn, nv; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + nv = 2.0f * nearZ; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] = (farZ + nearZ) * fn; + dest[2][3] =-1.0f; + dest[3][2] = farZ * nv * fn; +} + +/*! + * @brief set up perspective projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_rh_no(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) { + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearZ - farZ); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] = (nearZ + farZ) * fn; + dest[2][3] =-1.0f; + dest[3][2] = 2.0f * nearZ * farZ * fn; + +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default_rh_no(float aspect, mat4 dest) { + glm_perspective_rh_no(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * resized with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize_rh_no(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glm_persp_move_far_rh_no(mat4 proj, float deltaFar) { + float fn, farZ, nearZ, p22, p32; + + p22 = proj[2][2]; + p32 = proj[3][2]; + + nearZ = p32 / (p22 - 1.0f); + farZ = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearZ - farZ); + + proj[2][2] = (farZ + nearZ) * fn; + proj[3][2] = 2.0f * nearZ * farZ * fn; +} + +/*! + * @brief decomposes frustum values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_rh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + float m00, m11, m20, m21, m22, m32, n, f; + float n_m11, n_m00; + + m00 = proj[0][0]; + m11 = proj[1][1]; + m20 = proj[2][0]; + m21 = proj[2][1]; + m22 = proj[2][2]; + m32 = proj[3][2]; + + n = m32 / (m22 - 1.0f); + f = m32 / (m22 + 1.0f); + + n_m11 = n / m11; + n_m00 = n / m00; + + *nearZ = n; + *farZ = f; + *bottom = n_m11 * (m21 - 1.0f); + *top = n_m11 * (m21 + 1.0f); + *left = n_m00 * (m20 - 1.0f); + *right = n_m00 * (m20 + 1.0f); +} + +/*! + * @brief decomposes frustum values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv_rh_no(mat4 proj, float dest[6]) { + glm_persp_decomp_rh_no(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_x_rh_no(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearZ, m20, m00, m22; + + m00 = proj[0][0]; + m20 = proj[2][0]; + m22 = proj[2][2]; + + nearZ = proj[3][2] / (m22 - 1.0f); + *left = nearZ * (m20 - 1.0f) / m00; + *right = nearZ * (m20 + 1.0f) / m00; +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * y stands for y axis (top / botom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glm_persp_decomp_y_rh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearZ, m21, m11, m22; + + m21 = proj[2][1]; + m11 = proj[1][1]; + m22 = proj[2][2]; + + nearZ = proj[3][2] / (m22 - 1.0f); + *bottom = nearZ * (m21 - 1.0f) / m11; + *top = nearZ * (m21 + 1.0f) / m11; +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + float m32, m22; + + m32 = proj[3][2]; + m22 = proj[2][2]; + + *nearZ = m32 / (m22 - 1.0f); + *farZ = m32 / (m22 + 1.0f); +} + +/*! + * @brief decomposes far value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ) { + *farZ = proj[3][2] / (proj[2][2] + 1.0f); +} + +/*! + * @brief decomposes near value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ) { + *nearZ = proj[3][2] / (proj[2][2] - 1.0f); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest) { + float t, a, nearZ, farZ; + + t = 2.0f * tanf(fovy * 0.5f); + a = glm_persp_aspect(proj); + + glm_persp_decomp_z_rh_no(proj, &nearZ, &farZ); + + dest[1] = t * nearZ; + dest[3] = t * farZ; + dest[0] = a * dest[1]; + dest[2] = a * dest[3]; +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a right-hand coordinate system and a clip-space of [-1, 1]. + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_fovy_rh_no(mat4 proj) { + return glm_persp_fovy(proj); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a right-hand coordinate system and a clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect_rh_no(mat4 proj) { + return glm_persp_aspect(proj); +} + +#endif /*cglm_cam_rh_no_h*/ diff --git a/include/cglm/clipspace/persp_rh_zo.h b/include/cglm/clipspace/persp_rh_zo.h new file mode 100644 index 0000000..0bcc175 --- /dev/null +++ b/include/cglm/clipspace/persp_rh_zo.h @@ -0,0 +1,390 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_rh_zo(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) + CGLM_INLINE void glm_perspective_default_rh_zo(float aspect, mat4 dest) + CGLM_INLINE void glm_perspective_resize_rh_zo(float aspect, mat4 proj) + CGLM_INLINE void glm_persp_move_far_rh_zo(mat4 proj, + float deltaFar) + CGLM_INLINE void glm_persp_decomp_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ, + float * __restrict top, + float * __restrict bottom, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decompv_rh_zo(mat4 proj, + float dest[6]) + CGLM_INLINE void glm_persp_decomp_x_rh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) + CGLM_INLINE void glm_persp_decomp_y_rh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) + CGLM_INLINE void glm_persp_decomp_z_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ) + CGLM_INLINE void glm_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ) + CGLM_INLINE void glm_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest) + */ + +#ifndef cglm_persp_rh_zo_h +#define cglm_persp_rh_zo_h + +#include "../common.h" +#include "../plane.h" +#include "persp.h" + +/*! + * @brief set up perspective peprojection matrix with a right-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + float rl, tb, fn, nv; + + glm_mat4_zero(dest); + + rl = 1.0f / (right - left); + tb = 1.0f / (top - bottom); + fn =-1.0f / (farZ - nearZ); + nv = 2.0f * nearZ; + + dest[0][0] = nv * rl; + dest[1][1] = nv * tb; + dest[2][0] = (right + left) * rl; + dest[2][1] = (top + bottom) * tb; + dest[2][2] = farZ * fn; + dest[2][3] =-1.0f; + dest[3][2] = farZ * nearZ * fn; +} + +/*! + * @brief set up perspective projection matrix with a right-hand coordinate + * system and a clip-space of [0, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_rh_zo(float fovy, + float aspect, + float nearZ, + float farZ, + mat4 dest) { + float f, fn; + + glm_mat4_zero(dest); + + f = 1.0f / tanf(fovy * 0.5f); + fn = 1.0f / (nearZ - farZ); + + dest[0][0] = f / aspect; + dest[1][1] = f; + dest[2][2] = farZ * fn; + dest[2][3] =-1.0f; + dest[3][2] = nearZ * farZ * fn; +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_perspective_default_rh_zo(float aspect, mat4 dest) { + glm_perspective_rh_zo(GLM_PI_4f, aspect, 0.01f, 100.0f, dest); +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * resized with a right-hand coordinate system and a clip-space of + * [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in, out] proj perspective projection matrix + */ +CGLM_INLINE +void +glm_perspective_resize_rh_zo(float aspect, mat4 proj) { + if (proj[0][0] == 0.0f) + return; + + proj[0][0] = proj[1][1] / aspect; +} + +/*! + * @brief extend perspective projection matrix's far distance with a + * right-hand coordinate system and a clip-space of [0, 1]. + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glm_persp_move_far_rh_zo(mat4 proj, float deltaFar) { + float fn, farZ, nearZ, p22, p32; + + p22 = proj[2][2]; + p32 = proj[3][2]; + + nearZ = p32 / p22; + farZ = p32 / (p22 + 1.0f) + deltaFar; + fn = 1.0f / (nearZ - farZ); + + proj[2][2] = farZ * fn; + proj[3][2] = nearZ * farZ * fn; +} + +/*! + * @brief decomposes frustum values of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_rh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + float m00, m11, m20, m21, m22, m32, n, f; + float n_m11, n_m00; + + m00 = proj[0][0]; + m11 = proj[1][1]; + m20 = proj[2][0]; + m21 = proj[2][1]; + m22 = proj[2][2]; + m32 = proj[3][2]; + + n = m32 / m22; + f = m32 / (m22 + 1.0f); + + n_m11 = n / m11; + n_m00 = n / m00; + + *nearZ = n; + *farZ = f; + *bottom = n_m11 * (m21 - 1.0f); + *top = n_m11 * (m21 + 1.0f); + *left = n_m00 * (m20 - 1.0f); + *right = n_m00 * (m20 + 1.0f); +} + +/*! + * @brief decomposes frustum values of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * this makes easy to get all values at once + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glm_persp_decompv_rh_zo(mat4 proj, float dest[6]) { + glm_persp_decomp_rh_zo(proj, &dest[0], &dest[1], &dest[2], + &dest[3], &dest[4], &dest[5]); +} + +/*! + * @brief decomposes left and right values of perspective projection (ZO). + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glm_persp_decomp_x_rh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) { + float nearZ, m20, m00, m22; + + m00 = proj[0][0]; + m20 = proj[2][0]; + m22 = proj[2][2]; + + nearZ = proj[3][2] / m22; + *left = nearZ * (m20 - 1.0f) / m00; + *right = nearZ * (m20 + 1.0f) / m00; +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * y stands for y axis (top / bottom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glm_persp_decomp_y_rh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + float nearZ, m21, m11, m22; + + m21 = proj[2][1]; + m11 = proj[1][1]; + m22 = proj[2][2]; + + nearZ = proj[3][2] / m22; + *bottom = nearZ * (m21 - 1) / m11; + *top = nearZ * (m21 + 1) / m11; +} + +/*! + * @brief decomposes near and far values of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_z_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + float m32, m22; + + m32 = proj[3][2]; + m22 = proj[2][2]; + + *nearZ = m32 / m22; + *farZ = m32 / (m22 + 1.0f); +} + +/*! + * @brief decomposes far value of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glm_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ) { + *farZ = proj[3][2] / (proj[2][2] + 1.0f); +} + +/*! + * @brief decomposes near value of perspective projection + * with angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glm_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ) { + *nearZ = proj[3][2] / proj[2][2]; +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @param[out] dest sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +void +glm_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest) { + float t, a, nearZ, farZ; + + t = 2.0f * tanf(fovy * 0.5f); + a = glm_persp_aspect(proj); + + glm_persp_decomp_z_rh_zo(proj, &nearZ, &farZ); + + dest[1] = t * nearZ; + dest[3] = t * farZ; + dest[0] = a * dest[1]; + dest[2] = a * dest[3]; +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a right-hand coordinate system and a clip-space of [0, 1]. + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_fovy_rh_zo(mat4 proj) { + return glm_persp_fovy(proj); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a right-hand coordinate system and a clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glm_persp_aspect_rh_zo(mat4 proj) { + return glm_persp_aspect(proj); +} + +#endif /*cglm_persp_rh_zo_h*/ diff --git a/include/cglm/clipspace/view_lh.h b/include/cglm/clipspace/view_lh.h new file mode 100644 index 0000000..48324f1 --- /dev/null +++ b/include/cglm/clipspace/view_lh.h @@ -0,0 +1,99 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_lookat_lh(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_lh(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_lh(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_lh_h +#define cglm_view_lh_h + +#include "../common.h" +#include "../plane.h" + +/*! + * @brief set up view matrix (LH) + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_lh(vec3 eye, vec3 center, vec3 up, mat4 dest) { + CGLM_ALIGN(8) vec3 f, u, s; + + glm_vec3_sub(center, eye, f); + glm_vec3_normalize(f); + + glm_vec3_crossn(f, up, s); + glm_vec3_cross(s, f, u); + + dest[0][0] = s[0]; + dest[0][1] = u[0]; + dest[0][2] = f[0]; + dest[1][0] = s[1]; + dest[1][1] = u[1]; + dest[1][2] = f[1]; + dest[2][0] = s[2]; + dest[2][1] = u[2]; + dest[2][2] = f[2]; + dest[3][0] =-glm_vec3_dot(s, eye); + dest[3][1] =-glm_vec3_dot(u, eye); + dest[3][2] =-glm_vec3_dot(f, eye); + dest[0][3] = dest[1][3] = dest[2][3] = 0.0f; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up view matrix with left handed coordinate system + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_lh(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + CGLM_ALIGN(8) vec3 target; + glm_vec3_add(eye, dir, target); + glm_lookat_lh(eye, target, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_lh(vec3 eye, vec3 dir, mat4 dest) { + CGLM_ALIGN(8) vec3 up; + glm_vec3_ortho(dir, up); + glm_look_lh(eye, dir, up, dest); +} + +#endif /*cglm_view_lh_h*/ diff --git a/include/cglm/clipspace/view_lh_no.h b/include/cglm/clipspace/view_lh_no.h new file mode 100644 index 0000000..9e8d59c --- /dev/null +++ b/include/cglm/clipspace/view_lh_no.h @@ -0,0 +1,73 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_lh_no_h +#define cglm_view_lh_no_h + +#include "view_lh.h" + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_lh(eye, center, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_lh(eye, dir, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_lh(eye, dir, dest); +} + +#endif /*cglm_view_lh_no_h*/ diff --git a/include/cglm/clipspace/view_lh_zo.h b/include/cglm/clipspace/view_lh_zo.h new file mode 100644 index 0000000..0652906 --- /dev/null +++ b/include/cglm/clipspace/view_lh_zo.h @@ -0,0 +1,73 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_lh_zo_h +#define cglm_view_lh_zo_h + +#include "view_lh.h" + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_lh(eye, center, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_lh(eye, dir, up, dest); +} + +/*! + * @brief set up view matrix with left handed coordinate system. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_lh(eye, dir, dest); +} + +#endif /*cglm_view_lh_zo_h*/ diff --git a/include/cglm/clipspace/view_rh.h b/include/cglm/clipspace/view_rh.h new file mode 100644 index 0000000..51ec916 --- /dev/null +++ b/include/cglm/clipspace/view_rh.h @@ -0,0 +1,99 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_lookat_rh(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_rh(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_rh(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_rh_h +#define cglm_view_rh_h + +#include "../common.h" +#include "../plane.h" + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_rh(vec3 eye, vec3 center, vec3 up, mat4 dest) { + CGLM_ALIGN(8) vec3 f, u, s; + + glm_vec3_sub(center, eye, f); + glm_vec3_normalize(f); + + glm_vec3_crossn(f, up, s); + glm_vec3_cross(s, f, u); + + dest[0][0] = s[0]; + dest[0][1] = u[0]; + dest[0][2] =-f[0]; + dest[1][0] = s[1]; + dest[1][1] = u[1]; + dest[1][2] =-f[1]; + dest[2][0] = s[2]; + dest[2][1] = u[2]; + dest[2][2] =-f[2]; + dest[3][0] =-glm_vec3_dot(s, eye); + dest[3][1] =-glm_vec3_dot(u, eye); + dest[3][2] = glm_vec3_dot(f, eye); + dest[0][3] = dest[1][3] = dest[2][3] = 0.0f; + dest[3][3] = 1.0f; +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_rh(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + CGLM_ALIGN(8) vec3 target; + glm_vec3_add(eye, dir, target); + glm_lookat_rh(eye, target, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_rh(vec3 eye, vec3 dir, mat4 dest) { + CGLM_ALIGN(8) vec3 up; + glm_vec3_ortho(dir, up); + glm_look_rh(eye, dir, up, dest); +} + +#endif /*cglm_view_rh_h*/ diff --git a/include/cglm/clipspace/view_rh_no.h b/include/cglm/clipspace/view_rh_no.h new file mode 100644 index 0000000..14b8b4c --- /dev/null +++ b/include/cglm/clipspace/view_rh_no.h @@ -0,0 +1,73 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_rh_no_h +#define cglm_view_rh_no_h + +#include "view_rh.h" + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_rh(eye, center, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_rh(eye, dir, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_rh(eye, dir, dest); +} + +#endif /*cglm_view_rh_no_h*/ diff --git a/include/cglm/clipspace/view_rh_zo.h b/include/cglm/clipspace/view_rh_zo.h new file mode 100644 index 0000000..cbabe64 --- /dev/null +++ b/include/cglm/clipspace/view_rh_zo.h @@ -0,0 +1,73 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE void glm_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) + CGLM_INLINE void glm_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) + */ + +#ifndef cglm_view_rh_zo_h +#define cglm_view_rh_zo_h + +#include "view_rh.h" + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_rh(eye, center, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_rh(eye, dir, up, dest); +} + +/*! + * @brief set up view matrix with right handed coordinate system. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[out] dest result matrix + */ +CGLM_INLINE +void +glm_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_rh(eye, dir, dest); +} + +#endif /*cglm_view_rh_zo_h*/ diff --git a/include/cglm/common.h b/include/cglm/common.h index 810d7ef..94e8551 100644 --- a/include/cglm/common.h +++ b/include/cglm/common.h @@ -50,4 +50,35 @@ # define GLM_FLT_EPSILON FLT_EPSILON #endif +/* + * Clip control: define GLM_FORCE_DEPTH_ZERO_TO_ONE before including + * CGLM to use a clip space between 0 to 1. + * Coordinate system: define GLM_FORCE_LEFT_HANDED before including + * CGLM to use the left handed coordinate system by default. + */ + +#define CGLM_CLIP_CONTROL_ZO_BIT (1 << 0) /* ZERO_TO_ONE */ +#define CGLM_CLIP_CONTROL_NO_BIT (1 << 1) /* NEGATIVE_ONE_TO_ONE */ +#define CGLM_CLIP_CONTROL_LH_BIT (1 << 2) /* LEFT_HANDED, For DirectX, Metal, Vulkan */ +#define CGLM_CLIP_CONTROL_RH_BIT (1 << 3) /* RIGHT_HANDED, For OpenGL, default in GLM */ + +#define CGLM_CLIP_CONTROL_LH_ZO (CGLM_CLIP_CONTROL_LH_BIT | CGLM_CLIP_CONTROL_ZO_BIT) +#define CGLM_CLIP_CONTROL_LH_NO (CGLM_CLIP_CONTROL_LH_BIT | CGLM_CLIP_CONTROL_NO_BIT) +#define CGLM_CLIP_CONTROL_RH_ZO (CGLM_CLIP_CONTROL_RH_BIT | CGLM_CLIP_CONTROL_ZO_BIT) +#define CGLM_CLIP_CONTROL_RH_NO (CGLM_CLIP_CONTROL_RH_BIT | CGLM_CLIP_CONTROL_NO_BIT) + +#ifdef CGLM_FORCE_DEPTH_ZERO_TO_ONE +# ifdef CGLM_FORCE_LEFT_HANDED +# define CGLM_CONFIG_CLIP_CONTROL CGLM_CLIP_CONTROL_LH_ZO +# else +# define CGLM_CONFIG_CLIP_CONTROL CGLM_CLIP_CONTROL_RH_ZO +# endif +#else +# ifdef CGLM_FORCE_LEFT_HANDED +# define CGLM_CONFIG_CLIP_CONTROL CGLM_CLIP_CONTROL_LH_NO +# else +# define CGLM_CONFIG_CLIP_CONTROL CGLM_CLIP_CONTROL_RH_NO +# endif +#endif + #endif /* cglm_common_h */ diff --git a/include/cglm/plane.h b/include/cglm/plane.h index 15ae580..0504373 100644 --- a/include/cglm/plane.h +++ b/include/cglm/plane.h @@ -9,6 +9,7 @@ #define cglm_plane_h #include "common.h" +#include "vec3.h" #include "vec4.h" /* diff --git a/meson.build b/meson.build index e5e106a..6ee3277 100644 --- a/meson.build +++ b/meson.build @@ -48,7 +48,19 @@ cglm_src = files( 'src/sphere.c', 'src/vec2.c', 'src/vec3.c', - 'src/vec4.c' + 'src/vec4.c', + 'src/clipspace/ortho_lh_no.c', + 'src/clipspace/ortho_lh_zo.c', + 'src/clipspace/ortho_rh_no.c', + 'src/clipspace/ortho_rh_zo.c', + 'src/clipspace/persp_lh_no.c', + 'src/clipspace/persp_lh_zo.c', + 'src/clipspace/persp_rh_no.c', + 'src/clipspace/persp_rh_zo.c' + 'src/clipspace/view_lh_no.c', + 'src/clipspace/view_lh_zo.c', + 'src/clipspace/view_rh_no.c' + 'src/clipspace/view_rh_zo.c' ) cglm_lib = library('cglm', diff --git a/src/cam_lh_no.c b/src/cam_lh_no.c deleted file mode 100644 index 4354373..0000000 --- a/src/cam_lh_no.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -#include "../include/cglm/cglm.h" - -CGLM_EXPORT -void -glmc_perspective_lh_no(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - glm_perspective_lh_no(fovy, - aspect, - nearVal, - farVal, - dest); -} - diff --git a/src/cam_lh_zo.c b/src/cam_lh_zo.c deleted file mode 100644 index a64dcd4..0000000 --- a/src/cam_lh_zo.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -#include "../include/cglm/cglm.h" - -CGLM_EXPORT -void -glmc_perspective_lh_zo(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - glm_perspective_lh_zo(fovy, - aspect, - nearVal, - farVal, - dest); -} - diff --git a/src/cam_rh_no.c b/src/cam_rh_no.c deleted file mode 100644 index 3d7d4a8..0000000 --- a/src/cam_rh_no.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -#include "../include/cglm/cglm.h" - -CGLM_EXPORT -void -glmc_perspective_rh_no(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - glm_perspective_rh_no(fovy, - aspect, - nearVal, - farVal, - dest); -} - diff --git a/src/cam_rh_zo.c b/src/cam_rh_zo.c deleted file mode 100644 index 949a506..0000000 --- a/src/cam_rh_zo.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c), Recep Aslantas. - * - * MIT License (MIT), http://opensource.org/licenses/MIT - * Full license can be found in the LICENSE file - */ - -#include "../include/cglm/cglm.h" - -CGLM_EXPORT -void -glmc_perspective_rh_zo(float fovy, - float aspect, - float nearVal, - float farVal, - mat4 dest) { - glm_perspective_rh_zo(fovy, - aspect, - nearVal, - farVal, - dest); -} - diff --git a/src/clipspace/ortho_lh_no.c b/src/clipspace/ortho_lh_no.c new file mode 100644 index 0000000..df58562 --- /dev/null +++ b/src/clipspace/ortho_lh_no.c @@ -0,0 +1,51 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/clipspace/ortho_lh_no.h" + +CGLM_EXPORT +void +glmc_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho_lh_no(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_lh_no(vec3 box[2], mat4 dest) { + glm_ortho_aabb_lh_no(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p_lh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p_lh_no(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_lh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz_lh_no(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_lh_no(float aspect, mat4 dest) { + glm_ortho_default_lh_no(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s_lh_no(float aspect, float size, mat4 dest) { + glm_ortho_default_s_lh_no(aspect, size, dest); +} diff --git a/src/clipspace/ortho_lh_zo.c b/src/clipspace/ortho_lh_zo.c new file mode 100644 index 0000000..65c875b --- /dev/null +++ b/src/clipspace/ortho_lh_zo.c @@ -0,0 +1,51 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/clipspace/ortho_lh_zo.h" + +CGLM_EXPORT +void +glmc_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho_lh_zo(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_lh_zo(vec3 box[2], mat4 dest) { + glm_ortho_aabb_lh_zo(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p_lh_zo(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz_lh_zo(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_lh_zo(float aspect, mat4 dest) { + glm_ortho_default_lh_zo(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s_lh_zo(float aspect, float size, mat4 dest) { + glm_ortho_default_s_lh_zo(aspect, size, dest); +} diff --git a/src/clipspace/ortho_rh_no.c b/src/clipspace/ortho_rh_no.c new file mode 100644 index 0000000..e350d30 --- /dev/null +++ b/src/clipspace/ortho_rh_no.c @@ -0,0 +1,51 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/clipspace/ortho_rh_no.h" + +CGLM_EXPORT +void +glmc_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho_rh_no(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_rh_no(vec3 box[2], mat4 dest) { + glm_ortho_aabb_rh_no(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p_rh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p_rh_no(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_rh_no(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz_rh_no(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_rh_no(float aspect, mat4 dest) { + glm_ortho_default_rh_no(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s_rh_no(float aspect, float size, mat4 dest) { + glm_ortho_default_s_rh_no(aspect, size, dest); +} diff --git a/src/clipspace/ortho_rh_zo.c b/src/clipspace/ortho_rh_zo.c new file mode 100644 index 0000000..4fd4b68 --- /dev/null +++ b/src/clipspace/ortho_rh_zo.c @@ -0,0 +1,51 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/clipspace/ortho_rh_zo.h" + +CGLM_EXPORT +void +glmc_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_ortho_rh_zo(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_rh_zo(vec3 box[2], mat4 dest) { + glm_ortho_aabb_rh_zo(box, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_p_rh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_p_rh_zo(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_aabb_pz_rh_zo(vec3 box[2], float padding, mat4 dest) { + glm_ortho_aabb_pz_rh_zo(box, padding, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_rh_zo(float aspect, mat4 dest) { + glm_ortho_default_rh_zo(aspect, dest); +} + +CGLM_EXPORT +void +glmc_ortho_default_s_rh_zo(float aspect, float size, mat4 dest) { + glm_ortho_default_s_rh_zo(aspect, size, dest); +} diff --git a/src/clipspace/persp_lh_no.c b/src/clipspace/persp_lh_no.c new file mode 100644 index 0000000..b52ebec --- /dev/null +++ b/src/clipspace/persp_lh_no.c @@ -0,0 +1,109 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/clipspace/persp_lh_no.h" + +CGLM_EXPORT +void +glmc_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum_lh_no(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_perspective_lh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_lh_no(fovy, + aspect, + nearVal, + farVal, + dest); +} + +CGLM_EXPORT +void +glmc_persp_move_far_lh_no(mat4 proj, float deltaFar) { + glm_persp_move_far_lh_no(proj, deltaFar); +} + +CGLM_EXPORT +void +glmc_persp_decomp_lh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_lh_no(proj, nearZ, farZ, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv_lh_no(mat4 proj, float dest[6]) { + glm_persp_decompv_lh_no(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x_lh_no(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_lh_no(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y_lh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_lh_no(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z_lh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_lh_no(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far_lh_no(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far_lh_no(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near_lh_no(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near_lh_no(proj, nearZ); +} + +CGLM_EXPORT +void +glmc_persp_sizes_lh_no(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes_lh_no(proj, fovy, dest); +} + +CGLM_EXPORT +float +glmc_persp_fovy_lh_no(mat4 proj) { + return glm_persp_fovy_lh_no(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect_lh_no(mat4 proj) { + return glm_persp_aspect_lh_no(proj); +} diff --git a/src/clipspace/persp_lh_zo.c b/src/clipspace/persp_lh_zo.c new file mode 100644 index 0000000..ec0ba95 --- /dev/null +++ b/src/clipspace/persp_lh_zo.c @@ -0,0 +1,109 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/clipspace/persp_lh_zo.h" + +CGLM_EXPORT +void +glmc_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum_lh_zo(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_perspective_lh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_lh_zo(fovy, + aspect, + nearVal, + farVal, + dest); +} + +CGLM_EXPORT +void +glmc_persp_move_far_lh_zo(mat4 proj, float deltaFar) { + glm_persp_move_far_lh_zo(proj, deltaFar); +} + +CGLM_EXPORT +void +glmc_persp_decomp_lh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_lh_zo(proj, nearZ, farZ, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv_lh_zo(mat4 proj, float dest[6]) { + glm_persp_decompv_lh_zo(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x_lh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_lh_zo(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y_lh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_lh_zo(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z_lh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_lh_zo(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far_lh_zo(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far_lh_zo(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near_lh_zo(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near_lh_zo(proj, nearZ); +} + +CGLM_EXPORT +void +glmc_persp_sizes_lh_zo(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes_lh_zo(proj, fovy, dest); +} + +CGLM_EXPORT +float +glmc_persp_fovy_lh_zo(mat4 proj) { + return glm_persp_fovy_lh_zo(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect_lh_zo(mat4 proj) { + return glm_persp_aspect_lh_zo(proj); +} diff --git a/src/clipspace/persp_rh_no.c b/src/clipspace/persp_rh_no.c new file mode 100644 index 0000000..5a3ed3e --- /dev/null +++ b/src/clipspace/persp_rh_no.c @@ -0,0 +1,109 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/clipspace/persp_rh_no.h" + +CGLM_EXPORT +void +glmc_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum_rh_no(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_perspective_rh_no(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_rh_no(fovy, + aspect, + nearVal, + farVal, + dest); +} + +CGLM_EXPORT +void +glmc_persp_move_far_rh_no(mat4 proj, float deltaFar) { + glm_persp_move_far_rh_no(proj, deltaFar); +} + +CGLM_EXPORT +void +glmc_persp_decomp_rh_no(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_rh_no(proj, nearZ, farZ, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv_rh_no(mat4 proj, float dest[6]) { + glm_persp_decompv_rh_no(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x_rh_no(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_rh_no(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y_rh_no(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_rh_no(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z_rh_no(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_rh_no(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far_rh_no(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far_rh_no(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near_rh_no(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near_rh_no(proj, nearZ); +} + +CGLM_EXPORT +void +glmc_persp_sizes_rh_no(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes_rh_no(proj, fovy, dest); +} + +CGLM_EXPORT +float +glmc_persp_fovy_rh_no(mat4 proj) { + return glm_persp_fovy_rh_no(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect_rh_no(mat4 proj) { + return glm_persp_aspect_rh_no(proj); +} diff --git a/src/clipspace/persp_rh_zo.c b/src/clipspace/persp_rh_zo.c new file mode 100644 index 0000000..4e4fc5a --- /dev/null +++ b/src/clipspace/persp_rh_zo.c @@ -0,0 +1,109 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/clipspace/persp_rh_zo.h" + +CGLM_EXPORT +void +glmc_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ, + mat4 dest) { + glm_frustum_rh_zo(left, right, + bottom, top, + nearZ, farZ, + dest); +} + +CGLM_EXPORT +void +glmc_perspective_rh_zo(float fovy, + float aspect, + float nearVal, + float farVal, + mat4 dest) { + glm_perspective_rh_zo(fovy, + aspect, + nearVal, + farVal, + dest); +} + +CGLM_EXPORT +void +glmc_persp_move_far_rh_zo(mat4 proj, float deltaFar) { + glm_persp_move_far_rh_zo(proj, deltaFar); +} + +CGLM_EXPORT +void +glmc_persp_decomp_rh_zo(mat4 proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_rh_zo(proj, nearZ, farZ, top, bottom, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decompv_rh_zo(mat4 proj, float dest[6]) { + glm_persp_decompv_rh_zo(proj, dest); +} + +CGLM_EXPORT +void +glmc_persp_decomp_x_rh_zo(mat4 proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_rh_zo(proj, left, right); +} + +CGLM_EXPORT +void +glmc_persp_decomp_y_rh_zo(mat4 proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_rh_zo(proj, top, bottom); +} + +CGLM_EXPORT +void +glmc_persp_decomp_z_rh_zo(mat4 proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_rh_zo(proj, nearZ, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_far_rh_zo(mat4 proj, float * __restrict farZ) { + glm_persp_decomp_far_rh_zo(proj, farZ); +} + +CGLM_EXPORT +void +glmc_persp_decomp_near_rh_zo(mat4 proj, float * __restrict nearZ) { + glm_persp_decomp_near_rh_zo(proj, nearZ); +} + +CGLM_EXPORT +void +glmc_persp_sizes_rh_zo(mat4 proj, float fovy, vec4 dest) { + glm_persp_sizes_rh_zo(proj, fovy, dest); +} + +CGLM_EXPORT +float +glmc_persp_fovy_rh_zo(mat4 proj) { + return glm_persp_fovy_rh_zo(proj); +} + +CGLM_EXPORT +float +glmc_persp_aspect_rh_zo(mat4 proj) { + return glm_persp_aspect_rh_zo(proj); +} diff --git a/src/clipspace/view_lh_no.c b/src/clipspace/view_lh_no.c new file mode 100644 index 0000000..e2376b8 --- /dev/null +++ b/src/clipspace/view_lh_no.c @@ -0,0 +1,27 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/clipspace/view_lh_no.h" + +CGLM_EXPORT +void +glmc_lookat_lh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_lh_no(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look_lh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_lh_no(eye, dir, up, dest); +} + +CGLM_EXPORT +void +glmc_look_anyup_lh_no(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_lh_no(eye, dir, dest); +} diff --git a/src/clipspace/view_lh_zo.c b/src/clipspace/view_lh_zo.c new file mode 100644 index 0000000..7d75360 --- /dev/null +++ b/src/clipspace/view_lh_zo.c @@ -0,0 +1,27 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/clipspace/view_lh_zo.h" + +CGLM_EXPORT +void +glmc_lookat_lh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_lh_zo(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look_lh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_lh_zo(eye, dir, up, dest); +} + +CGLM_EXPORT +void +glmc_look_anyup_lh_zo(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_lh_zo(eye, dir, dest); +} diff --git a/src/clipspace/view_rh_no.c b/src/clipspace/view_rh_no.c new file mode 100644 index 0000000..15fab70 --- /dev/null +++ b/src/clipspace/view_rh_no.c @@ -0,0 +1,27 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/clipspace/view_rh_no.h" + +CGLM_EXPORT +void +glmc_lookat_rh_no(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_rh_no(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look_rh_no(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_rh_no(eye, dir, up, dest); +} + +CGLM_EXPORT +void +glmc_look_anyup_rh_no(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_rh_no(eye, dir, dest); +} diff --git a/src/clipspace/view_rh_zo.c b/src/clipspace/view_rh_zo.c new file mode 100644 index 0000000..9672182 --- /dev/null +++ b/src/clipspace/view_rh_zo.c @@ -0,0 +1,27 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/clipspace/view_rh_zo.h" + +CGLM_EXPORT +void +glmc_lookat_rh_zo(vec3 eye, vec3 center, vec3 up, mat4 dest) { + glm_lookat_rh_zo(eye, center, up, dest); +} + +CGLM_EXPORT +void +glmc_look_rh_zo(vec3 eye, vec3 dir, vec3 up, mat4 dest) { + glm_look_rh_zo(eye, dir, up, dest); +} + +CGLM_EXPORT +void +glmc_look_anyup_rh_zo(vec3 eye, vec3 dir, mat4 dest) { + glm_look_anyup_rh_zo(eye, dir, dest); +} diff --git a/test/include/common.h b/test/include/common.h index bf64ee5..2eb2e83 100644 --- a/test/include/common.h +++ b/test/include/common.h @@ -20,6 +20,10 @@ # define _GNU_SOURCE /* for drand48() */ #endif +#ifndef CGLM_CLIPSPACE_INCLUDE_ALL +# define CGLM_CLIPSPACE_INCLUDE_ALL +#endif + #include #include #include diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 336ff0b..ab93120 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -70,8 +70,35 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -285,4 +312,4 @@ - \ No newline at end of file + From eddaf464fff7ea97e965d0773c0ab42011cb68f7 Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Fri, 14 May 2021 15:25:29 +0200 Subject: [PATCH 06/13] style: fix missing whitespace for alignment Co-authored-by: Michael --- include/cglm/call/clipspace/ortho_lh_no.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/cglm/call/clipspace/ortho_lh_no.h b/include/cglm/call/clipspace/ortho_lh_no.h index 3fc72a1..c19692c 100644 --- a/include/cglm/call/clipspace/ortho_lh_no.h +++ b/include/cglm/call/clipspace/ortho_lh_no.h @@ -17,7 +17,7 @@ CGLM_EXPORT void glmc_ortho_lh_no(float left, float right, float bottom, float top, - float nearZ, float farZ, + float nearZ, float farZ, mat4 dest); CGLM_EXPORT From 403097d56cd15d9753f76cf6a69cb821474c5a1e Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Fri, 14 May 2021 15:27:01 +0200 Subject: [PATCH 07/13] build: fix duplicate line in CMakeLists.txt --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a6e27fe..406a1fc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,6 @@ add_library(${PROJECT_NAME} src/quat.c src/cam.c src/vec2.c - src/vec2.c src/vec3.c src/vec4.c src/mat2.c From 89e8c352ecddf3a0a103936ea9f45268a2ac5375 Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Fri, 14 May 2021 15:44:10 +0200 Subject: [PATCH 08/13] style: fix missing whitespace for alignment Co-authored-by: Michael --- 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_lh_zo.h | 2 +- include/cglm/call/clipspace/persp_rh_no.h | 2 +- include/cglm/call/clipspace/persp_rh_zo.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/cglm/call/clipspace/ortho_lh_zo.h b/include/cglm/call/clipspace/ortho_lh_zo.h index 81af396..572182c 100644 --- a/include/cglm/call/clipspace/ortho_lh_zo.h +++ b/include/cglm/call/clipspace/ortho_lh_zo.h @@ -17,7 +17,7 @@ CGLM_EXPORT void glmc_ortho_lh_zo(float left, float right, float bottom, float top, - float nearZ, float farZ, + float nearZ, float farZ, mat4 dest); CGLM_EXPORT diff --git a/include/cglm/call/clipspace/ortho_rh_no.h b/include/cglm/call/clipspace/ortho_rh_no.h index 8ffd9de..c11acdc 100644 --- a/include/cglm/call/clipspace/ortho_rh_no.h +++ b/include/cglm/call/clipspace/ortho_rh_no.h @@ -17,7 +17,7 @@ CGLM_EXPORT void glmc_ortho_rh_no(float left, float right, float bottom, float top, - float nearZ, float farZ, + float nearZ, float farZ, mat4 dest); CGLM_EXPORT diff --git a/include/cglm/call/clipspace/ortho_rh_zo.h b/include/cglm/call/clipspace/ortho_rh_zo.h index 98572a3..ba8d9ae 100644 --- a/include/cglm/call/clipspace/ortho_rh_zo.h +++ b/include/cglm/call/clipspace/ortho_rh_zo.h @@ -17,7 +17,7 @@ CGLM_EXPORT void glmc_ortho_rh_zo(float left, float right, float bottom, float top, - float nearZ, float farZ, + float nearZ, float farZ, mat4 dest); CGLM_EXPORT diff --git a/include/cglm/call/clipspace/persp_lh_no.h b/include/cglm/call/clipspace/persp_lh_no.h index badd081..25426a7 100644 --- a/include/cglm/call/clipspace/persp_lh_no.h +++ b/include/cglm/call/clipspace/persp_lh_no.h @@ -17,7 +17,7 @@ CGLM_EXPORT void glmc_frustum_lh_no(float left, float right, float bottom, float top, - float nearZ, float farZ, + float nearZ, float farZ, mat4 dest); CGLM_EXPORT diff --git a/include/cglm/call/clipspace/persp_lh_zo.h b/include/cglm/call/clipspace/persp_lh_zo.h index cbe79d9..c22deac 100644 --- a/include/cglm/call/clipspace/persp_lh_zo.h +++ b/include/cglm/call/clipspace/persp_lh_zo.h @@ -17,7 +17,7 @@ CGLM_EXPORT void glmc_frustum_lh_zo(float left, float right, float bottom, float top, - float nearZ, float farZ, + float nearZ, float farZ, mat4 dest); CGLM_EXPORT diff --git a/include/cglm/call/clipspace/persp_rh_no.h b/include/cglm/call/clipspace/persp_rh_no.h index b4537ef..7909904 100644 --- a/include/cglm/call/clipspace/persp_rh_no.h +++ b/include/cglm/call/clipspace/persp_rh_no.h @@ -17,7 +17,7 @@ CGLM_EXPORT void glmc_frustum_rh_no(float left, float right, float bottom, float top, - float nearZ, float farZ, + float nearZ, float farZ, mat4 dest); CGLM_EXPORT diff --git a/include/cglm/call/clipspace/persp_rh_zo.h b/include/cglm/call/clipspace/persp_rh_zo.h index 4ea0945..cf9f7dc 100644 --- a/include/cglm/call/clipspace/persp_rh_zo.h +++ b/include/cglm/call/clipspace/persp_rh_zo.h @@ -17,7 +17,7 @@ CGLM_EXPORT void glmc_frustum_rh_zo(float left, float right, float bottom, float top, - float nearZ, float farZ, + float nearZ, float farZ, mat4 dest); CGLM_EXPORT From 4d20f97275211dbce8a81a7316a89a618ca73a55 Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Fri, 14 May 2021 16:32:54 +0200 Subject: [PATCH 09/13] clipspace: fix typo'd clip control define --- include/cglm/cam.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/include/cglm/cam.h b/include/cglm/cam.h index 8dfac93..c8cfd42 100644 --- a/include/cglm/cam.h +++ b/include/cglm/cam.h @@ -348,9 +348,9 @@ glm_perspective_resize(float aspect, mat4 proj) { CGLM_INLINE void glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) { -#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT glm_lookat_lh(eye, center, up, dest); -#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT glm_lookat_rh(eye, center, up, dest); #endif } @@ -372,9 +372,9 @@ glm_lookat(vec3 eye, vec3 center, vec3 up, mat4 dest) { CGLM_INLINE void glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { -#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT glm_look_lh(eye, dir, up, dest); -#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT glm_look_rh(eye, dir, up, dest); #endif } @@ -392,9 +392,9 @@ glm_look(vec3 eye, vec3 dir, vec3 up, mat4 dest) { CGLM_INLINE void glm_look_anyup(vec3 eye, vec3 dir, mat4 dest) { -#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH +#if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_LH_BIT glm_look_anyup_lh(eye, dir, dest); -#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH +#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_RH_BIT glm_look_anyup_rh(eye, dir, dest); #endif } From a5af9e5eac64036d2251dd7f85d81222175c8e55 Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Fri, 14 May 2021 16:49:18 +0200 Subject: [PATCH 10/13] build: fix Makefile.am missing clipspace source files --- Makefile.am | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile.am b/Makefile.am index a2b8a41..8e8cb91 100644 --- a/Makefile.am +++ b/Makefile.am @@ -161,10 +161,6 @@ libcglm_la_SOURCES=\ src/io.c \ src/quat.c \ src/cam.c \ - src/cam_lh_zo.c \ - src/cam_rh_zo.c \ - src/cam_lh_no.c \ - src/cam_rh_no.c \ src/vec2.c \ src/vec3.c \ src/vec4.c \ @@ -180,7 +176,19 @@ libcglm_la_SOURCES=\ src/curve.c \ src/bezier.c \ src/ray.c \ - src/affine2d.c + src/affine2d.c \ + src/clipspace/ortho_lh_no.c \ + src/clipspace/ortho_lh_zo.c \ + src/clipspace/ortho_rh_no.c \ + src/clipspace/ortho_rh_zo.c \ + src/clipspace/persp_lh_no.c \ + src/clipspace/persp_lh_zo.c \ + src/clipspace/persp_rh_no.c \ + src/clipspace/persp_rh_zo.c \ + src/clipspace/view_lh_no.c \ + src/clipspace/view_lh_zo.c \ + src/clipspace/view_rh_no.c \ + src/clipspace/view_rh_zo.c test_tests_SOURCES=\ test/runner.c \ From 56ec058c7dcc23c6e568eb943f28f14d38bc64df Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Fri, 14 May 2021 16:55:11 +0200 Subject: [PATCH 11/13] style: fix documentation consistency for describing clipspace --- include/cglm/clipspace/ortho_lh_zo.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/include/cglm/clipspace/ortho_lh_zo.h b/include/cglm/clipspace/ortho_lh_zo.h index c88322a..f49f8f0 100644 --- a/include/cglm/clipspace/ortho_lh_zo.h +++ b/include/cglm/clipspace/ortho_lh_zo.h @@ -68,8 +68,7 @@ glm_ortho_lh_zo(float left, float right, /*! * @brief set up orthographic projection matrix using bounding box - * with a left-hand coordinate system and a clip-space with depth - * values from zero to one. + * with a left-hand coordinate system and a clip-space of [0, 1]. * * bounding box (AABB) must be in view space * @@ -87,8 +86,7 @@ glm_ortho_aabb_lh_zo(vec3 box[2], mat4 dest) { /*! * @brief set up orthographic projection matrix using bounding box - * with a left-hand coordinate system and a clip-space with depth - * values from zero to one. + * with a left-hand coordinate system and a clip-space of [0, 1]. * * bounding box (AABB) must be in view space * @@ -107,8 +105,7 @@ glm_ortho_aabb_p_lh_zo(vec3 box[2], float padding, mat4 dest) { /*! * @brief set up orthographic projection matrix using bounding box - * with a left-hand coordinate system and a clip-space with depth - * values from zero to one. + * with a left-hand coordinate system and a clip-space of [0, 1]. * * bounding box (AABB) must be in view space * @@ -126,8 +123,8 @@ glm_ortho_aabb_pz_lh_zo(vec3 box[2], float padding, mat4 dest) { } /*! - * @brief set up unit orthographic projection matrix with a left-hand - * coordinate system and a clip-space of [0, 1]. + * @brief set up unit orthographic projection matrix + * with a left-hand coordinate system and a clip-space of [0, 1]. * * @param[in] aspect aspect ration ( width / height ) * @param[out] dest result matrix @@ -147,8 +144,7 @@ glm_ortho_default_lh_zo(float aspect, mat4 dest) { /*! * @brief set up orthographic projection matrix with given CUBE size - * with a left-hand coordinate system and a clip-space with depth - * values from zero to one. + * with a left-hand coordinate system and a clip-space of [0, 1]. * * @param[in] aspect aspect ratio ( width / height ) * @param[in] size cube size From 8ddb5d5740a9d27e5784c8fe97808294b809f7da Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Fri, 14 May 2021 16:58:48 +0200 Subject: [PATCH 12/13] build: fix incorrect include paths for libcglm --- src/clipspace/ortho_lh_no.c | 4 ++-- src/clipspace/ortho_lh_zo.c | 4 ++-- src/clipspace/ortho_rh_no.c | 4 ++-- src/clipspace/ortho_rh_zo.c | 4 ++-- src/clipspace/persp_lh_no.c | 2 +- src/clipspace/persp_lh_zo.c | 2 +- src/clipspace/persp_rh_no.c | 2 +- src/clipspace/persp_rh_zo.c | 2 +- src/clipspace/view_lh_no.c | 4 ++-- src/clipspace/view_lh_zo.c | 4 ++-- src/clipspace/view_rh_no.c | 4 ++-- src/clipspace/view_rh_zo.c | 4 ++-- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/clipspace/ortho_lh_no.c b/src/clipspace/ortho_lh_no.c index df58562..e83511d 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/cglm.h" +#include "../../include/cglm/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 65c875b..155d53e 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/cglm.h" +#include "../../include/cglm/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 e350d30..7f9c02b 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/cglm.h" +#include "../../include/cglm/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 4fd4b68..33cb83a 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/cglm.h" +#include "../../include/cglm/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 b52ebec..fe58385 100644 --- a/src/clipspace/persp_lh_no.c +++ b/src/clipspace/persp_lh_no.c @@ -5,7 +5,7 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm/clipspace/persp_lh_no.h" +#include "../../include/cglm/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 ec0ba95..b0d5838 100644 --- a/src/clipspace/persp_lh_zo.c +++ b/src/clipspace/persp_lh_zo.c @@ -5,7 +5,7 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm/clipspace/persp_lh_zo.h" +#include "../../include/cglm/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 5a3ed3e..56bd89b 100644 --- a/src/clipspace/persp_rh_no.c +++ b/src/clipspace/persp_rh_no.c @@ -5,7 +5,7 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm/clipspace/persp_rh_no.h" +#include "../../include/cglm/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 4e4fc5a..03d7ac6 100644 --- a/src/clipspace/persp_rh_zo.c +++ b/src/clipspace/persp_rh_zo.c @@ -5,7 +5,7 @@ * Full license can be found in the LICENSE file */ -#include "../include/cglm/clipspace/persp_rh_zo.h" +#include "../../include/cglm/clipspace/persp_rh_zo.h" CGLM_EXPORT void diff --git a/src/clipspace/view_lh_no.c b/src/clipspace/view_lh_no.c index e2376b8..8bed6a3 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/cglm.h" +#include "../../include/cglm/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 7d75360..cee487c 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/cglm.h" +#include "../../include/cglm/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 15fab70..3548ff2 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/cglm.h" +#include "../../include/cglm/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 9672182..537daee 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/cglm.h" +#include "../../include/cglm/clipspace/view_rh_zo.h" CGLM_EXPORT void From 7f7e9f69dab6174a48af02393706bccfca3599e5 Mon Sep 17 00:00:00 2001 From: Tai Chi Minh Ralph Eastwood Date: Sat, 22 May 2021 22:41:03 +0200 Subject: [PATCH 13/13] clipspace: add struct API implementations --- include/cglm/struct/cam.h | 311 ++++++++++++++++---- include/cglm/struct/clipspace/ortho_lh_no.h | 152 ++++++++++ include/cglm/struct/clipspace/ortho_lh_zo.h | 152 ++++++++++ include/cglm/struct/clipspace/ortho_rh_no.h | 152 ++++++++++ include/cglm/struct/clipspace/ortho_rh_zo.h | 152 ++++++++++ include/cglm/struct/clipspace/persp_lh_no.h | 297 +++++++++++++++++++ include/cglm/struct/clipspace/persp_lh_zo.h | 297 +++++++++++++++++++ include/cglm/struct/clipspace/persp_rh_no.h | 297 +++++++++++++++++++ include/cglm/struct/clipspace/persp_rh_zo.h | 297 +++++++++++++++++++ include/cglm/struct/clipspace/view_lh_no.h | 88 ++++++ include/cglm/struct/clipspace/view_lh_zo.h | 88 ++++++ include/cglm/struct/clipspace/view_rh_no.h | 88 ++++++ include/cglm/struct/clipspace/view_rh_zo.h | 88 ++++++ 13 files changed, 2397 insertions(+), 62 deletions(-) create mode 100644 include/cglm/struct/clipspace/ortho_lh_no.h create mode 100644 include/cglm/struct/clipspace/ortho_lh_zo.h create mode 100644 include/cglm/struct/clipspace/ortho_rh_no.h create mode 100644 include/cglm/struct/clipspace/ortho_rh_zo.h create mode 100644 include/cglm/struct/clipspace/persp_lh_no.h create mode 100644 include/cglm/struct/clipspace/persp_lh_zo.h create mode 100644 include/cglm/struct/clipspace/persp_rh_no.h create mode 100644 include/cglm/struct/clipspace/persp_rh_zo.h create mode 100644 include/cglm/struct/clipspace/view_lh_no.h create mode 100644 include/cglm/struct/clipspace/view_lh_zo.h create mode 100644 include/cglm/struct/clipspace/view_rh_no.h create mode 100644 include/cglm/struct/clipspace/view_rh_zo.h diff --git a/include/cglm/struct/cam.h b/include/cglm/struct/cam.h index c1e954b..151eec4 100644 --- a/include/cglm/struct/cam.h +++ b/include/cglm/struct/cam.h @@ -51,6 +51,39 @@ #include "../plane.h" #include "../cam.h" +#ifndef CGLM_CLIPSPACE_INCLUDE_ALL +# if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO +# include "clipspace/ortho_lh_zo.h" +# include "clipspace/persp_lh_zo.h" +# include "clipspace/view_lh_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO +# include "clipspace/ortho_lh_no.h" +# include "clipspace/persp_lh_no.h" +# include "clipspace/view_lh_no.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO +# include "clipspace/ortho_rh_zo.h" +# include "clipspace/persp_rh_zo.h" +# include "clipspace/view_rh_zo.h" +# elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO +# include "clipspace/ortho_rh_no.h" +# include "clipspace/persp_rh_no.h" +# include "clipspace/view_rh_no.h" +# endif +#else +# include "clipspace/ortho_lh_zo.h" +# include "clipspace/persp_lh_zo.h" +# include "clipspace/ortho_lh_no.h" +# include "clipspace/persp_lh_no.h" +# include "clipspace/ortho_rh_zo.h" +# include "clipspace/persp_rh_zo.h" +# include "clipspace/ortho_rh_no.h" +# include "clipspace/persp_rh_no.h" +# include "clipspace/view_lh_zo.h" +# include "clipspace/view_lh_no.h" +# include "clipspace/view_rh_zo.h" +# include "clipspace/view_rh_no.h" +#endif + /*! * @brief set up perspective peprojection matrix * @@ -67,9 +100,15 @@ mat4s glms_frustum(float left, float right, float bottom, float top, float nearZ, float farZ) { - mat4s dest; - glm_frustum(left, right, bottom, top, nearZ, farZ, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_frustum_lh_zo(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_frustum_lh_no(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_frustum_rh_zo(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_frustum_rh_no(left, right, bottom, top, nearZ, farZ); +#endif } /*! @@ -88,9 +127,15 @@ mat4s glms_ortho(float left, float right, float bottom, float top, float nearZ, float farZ) { - mat4s dest; - glm_ortho(left, right, bottom, top, nearZ, farZ, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_lh_zo(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_lh_no(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_rh_zo(left, right, bottom, top, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_rh_no(left, right, bottom, top, nearZ, farZ); +#endif } /*! @@ -104,13 +149,15 @@ glms_ortho(float left, float right, CGLM_INLINE mat4s glms_ortho_aabb(vec3s box[2]) { - mat4s dest; - vec3 rawBox[2]; - - glms_vec3_unpack(rawBox, box, 2); - glm_ortho_aabb(rawBox, dest.raw); - - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_aabb_lh_zo(box); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_aabb_lh_no(box); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_aabb_rh_zo(box); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_aabb_rh_no(box); +#endif } /*! @@ -125,13 +172,15 @@ glms_ortho_aabb(vec3s box[2]) { CGLM_INLINE mat4s glms_ortho_aabb_p(vec3s box[2], float padding) { - mat4s dest; - vec3 rawBox[2]; - - glms_vec3_unpack(rawBox, box, 2); - glm_ortho_aabb_p(rawBox, padding, dest.raw); - - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_aabb_p_lh_zo(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_aabb_p_lh_no(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_aabb_p_rh_zo(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_aabb_p_rh_no(box, padding); +#endif } /*! @@ -146,13 +195,15 @@ glms_ortho_aabb_p(vec3s box[2], float padding) { CGLM_INLINE mat4s glms_ortho_aabb_pz(vec3s box[2], float padding) { - mat4s dest; - vec3 rawBox[2]; - - glms_vec3_unpack(rawBox, box, 2); - glm_ortho_aabb_pz(rawBox, padding, dest.raw); - - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_aabb_pz_lh_zo(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_aabb_pz_lh_no(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_aabb_pz_rh_zo(box, padding); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_aabb_pz_rh_no(box, padding); +#endif } /*! @@ -164,9 +215,15 @@ glms_ortho_aabb_pz(vec3s box[2], float padding) { CGLM_INLINE mat4s glms_ortho_default(float aspect) { - mat4s dest; - glm_ortho_default(aspect, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_default_lh_zo(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_default_lh_no(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_default_rh_zo(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_default_rh_no(aspect); +#endif } /*! @@ -179,9 +236,15 @@ glms_ortho_default(float aspect) { CGLM_INLINE mat4s glms_ortho_default_s(float aspect, float size) { - mat4s dest; - glm_ortho_default_s(aspect, size, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_ortho_default_s_lh_zo(aspect, size); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_ortho_default_s_lh_no(aspect, size); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_ortho_default_s_rh_zo(aspect, size); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_ortho_default_s_rh_no(aspect, size); +#endif } /*! @@ -196,9 +259,15 @@ glms_ortho_default_s(float aspect, float size) { CGLM_INLINE mat4s glms_perspective(float fovy, float aspect, float nearZ, float farZ) { - mat4s dest; - glm_perspective(fovy, aspect, nearZ, farZ, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_perspective_lh_zo(fovy, aspect, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_perspective_lh_no(fovy, aspect, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_perspective_rh_zo(fovy, aspect, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_perspective_rh_no(fovy, aspect, nearZ, farZ); +#endif } /*! @@ -212,7 +281,15 @@ glms_perspective(float fovy, float aspect, float nearZ, float farZ) { CGLM_INLINE void glms_persp_move_far(mat4s proj, float deltaFar) { - glm_persp_move_far(proj.raw, deltaFar); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_move_far_lh_zo(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_move_far_lh_no(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_move_far_rh_zo(proj, deltaFar); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_move_far_rh_no(proj, deltaFar); +#endif } /*! @@ -225,9 +302,15 @@ glms_persp_move_far(mat4s proj, float deltaFar) { CGLM_INLINE mat4s glms_perspective_default(float aspect) { - mat4s dest; - glm_perspective_default(aspect, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_perspective_default_lh_zo(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_perspective_default_lh_no(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_perspective_default_rh_zo(aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_perspective_default_rh_no(aspect); +#endif } /*! @@ -241,7 +324,15 @@ glms_perspective_default(float aspect) { CGLM_INLINE void glms_perspective_resize(mat4s proj, float aspect) { - glm_perspective_resize(aspect, proj.raw); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_perspective_resize_lh_zo(proj, aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_perspective_resize_lh_no(proj, aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_perspective_resize_rh_zo(proj, aspect); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_perspective_resize_rh_no(proj, aspect); +#endif } /*! @@ -258,9 +349,15 @@ glms_perspective_resize(mat4s proj, float aspect) { CGLM_INLINE mat4s glms_lookat(vec3s eye, vec3s center, vec3s up) { - mat4s dest; - glm_lookat(eye.raw, center.raw, up.raw, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_lookat_lh_zo(eye, center, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_lookat_lh_no(eye, center, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_lookat_rh_zo(eye, center, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_lookat_rh_no(eye, center, up); +#endif } /*! @@ -280,9 +377,15 @@ glms_lookat(vec3s eye, vec3s center, vec3s up) { CGLM_INLINE mat4s glms_look(vec3s eye, vec3s dir, vec3s up) { - mat4s dest; - glm_look(eye.raw, dir.raw, up.raw, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_look_lh_zo(eye, dir, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_look_lh_no(eye, dir, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_look_rh_zo(eye, dir, up); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_look_rh_no(eye, dir, up); +#endif } /*! @@ -298,9 +401,15 @@ glms_look(vec3s eye, vec3s dir, vec3s up) { CGLM_INLINE mat4s glms_look_anyup(vec3s eye, vec3s dir) { - mat4s dest; - glm_look_anyup(eye.raw, dir.raw, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_look_anyup_lh_zo(eye, dir); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_look_anyup_lh_no(eye, dir); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_look_anyup_rh_zo(eye, dir); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_look_anyup_rh_no(eye, dir); +#endif } /*! @@ -320,7 +429,15 @@ glms_persp_decomp(mat4s proj, float * __restrict nearZ, float * __restrict farZ, float * __restrict top, float * __restrict bottom, float * __restrict left, float * __restrict right) { - glm_persp_decomp(proj.raw, nearZ, farZ, top, bottom, left, right); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_lh_zo(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_lh_no(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_rh_zo(proj, nearZ, farZ, top, bottom, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_rh_no(proj, nearZ, farZ, top, bottom, left, right); +#endif } /*! @@ -333,7 +450,15 @@ glms_persp_decomp(mat4s proj, CGLM_INLINE void glms_persp_decompv(mat4s proj, float dest[6]) { - glm_persp_decompv(proj.raw, dest); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decompv_lh_zo(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decompv_lh_no(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decompv_rh_zo(proj, dest); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decompv_rh_no(proj, dest); +#endif } /*! @@ -349,7 +474,15 @@ void glms_persp_decomp_x(mat4s proj, float * __restrict left, float * __restrict right) { - glm_persp_decomp_x(proj.raw, left, right); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_x_lh_zo(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_x_lh_no(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_x_rh_zo(proj, left, right); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_x_rh_no(proj, left, right); +#endif } /*! @@ -365,7 +498,15 @@ void glms_persp_decomp_y(mat4s proj, float * __restrict top, float * __restrict bottom) { - glm_persp_decomp_y(proj.raw, top, bottom); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_persp_decomp_y_lh_zo(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_persp_decomp_y_lh_no(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_persp_decomp_y_rh_zo(proj, top, bottom); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_persp_decomp_y_rh_no(proj, top, bottom); +#endif } /*! @@ -381,7 +522,15 @@ void glms_persp_decomp_z(mat4s proj, float * __restrict nearZ, float * __restrict farZ) { - glm_persp_decomp_z(proj.raw, nearZ, farZ); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_z_lh_zo(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_z_lh_no(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_z_rh_zo(proj, nearZ, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_z_rh_no(proj, nearZ, farZ); +#endif } /*! @@ -393,7 +542,15 @@ glms_persp_decomp_z(mat4s proj, CGLM_INLINE void glms_persp_decomp_far(mat4s proj, float * __restrict farZ) { - glm_persp_decomp_far(proj.raw, farZ); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_far_lh_zo(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_far_lh_no(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_far_rh_zo(proj, farZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_far_rh_no(proj, farZ); +#endif } /*! @@ -405,7 +562,15 @@ glms_persp_decomp_far(mat4s proj, float * __restrict farZ) { CGLM_INLINE void glms_persp_decomp_near(mat4s proj, float * __restrict nearZ) { - glm_persp_decomp_near(proj.raw, nearZ); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + glms_persp_decomp_near_lh_zo(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + glms_persp_decomp_near_lh_no(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + glms_persp_decomp_near_rh_zo(proj, nearZ); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + glms_persp_decomp_near_rh_no(proj, nearZ); +#endif } /*! @@ -419,7 +584,15 @@ glms_persp_decomp_near(mat4s proj, float * __restrict nearZ) { CGLM_INLINE float glms_persp_fovy(mat4s proj) { - return glm_persp_fovy(proj.raw); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_persp_fovy_lh_zo(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_persp_fovy_lh_no(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_persp_fovy_rh_zo(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_persp_fovy_rh_no(proj); +#endif } /*! @@ -430,7 +603,15 @@ glms_persp_fovy(mat4s proj) { CGLM_INLINE float glms_persp_aspect(mat4s proj) { - return glm_persp_aspect(proj.raw); +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_persp_aspect_lh_zo(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_persp_aspect_lh_no(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_persp_aspect_rh_zo(proj); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_persp_aspect_rh_no(proj); +#endif } /*! @@ -443,9 +624,15 @@ glms_persp_aspect(mat4s proj) { CGLM_INLINE vec4s glms_persp_sizes(mat4s proj, float fovy) { - vec4s dest; - glm_persp_sizes(proj.raw, fovy, dest.raw); - return dest; +#if CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_ZO + return glms_persp_sizes_lh_zo(proj, fovy); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_LH_NO + return glms_persp_sizes_lh_no(proj, fovy); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_ZO + return glms_persp_sizes_rh_zo(proj, fovy); +#elif CGLM_CONFIG_CLIP_CONTROL == CGLM_CLIP_CONTROL_RH_NO + return glms_persp_sizes_rh_no(proj, fovy); +#endif } #endif /* cglms_cam_h */ diff --git a/include/cglm/struct/clipspace/ortho_lh_no.h b/include/cglm/struct/clipspace/ortho_lh_no.h new file mode 100644 index 0000000..9a22ff5 --- /dev/null +++ b/include/cglm/struct/clipspace/ortho_lh_no.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho_aabb_lh_no(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p_lh_no(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz_lh_no(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default_lh_no(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s_lh_no(float aspect, float size) + */ + +#ifndef cglms_ortho_lh_no_h +#define cglms_ortho_lh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_ortho_lh_no(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_lh_no(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_lh_no(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_p_lh_no(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p_lh_no(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_pz_lh_no(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz_lh_no(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_lh_no(float aspect) { + mat4s dest; + glm_ortho_default_lh_no(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s_lh_no(float aspect, float size) { + mat4s dest; + glm_ortho_default_s_lh_no(aspect, size, dest.raw); + return dest; +} + +#endif /* cglms_ortho_lh_no_h */ diff --git a/include/cglm/struct/clipspace/ortho_lh_zo.h b/include/cglm/struct/clipspace/ortho_lh_zo.h new file mode 100644 index 0000000..09f4731 --- /dev/null +++ b/include/cglm/struct/clipspace/ortho_lh_zo.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho_aabb_lh_zo(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p_lh_zo(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz_lh_zo(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default_lh_zo(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s_lh_zo(float aspect, float size) + */ + +#ifndef cglms_ortho_lh_zo_h +#define cglms_ortho_lh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_ortho_lh_zo(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_lh_zo(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_lh_zo(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_p_lh_zo(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p_lh_zo(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_pz_lh_zo(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz_lh_zo(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_lh_zo(float aspect) { + mat4s dest; + glm_ortho_default_lh_zo(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s_lh_zo(float aspect, float size) { + mat4s dest; + glm_ortho_default_s_lh_zo(aspect, size, dest.raw); + return dest; +} + +#endif /* cglms_ortho_lh_zo_h */ diff --git a/include/cglm/struct/clipspace/ortho_rh_no.h b/include/cglm/struct/clipspace/ortho_rh_no.h new file mode 100644 index 0000000..28bd275 --- /dev/null +++ b/include/cglm/struct/clipspace/ortho_rh_no.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho_aabb_rh_no(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p_rh_no(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz_rh_no(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default_rh_no(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s_rh_no(float aspect, float size) + */ + +#ifndef cglms_ortho_rh_no_h +#define cglms_ortho_rh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_ortho_rh_no(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_rh_no(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_rh_no(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_p_rh_no(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p_rh_no(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_pz_rh_no(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz_rh_no(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_rh_no(float aspect) { + mat4s dest; + glm_ortho_default_rh_no(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s_rh_no(float aspect, float size) { + mat4s dest; + glm_ortho_default_s_rh_no(aspect, size, dest.raw); + return dest; +} + +#endif /* cglms_ortho_rh_no_h */ diff --git a/include/cglm/struct/clipspace/ortho_rh_zo.h b/include/cglm/struct/clipspace/ortho_rh_zo.h new file mode 100644 index 0000000..0758d62 --- /dev/null +++ b/include/cglm/struct/clipspace/ortho_rh_zo.h @@ -0,0 +1,152 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_ortho_aabb_rh_zo(vec3s box[2]); + CGLM_INLINE mat4s glms_ortho_aabb_p_rh_zo(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_aabb_pz_rh_zo(vec3s box[2], float padding); + CGLM_INLINE mat4s glms_ortho_default_rh_zo(float aspect) + CGLM_INLINE mat4s glms_ortho_default_s_rh_zo(float aspect, float size) + */ + +#ifndef cglms_ortho_rh_zo_h +#define cglms_ortho_rh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_ortho_rh_zo(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_rh_zo(vec3s box[2]) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_rh_zo(rawBox, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_p_rh_zo(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_p_rh_zo(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up orthographic projection matrix using bounding box + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * bounding box (AABB) must be in view space + * + * @param[in] box AABB + * @param[in] padding padding for near and far + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_aabb_pz_rh_zo(vec3s box[2], float padding) { + mat4s dest; + vec3 rawBox[2]; + + glms_vec3_unpack(rawBox, box, 2); + glm_ortho_aabb_pz_rh_zo(rawBox, padding, dest.raw); + + return dest; +} + +/*! + * @brief set up unit orthographic projection matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ration ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_rh_zo(float aspect) { + mat4s dest; + glm_ortho_default_rh_zo(aspect, dest.raw); + return dest; +} + +/*! + * @brief set up orthographic projection matrix with given CUBE size + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] size cube size + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_ortho_default_s_rh_zo(float aspect, float size) { + mat4s dest; + glm_ortho_default_s_rh_zo(aspect, size, dest.raw); + return dest; +} + +#endif /* cglms_ortho_rh_zo_h */ diff --git a/include/cglm/struct/clipspace/persp_lh_no.h b/include/cglm/struct/clipspace/persp_lh_no.h new file mode 100644 index 0000000..af957ad --- /dev/null +++ b/include/cglm/struct/clipspace/persp_lh_no.h @@ -0,0 +1,297 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_perspective_lh_no(float fovy, + float aspect, + float nearZ, + float farZ) + CGLM_INLINE void glms_persp_move_far_lh_no(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default_lh_no(float aspect) + CGLM_INLINE void glms_perspective_resize_lh_no(mat4s proj, float aspect) + CGLM_INLINE void glms_persp_decomp_lh_no(mat4s proj, + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv_lh_no(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x_lh_no(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y_lh_no(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z_lh_no(mat4s proj, float *nearv, float *farv) + CGLM_INLINE void glms_persp_decomp_far_lh_no(mat4s proj, float *farZ) + CGLM_INLINE void glms_persp_decomp_near_lh_no(mat4s proj, float *nearZ) + CGLM_INLINE float glms_persp_fovy_lh_no(mat4s proj) + CGLM_INLINE float glms_persp_aspect_lh_no(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes_lh_no(mat4s proj, float fovy) + */ + +#ifndef cglms_persp_lh_no_h +#define cglms_persp_lh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum_lh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_frustum_lh_no(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_lh_no(float fovy, float aspect, float nearZ, float farZ) { + mat4s dest; + glm_perspective_lh_no(fovy, aspect, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glms_persp_move_far_lh_no(mat4s proj, float deltaFar) { + glm_persp_move_far_lh_no(proj.raw, deltaFar); +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default_lh_no(float aspect) { + mat4s dest; + glm_perspective_default_lh_no(aspect, dest.raw); + return dest; +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +void +glms_perspective_resize_lh_no(mat4s proj, float aspect) { + glm_perspective_resize_lh_no(aspect, proj.raw); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_lh_no(mat4s proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_lh_no(proj.raw, nearZ, farZ, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv_lh_no(mat4s proj, float dest[6]) { + glm_persp_decompv_lh_no(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_x_lh_no(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_lh_no(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * y stands for y axis (top / botom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glms_persp_decomp_y_lh_no(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_lh_no(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z_lh_no(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_lh_no(proj.raw, nearZ, farZ); +} + +/*! + * @brief decomposes far value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far_lh_no(mat4s proj, float * __restrict farZ) { + glm_persp_decomp_far_lh_no(proj.raw, farZ); +} + +/*! + * @brief decomposes near value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near_lh_no(mat4s proj, float * __restrict nearZ) { + glm_persp_decomp_near_lh_no(proj.raw, nearZ); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_fovy_lh_no(mat4s proj) { + return glm_persp_fovy_lh_no(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect_lh_no(mat4s proj) { + return glm_persp_aspect_lh_no(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @returns sizes as vector, sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +vec4s +glms_persp_sizes_lh_no(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes_lh_no(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_persp_lh_no_h */ diff --git a/include/cglm/struct/clipspace/persp_lh_zo.h b/include/cglm/struct/clipspace/persp_lh_zo.h new file mode 100644 index 0000000..e1ddacc --- /dev/null +++ b/include/cglm/struct/clipspace/persp_lh_zo.h @@ -0,0 +1,297 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_perspective_lh_zo(float fovy, + float aspect, + float nearZ, + float farZ) + CGLM_INLINE void glms_persp_move_far_lh_zo(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default_lh_zo(float aspect) + CGLM_INLINE void glms_perspective_resize_lh_zo(mat4s proj, float aspect) + CGLM_INLINE void glms_persp_decomp_lh_zo(mat4s proj, + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv_lh_zo(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x_lh_zo(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y_lh_zo(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z_lh_zo(mat4s proj, float *nearv, float *farv) + CGLM_INLINE void glms_persp_decomp_far_lh_zo(mat4s proj, float *farZ) + CGLM_INLINE void glms_persp_decomp_near_lh_zo(mat4s proj, float *nearZ) + CGLM_INLINE float glms_persp_fovy_lh_zo(mat4s proj) + CGLM_INLINE float glms_persp_aspect_lh_zo(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes_lh_zo(mat4s proj, float fovy) + */ + +#ifndef cglms_persp_lh_zo_h +#define cglms_persp_lh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum_lh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_frustum_lh_zo(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_lh_zo(float fovy, float aspect, float nearZ, float farZ) { + mat4s dest; + glm_perspective_lh_zo(fovy, aspect, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glms_persp_move_far_lh_zo(mat4s proj, float deltaFar) { + glm_persp_move_far_lh_zo(proj.raw, deltaFar); +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default_lh_zo(float aspect) { + mat4s dest; + glm_perspective_default_lh_zo(aspect, dest.raw); + return dest; +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +void +glms_perspective_resize_lh_zo(mat4s proj, float aspect) { + glm_perspective_resize_lh_zo(aspect, proj.raw); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_lh_zo(mat4s proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_lh_zo(proj.raw, nearZ, farZ, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv_lh_zo(mat4s proj, float dest[6]) { + glm_persp_decompv_lh_zo(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_x_lh_zo(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_lh_zo(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * y stands for y axis (top / botom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glms_persp_decomp_y_lh_zo(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_lh_zo(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z_lh_zo(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_lh_zo(proj.raw, nearZ, farZ); +} + +/*! + * @brief decomposes far value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far_lh_zo(mat4s proj, float * __restrict farZ) { + glm_persp_decomp_far_lh_zo(proj.raw, farZ); +} + +/*! + * @brief decomposes near value of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near_lh_zo(mat4s proj, float * __restrict nearZ) { + glm_persp_decomp_near_lh_zo(proj.raw, nearZ); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_fovy_lh_zo(mat4s proj) { + return glm_persp_fovy_lh_zo(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect_lh_zo(mat4s proj) { + return glm_persp_aspect_lh_zo(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @returns sizes as vector, sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +vec4s +glms_persp_sizes_lh_zo(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes_lh_zo(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_persp_lh_zo_h */ diff --git a/include/cglm/struct/clipspace/persp_rh_no.h b/include/cglm/struct/clipspace/persp_rh_no.h new file mode 100644 index 0000000..fbd6e6c --- /dev/null +++ b/include/cglm/struct/clipspace/persp_rh_no.h @@ -0,0 +1,297 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_perspective_rh_no(float fovy, + float aspect, + float nearZ, + float farZ) + CGLM_INLINE void glms_persp_move_far_rh_no(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default_rh_no(float aspect) + CGLM_INLINE void glms_perspective_resize_rh_no(mat4s proj, float aspect) + CGLM_INLINE void glms_persp_decomp_rh_no(mat4s proj, + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv_rh_no(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x_rh_no(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y_rh_no(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z_rh_no(mat4s proj, float *nearv, float *farv) + CGLM_INLINE void glms_persp_decomp_far_rh_no(mat4s proj, float *farZ) + CGLM_INLINE void glms_persp_decomp_near_rh_no(mat4s proj, float *nearZ) + CGLM_INLINE float glms_persp_fovy_rh_no(mat4s proj) + CGLM_INLINE float glms_persp_aspect_rh_no(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes_rh_no(mat4s proj, float fovy) + */ + +#ifndef cglms_persp_rh_no_h +#define cglms_persp_rh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum_rh_no(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_frustum_rh_no(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_rh_no(float fovy, float aspect, float nearZ, float farZ) { + mat4s dest; + glm_perspective_rh_no(fovy, aspect, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glms_persp_move_far_rh_no(mat4s proj, float deltaFar) { + glm_persp_move_far_rh_no(proj.raw, deltaFar); +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default_rh_no(float aspect) { + mat4s dest; + glm_perspective_default_rh_no(aspect, dest.raw); + return dest; +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +void +glms_perspective_resize_rh_no(mat4s proj, float aspect) { + glm_perspective_resize_rh_no(aspect, proj.raw); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_rh_no(mat4s proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_rh_no(proj.raw, nearZ, farZ, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv_rh_no(mat4s proj, float dest[6]) { + glm_persp_decompv_rh_no(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_x_rh_no(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_rh_no(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * y stands for y axis (top / botom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glms_persp_decomp_y_rh_no(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_rh_no(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z_rh_no(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_rh_no(proj.raw, nearZ, farZ); +} + +/*! + * @brief decomposes far value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far_rh_no(mat4s proj, float * __restrict farZ) { + glm_persp_decomp_far_rh_no(proj.raw, farZ); +} + +/*! + * @brief decomposes near value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near_rh_no(mat4s proj, float * __restrict nearZ) { + glm_persp_decomp_near_rh_no(proj.raw, nearZ); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_fovy_rh_no(mat4s proj) { + return glm_persp_fovy_rh_no(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect_rh_no(mat4s proj) { + return glm_persp_aspect_rh_no(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @returns sizes as vector, sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +vec4s +glms_persp_sizes_rh_no(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes_rh_no(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_persp_rh_no_h */ diff --git a/include/cglm/struct/clipspace/persp_rh_zo.h b/include/cglm/struct/clipspace/persp_rh_zo.h new file mode 100644 index 0000000..596ffee --- /dev/null +++ b/include/cglm/struct/clipspace/persp_rh_zo.h @@ -0,0 +1,297 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) + CGLM_INLINE mat4s glms_perspective_rh_zo(float fovy, + float aspect, + float nearZ, + float farZ) + CGLM_INLINE void glms_persp_move_far_rh_zo(mat4s proj, float deltaFar) + CGLM_INLINE mat4s glms_perspective_default_rh_zo(float aspect) + CGLM_INLINE void glms_perspective_resize_rh_zo(mat4s proj, float aspect) + CGLM_INLINE void glms_persp_decomp_rh_zo(mat4s proj, + float *nearv, float *farv, + float *top, float *bottom, + float *left, float *right) + CGLM_INLINE void glms_persp_decompv_rh_zo(mat4s proj, float dest[6]) + CGLM_INLINE void glms_persp_decomp_x_rh_zo(mat4s proj, float *left, float *right) + CGLM_INLINE void glms_persp_decomp_y_rh_zo(mat4s proj, float *top, float *bottom) + CGLM_INLINE void glms_persp_decomp_z_rh_zo(mat4s proj, float *nearv, float *farv) + CGLM_INLINE void glms_persp_decomp_far_rh_zo(mat4s proj, float *farZ) + CGLM_INLINE void glms_persp_decomp_near_rh_zo(mat4s proj, float *nearZ) + CGLM_INLINE float glms_persp_fovy_rh_zo(mat4s proj) + CGLM_INLINE float glms_persp_aspect_rh_zo(mat4s proj) + CGLM_INLINE vec4s glms_persp_sizes_rh_zo(mat4s proj, float fovy) + */ + +#ifndef cglms_persp_rh_zo_h +#define cglms_persp_rh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up perspective peprojection matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] left viewport.left + * @param[in] right viewport.right + * @param[in] bottom viewport.bottom + * @param[in] top viewport.top + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping plane + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_frustum_rh_zo(float left, float right, + float bottom, float top, + float nearZ, float farZ) { + mat4s dest; + glm_frustum_rh_zo(left, right, bottom, top, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief set up perspective projection matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] fovy field of view angle + * @param[in] aspect aspect ratio ( width / height ) + * @param[in] nearZ near clipping plane + * @param[in] farZ far clipping planes + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_rh_zo(float fovy, float aspect, float nearZ, float farZ) { + mat4s dest; + glm_perspective_rh_zo(fovy, aspect, nearZ, farZ, dest.raw); + return dest; +} + +/*! + * @brief extend perspective projection matrix's far distance + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * this function does not guarantee far >= near, be aware of that! + * + * @param[in, out] proj projection matrix to extend + * @param[in] deltaFar distance from existing far (negative to shink) + */ +CGLM_INLINE +void +glms_persp_move_far_rh_zo(mat4s proj, float deltaFar) { + glm_persp_move_far_rh_zo(proj.raw, deltaFar); +} + +/*! + * @brief set up perspective projection matrix with default near/far + * and angle values with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] aspect aspect ratio ( width / height ) + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_perspective_default_rh_zo(float aspect) { + mat4s dest; + glm_perspective_default_rh_zo(aspect, dest.raw); + return dest; +} + +/*! + * @brief resize perspective matrix by aspect ratio ( width / height ) + * this makes very easy to resize proj matrix when window /viewport + * reized with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in, out] proj perspective projection matrix + * @param[in] aspect aspect ratio ( width / height ) + */ +CGLM_INLINE +void +glms_perspective_resize_rh_zo(mat4s proj, float aspect) { + glm_perspective_resize_rh_zo(aspect, proj.raw); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + * @param[out] top top + * @param[out] bottom bottom + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_rh_zo(mat4s proj, + float * __restrict nearZ, float * __restrict farZ, + float * __restrict top, float * __restrict bottom, + float * __restrict left, float * __restrict right) { + glm_persp_decomp_rh_zo(proj.raw, nearZ, farZ, top, bottom, left, right); +} + +/*! + * @brief decomposes frustum values of perspective projection. + * this makes easy to get all values at once + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] dest array + */ +CGLM_INLINE +void +glms_persp_decompv_rh_zo(mat4s proj, float dest[6]) { + glm_persp_decompv_rh_zo(proj.raw, dest); +} + +/*! + * @brief decomposes left and right values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * x stands for x axis (left / right axis) + * + * @param[in] proj perspective projection matrix + * @param[out] left left + * @param[out] right right + */ +CGLM_INLINE +void +glms_persp_decomp_x_rh_zo(mat4s proj, + float * __restrict left, + float * __restrict right) { + glm_persp_decomp_x_rh_zo(proj.raw, left, right); +} + +/*! + * @brief decomposes top and bottom values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * y stands for y axis (top / botom axis) + * + * @param[in] proj perspective projection matrix + * @param[out] top top + * @param[out] bottom bottom + */ +CGLM_INLINE +void +glms_persp_decomp_y_rh_zo(mat4s proj, + float * __restrict top, + float * __restrict bottom) { + glm_persp_decomp_y_rh_zo(proj.raw, top, bottom); +} + +/*! + * @brief decomposes near and far values of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * z stands for z axis (near / far axis) + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_z_rh_zo(mat4s proj, + float * __restrict nearZ, + float * __restrict farZ) { + glm_persp_decomp_z_rh_zo(proj.raw, nearZ, farZ); +} + +/*! + * @brief decomposes far value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] farZ far + */ +CGLM_INLINE +void +glms_persp_decomp_far_rh_zo(mat4s proj, float * __restrict farZ) { + glm_persp_decomp_far_rh_zo(proj.raw, farZ); +} + +/*! + * @brief decomposes near value of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[out] nearZ near + */ +CGLM_INLINE +void +glms_persp_decomp_near_rh_zo(mat4s proj, float * __restrict nearZ) { + glm_persp_decomp_near_rh_zo(proj.raw, nearZ); +} + +/*! + * @brief returns field of view angle along the Y-axis (in radians) + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * if you need to degrees, use glm_deg to convert it or use this: + * fovy_deg = glm_deg(glm_persp_fovy(projMatrix)) + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_fovy_rh_zo(mat4s proj) { + return glm_persp_fovy_rh_zo(proj.raw); +} + +/*! + * @brief returns aspect ratio of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + */ +CGLM_INLINE +float +glms_persp_aspect_rh_zo(mat4s proj) { + return glm_persp_aspect_rh_zo(proj.raw); +} + +/*! + * @brief returns sizes of near and far planes of perspective projection + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * @param[in] proj perspective projection matrix + * @param[in] fovy fovy (see brief) + * @returns sizes as vector, sizes order: [Wnear, Hnear, Wfar, Hfar] + */ +CGLM_INLINE +vec4s +glms_persp_sizes_rh_zo(mat4s proj, float fovy) { + vec4s dest; + glm_persp_sizes_rh_zo(proj.raw, fovy, dest.raw); + return dest; +} + +#endif /* cglms_persp_rh_zo_h */ diff --git a/include/cglm/struct/clipspace/view_lh_no.h b/include/cglm/struct/clipspace/view_lh_no.h new file mode 100644 index 0000000..bb5eed6 --- /dev/null +++ b/include/cglm/struct/clipspace/view_lh_no.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_lookat_lh_no(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look_lh_no(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup_lh_no(vec3s eye, vec3s dir) + */ + +#ifndef cglms_view_lh_no_h +#define cglms_view_lh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_lookat_lh_no(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat_lh_no(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_lh_no(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look_lh_no(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [-1, 1]. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_anyup_lh_no(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup_lh_no(eye.raw, dir.raw, dest.raw); + return dest; +} + +#endif /* cglms_view_lh_no_h */ diff --git a/include/cglm/struct/clipspace/view_lh_zo.h b/include/cglm/struct/clipspace/view_lh_zo.h new file mode 100644 index 0000000..322fdf6 --- /dev/null +++ b/include/cglm/struct/clipspace/view_lh_zo.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_lookat_lh_zo(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look_lh_zo(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup_lh_zo(vec3s eye, vec3s dir) + */ + +#ifndef cglms_view_lh_zo_h +#define cglms_view_lh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_lookat_lh_zo(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat_lh_zo(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_lh_zo(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look_lh_zo(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a left-hand coordinate system and a + * clip-space of [0, 1]. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_anyup_lh_zo(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup_lh_zo(eye.raw, dir.raw, dest.raw); + return dest; +} + +#endif /* cglms_view_lh_zo_h */ diff --git a/include/cglm/struct/clipspace/view_rh_no.h b/include/cglm/struct/clipspace/view_rh_no.h new file mode 100644 index 0000000..df82b1d --- /dev/null +++ b/include/cglm/struct/clipspace/view_rh_no.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_lookat_rh_no(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look_rh_no(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup_rh_no(vec3s eye, vec3s dir) + */ + +#ifndef cglms_view_rh_no_h +#define cglms_view_rh_no_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_lookat_rh_no(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat_rh_no(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_rh_no(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look_rh_no(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [-1, 1]. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_anyup_rh_no(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup_rh_no(eye.raw, dir.raw, dest.raw); + return dest; +} + +#endif /* cglms_view_rh_no_h */ diff --git a/include/cglm/struct/clipspace/view_rh_zo.h b/include/cglm/struct/clipspace/view_rh_zo.h new file mode 100644 index 0000000..5097bc8 --- /dev/null +++ b/include/cglm/struct/clipspace/view_rh_zo.h @@ -0,0 +1,88 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), htt../opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +/* + Functions: + CGLM_INLINE mat4s glms_lookat_rh_zo(vec3s eye, vec3s center, vec3s up) + CGLM_INLINE mat4s glms_look_rh_zo(vec3s eye, vec3s dir, vec3s up) + CGLM_INLINE mat4s glms_look_anyup_rh_zo(vec3s eye, vec3s dir) + */ + +#ifndef cglms_view_rh_zo_h +#define cglms_view_rh_zo_h + +#include "../../common.h" +#include "../../types-struct.h" +#include "../../plane.h" +#include "../../cam.h" + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] center center vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_lookat_rh_zo(vec3s eye, vec3s center, vec3s up) { + mat4s dest; + glm_lookat_rh_zo(eye.raw, center.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * convenient wrapper for lookat: if you only have direction not target self + * then this might be useful. Because you need to get target from direction. + * + * NOTE: The UP vector must not be parallel to the line of sight from + * the eye point to the reference point + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @param[in] up up vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_rh_zo(vec3s eye, vec3s dir, vec3s up) { + mat4s dest; + glm_look_rh_zo(eye.raw, dir.raw, up.raw, dest.raw); + return dest; +} + +/*! + * @brief set up view matrix + * with a right-hand coordinate system and a + * clip-space of [0, 1]. + * + * convenient wrapper for look: if you only have direction and if you don't + * care what UP vector is then this might be useful to create view matrix + * + * @param[in] eye eye vector + * @param[in] dir direction vector + * @returns result matrix + */ +CGLM_INLINE +mat4s +glms_look_anyup_rh_zo(vec3s eye, vec3s dir) { + mat4s dest; + glm_look_anyup_rh_zo(eye.raw, dir.raw, dest.raw); + return dest; +} + +#endif /* cglms_view_rh_zo_h */