Compare commits

...

58 Commits

Author SHA1 Message Date
Recep Aslantas
7e5d1f435f Merge pull request #244 from geckor14/master
Remove unused variable
2022-03-18 12:39:29 +03:00
geckor14
851a58cedb Remove unused variable
The most recent version of Apple Clang (13.1.6) on macOS complains r3 is an unused variable. With -Werror enabled, this breaks the build.
2022-03-18 18:42:19 +11:00
Recep Aslantas
6fa1cefcc2 Merge pull request #243 from Sand3r-/patch-1
Fix a bug in glm_lookat_lh
2022-03-09 09:38:26 +03:00
Michał Gallus
7e211e1f49 Fix bug in view_lh.h #2
Reverse order of parameters in the second crossproduct
2022-03-08 01:42:43 +01:00
Michał Gallus
7d47b7f1fd Fix a bug in glm_lookat_lh
Fix the order of arguments passed to glm_vec3_crossn to avoid the negation of X axis.
2022-03-08 01:29:35 +01:00
Recep Aslantas
2a4748d452 fix glm_pickmatrix()'s param type 2022-01-31 02:56:39 +03:00
Recep Aslantas
f20bf0aaaf Merge pull request #236 from recp/ivec
add missing ivec types
2022-01-07 00:23:32 +03:00
Recep Aslantas
3a141b7cc8 extend unions for struct api 2022-01-06 18:12:46 +03:00
Recep Aslantas
5cd1a4ab44 add missing ivec types 2022-01-06 18:01:35 +03:00
Recep Aslantas
897f2afd88 Merge pull request #234 from madebr/sse3_header
Header containing sse3 intrinsics is pmmintrin.h
2021-12-31 17:51:30 +03:00
Anonymous Maarten
68e3a072e8 Header containing sse3 intrinsics is pmmintrin.h 2021-12-29 08:48:55 +01:00
Recep Aslantas
282ea84dc0 Merge pull request #231 from omar-polo/master
set PACKAGE_VERSION so it gets substituted in cglm.pc.in by cmake
2021-11-22 11:20:20 +03:00
Omar Polo
2d5506d15d set PACKAGE_VERSION so it gets substituted in cglm.pc.in by cmake
otherwise it ends up being an empty string and the installed pc has a
bogus line:

	Version:
2021-11-21 21:04:59 +01:00
Recep Aslantas
87f561fb06 Merge pull request #229 from mxi/vec2-ext-complex
Add complex routines to `vec2-ext`
2021-11-10 10:09:09 +03:00
Maxim Kasyanenko
522b18bda9 Add tests 2021-11-08 17:53:39 -08:00
Maxim Kasyanenko
b7178749ee Forgot to add the dynamic implementation file itself 2021-11-08 17:53:27 -08:00
Maxim Kasyanenko
98c708281f Syntax errors 2021-11-08 17:52:47 -08:00
Maxim Kasyanenko
896ba0a0f9 Add dynamic/struct versions of routines 2021-11-08 17:52:31 -08:00
Maxim Kasyanenko
4603816330 Forgot return type 2021-11-08 17:09:28 -08:00
Maxim Kasyanenko
9f5cc3a745 Implement a few complex routines 2021-11-08 16:28:55 -08:00
Recep Aslantas
bde653b607 Update CMakeLists.txt 2021-10-28 19:10:19 +03:00
Recep Aslantas
ede72ca412 Merge pull request #225 from podsvirov/fix-win32-shared
win: fix shared library name and destination
2021-10-17 18:09:18 +03:00
Konstantin Podsvirov
8e784e762f win: fix shared library name and destination 2021-10-10 12:02:44 +03:00
Recep Aslantas
82d1050c63 update GLM_FLT_EPSILON to use 1e-5 instead of 1e-6 2021-10-06 21:08:55 +03:00
Recep Aslantas
0631598d08 now working on v0.8.5 2021-08-18 05:03:59 +03:00
Recep Aslantas
34e5704fe8 bump version to v0.8.4 2021-08-18 04:47:11 +03:00
Recep Aslantas
672523e5af Merge pull request #219 from recp/project_zo
extend glm_project() to support ZERO_TO_ONE
2021-08-16 16:55:19 +03:00
Recep Aslantas
8427d02a9b pick matrix helper (aka gluPickMatrix) 2021-08-16 16:53:46 +03:00
Recep Aslantas
a2bd00df32 fix including headers, and suppress warnings 2021-08-16 15:51:52 +03:00
Recep Aslantas
4c8f7f310c Update project_zo.h 2021-08-16 14:27:20 +03:00
Recep Aslantas
9096fa6bab fix include paths 2021-08-16 14:27:12 +03:00
Recep Aslantas
29c3837672 implement project zo 2021-08-16 14:16:43 +03:00
Recep Aslantas
4530e0381b build: add missing files 2021-08-16 01:10:29 +03:00
Recep Aslantas
6cf1fb8992 Update .gitignore 2021-08-16 01:10:19 +03:00
Recep Aslantas
9ed4e41afd call version for clipspace-project 2021-08-16 01:08:11 +03:00
Recep Aslantas
28d24da6df build: add missing files 2021-08-16 00:55:19 +03:00
Recep Aslantas
ef22e2063f win: fix build error and comment style 2021-08-16 00:54:37 +03:00
Recep Aslantas
5a48aad1b0 Merge pull request #218 from Nairou/master
Add CGLM_FORCE_DEPTH_ZERO_TO_ONE support to glm_unprojecti
2021-08-16 00:45:22 +03:00
Caleb Gingles
07aee82125 Add CGLM_FORCE_DEPTH_ZERO_TO_ONE support to glm_unprojecti 2021-08-15 17:34:26 -04:00
Recep Aslantas
abbeb274c5 Merge pull request #214 from bubba2k/patch-1
Note that radians is expected in glm_perspective()
2021-08-09 10:54:02 +03:00
bubba2k
814adf11de Note that radians is expected in glm_perspective()
The `fovy` parameter is expected in radians, which isn't mentioned anywhere in the docs. Causes unnecessary confusion. Might as well point it out.
2021-08-09 03:02:47 +02:00
Recep Aslantas
d0d1e46533 Merge pull request #210 from legends2k/quat_rot_vecs 2021-06-15 19:59:45 +03:00
Sundaram Ramaswamy
03b4594d9e quat_from_vecs: incorporate PR comments
* C89-style comments
* Move all variable declarations to function start
* Remove constant variables
* Remove newline for ‘else’
2021-06-15 19:11:41 +05:30
Sundaram Ramaswamy
01e2b74a29 Update documentation for qaut_from_vecs 2021-06-10 23:52:09 +05:30
Sundaram Ramaswamy
ee5050f43c Tests for quaternion from two vec3 2021-06-10 23:15:10 +05:30
Sundaram Ramaswamy
b5802b99b2 Compute quaternion rotating a vector into another
Both `vec3` inputs should be of unit length; returns a unit quaternion.
2021-06-10 23:10:54 +05:30
Recep Aslantas
8b958e9600 Merge pull request #209 from legends2k/fix_vec3_cross
Fix cross product when an operand is also dest
2021-06-10 16:49:17 +03:00
Sundaram Ramaswamy
aa071b2a6b Fix cross product when operand is also dest 2021-06-10 17:20:50 +05:30
Recep Aslantas
479e7d4240 Merge pull request #207 from legends2k/fix_vec3_ortho
Fix vec3_ortho
2021-06-10 10:15:12 +03:00
Recep Aslantas
38c6188e12 Update vec3.h 2021-06-10 10:13:51 +03:00
Sundaram Ramaswamy
c330b47ded Remove debug printf statements 2021-06-10 10:27:28 +05:30
Sundaram Ramaswamy
2e8162b133 Fix vec3_ortho 2021-06-09 23:18:32 +05:30
Recep Aslantas
afdcae08dd Merge pull request #205 from legends2k/master
Include affine.h in quat.h; remove needless decls
2021-06-07 11:45:54 +03:00
Sundaram Ramaswamy
32d1c96dc0 Include affine.h in quat.h; remove needless decls
* affine.h is needed for glm_translate_make
* Remove function declarations
  - glm_mat4_mulv since mat4.h is already included
  - glm_mul_rot as affine-mat.h is already include
  - glm_translate as affine.h is included with this change
2021-06-07 11:35:56 +05:30
Recep Aslantas
4d2ba464a0 Update README.md 2021-05-30 18:11:17 +03:00
Recep Aslantas
398e47070b Update README.md 2021-05-30 18:09:17 +03:00
Recep Aslantas
619ac4ce9a Update README.md 2021-05-30 18:03:33 +03:00
Recep Aslantas
e83940f3b1 Create cglm.png 2021-05-30 17:48:29 +03:00
82 changed files with 916 additions and 113 deletions

1
.gitignore vendored
View File

@@ -78,3 +78,4 @@ confdefs.h
*.xcuserdatad *.xcuserdatad
.idea .idea
cmake-build-debug cmake-build-debug
*.o.tmp

View File

@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8.2) cmake_minimum_required(VERSION 3.8.2)
project(cglm VERSION 0.8.3 LANGUAGES C) project(cglm VERSION 0.8.5 LANGUAGES C)
set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED YES) set(CMAKE_C_STANDARD_REQUIRED YES)
@@ -47,7 +47,10 @@ include(GNUInstallDirs)
set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)
if(NOT CPack_CMake_INCLUDED)
include(CPack)
endif()
# Target Start # Target Start
add_library(${PROJECT_NAME} add_library(${PROJECT_NAME}
@@ -97,6 +100,12 @@ set_target_properties(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION} VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}) SOVERSION ${PROJECT_VERSION_MAJOR})
if(WIN32)
# Because SOVERSION has no effect to file naming on Windows
set_target_properties(${PROJECT_NAME} PROPERTIES
RUNTIME_OUTPUT_NAME ${PROJECT_NAME}-${PROJECT_VERSION_MAJOR})
endif()
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}
PUBLIC PUBLIC
$<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include>
@@ -122,7 +131,7 @@ install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME} EXPORT ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}) RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} install(DIRECTORY include/${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
PATTERN ".*" EXCLUDE) PATTERN ".*" EXCLUDE)
@@ -143,6 +152,7 @@ set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}) set(exec_prefix ${CMAKE_INSTALL_PREFIX})
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}") set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
set(PACKAGE_VERSION "${PROJECT_VERSION}")
configure_file(${CMAKE_CURRENT_LIST_DIR}/cglm.pc.in ${CMAKE_BINARY_DIR}/cglm.pc @ONLY) configure_file(${CMAKE_CURRENT_LIST_DIR}/cglm.pc.in ${CMAKE_BINARY_DIR}/cglm.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/cglm.pc install(FILES ${CMAKE_BINARY_DIR}/cglm.pc

View File

@@ -78,3 +78,7 @@ https://stackoverflow.com/a/57793352/2676533
16. ARM NEON Div 16. ARM NEON Div
http://github.com/microsoft/DirectXMath http://github.com/microsoft/DirectXMath
17. Pick Matrix
glu project -> project.c

View File

@@ -84,7 +84,9 @@ cglm_clipspace_HEADERS = include/cglm/clipspace/persp.h \
include/cglm/clipspace/view_lh_zo.h \ include/cglm/clipspace/view_lh_zo.h \
include/cglm/clipspace/view_rh_zo.h \ include/cglm/clipspace/view_rh_zo.h \
include/cglm/clipspace/view_lh_no.h \ include/cglm/clipspace/view_lh_no.h \
include/cglm/clipspace/view_rh_no.h include/cglm/clipspace/view_rh_no.h \
include/cglm/clipspace/project_zo.h \
include/cglm/clipspace/project_no.h
cglm_calldir=$(includedir)/cglm/call cglm_calldir=$(includedir)/cglm/call
cglm_call_HEADERS = include/cglm/call/mat4.h \ cglm_call_HEADERS = include/cglm/call/mat4.h \
@@ -109,6 +111,22 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \
include/cglm/call/ray.h \ include/cglm/call/ray.h \
include/cglm/call/affine2d.h include/cglm/call/affine2d.h
cglm_call_clipspacedir=$(includedir)/cglm/call/clipspace
cglm_call_clipspace_HEADERS = include/cglm/call/clipspace/persp_lh_zo.h \
include/cglm/call/clipspace/persp_rh_zo.h \
include/cglm/call/clipspace/persp_lh_no.h \
include/cglm/call/clipspace/persp_rh_no.h \
include/cglm/call/clipspace/ortho_lh_zo.h \
include/cglm/call/clipspace/ortho_rh_zo.h \
include/cglm/call/clipspace/ortho_lh_no.h \
include/cglm/call/clipspace/ortho_rh_no.h \
include/cglm/call/clipspace/view_lh_zo.h \
include/cglm/call/clipspace/view_rh_zo.h \
include/cglm/call/clipspace/view_lh_no.h \
include/cglm/call/clipspace/view_rh_no.h \
include/cglm/call/clipspace/project_no.h \
include/cglm/call/clipspace/project_zo.h
cglm_simddir=$(includedir)/cglm/simd cglm_simddir=$(includedir)/cglm/simd
cglm_simd_HEADERS = include/cglm/simd/intrin.h \ cglm_simd_HEADERS = include/cglm/simd/intrin.h \
include/cglm/simd/x86.h \ include/cglm/simd/x86.h \
@@ -202,8 +220,10 @@ libcglm_la_SOURCES=\
src/clipspace/view_lh_no.c \ src/clipspace/view_lh_no.c \
src/clipspace/view_lh_zo.c \ src/clipspace/view_lh_zo.c \
src/clipspace/view_rh_no.c \ src/clipspace/view_rh_no.c \
src/clipspace/view_rh_zo.c src/clipspace/view_rh_zo.c \
src/clipspace/project_no.c \
src/clipspace/project_zo.c
test_tests_SOURCES=\ test_tests_SOURCES=\
test/runner.c \ test/runner.c \
test/src/test_common.c \ test/src/test_common.c \

View File

@@ -1,19 +1,59 @@
# 🎥 OpenGL Mathematics (glm) for `C` # 🎥 OpenGL Mathematics (glm) for `C`
[![Build Status](https://travis-ci.com/recp/cglm.svg?branch=master)](https://travis-ci.com/recp/cglm)
[![Build status](https://ci.appveyor.com/api/projects/status/av7l3gc0yhfex8y4/branch/master?svg=true)](https://ci.appveyor.com/project/recp/cglm/branch/master)
[![Documentation Status](https://readthedocs.org/projects/cglm/badge/?version=latest)](http://cglm.readthedocs.io/en/latest/?badge=latest)
[![Coverage Status](https://coveralls.io/repos/github/recp/cglm/badge.svg?branch=master)](https://coveralls.io/github/recp/cglm?branch=master)
[![codecov](https://codecov.io/gh/recp/cglm/branch/master/graph/badge.svg)](https://codecov.io/gh/recp/cglm)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/6a62b37d5f214f178ebef269dc4a6bf1)](https://www.codacy.com/app/recp/cglm?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=recp/cglm&amp;utm_campaign=Badge_Grade)
[![Backers on Open Collective](https://opencollective.com/cglm/backers/badge.svg)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/cglm/sponsors/badge.svg)](#sponsors)
#### Documentation <p align="center">
<img alt="" src="cglm.png" width="550" />
</p>
<br>
<p align="center">
<a href="https://travis-ci.com/recp/cglm">
<img src="https://travis-ci.com/recp/cglm.svg?branch=master"
alt="Build Status">
</a>
<a href="https://ci.appveyor.com/project/recp/cglm/branch/master">
<img src="https://ci.appveyor.com/api/projects/status/av7l3gc0yhfex8y4/branch/master?svg=true"
alt="Windows Build Status">
</a>
<a href="http://cglm.readthedocs.io/en/latest/?badge=latest">
<img src="https://readthedocs.org/projects/cglm/badge/?version=latest"
alt="Documentation Status">
</a>
<a href="https://www.codacy.com/app/recp/cglm?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=recp/cglm&amp;utm_campaign=Badge_Grade">
<img src="https://api.codacy.com/project/badge/Grade/6a62b37d5f214f178ebef269dc4a6bf1"
alt="Codacy Badge"/>
</a>
<a href="https://coveralls.io/github/recp/cglm?branch=master">
<img src="https://coveralls.io/repos/github/recp/cglm/badge.svg?branch=master"
alt="Coverage Status"/>
</a>
<a href="https://codecov.io/gh/recp/cglm">
<img src="https://codecov.io/gh/recp/cglm/branch/master/graph/badge.svg"
alt="Coverage Status"/>
</a>
<br /><br />
<a href="#sponsors">
<img src="https://opencollective.com/cglm/sponsors/badge.svg"
alt="Sponsors on Open Collective"/>
</a>
<a href="#backers">
<img src="https://opencollective.com/cglm/backers/badge.svg"
alt="Backers on Open Collective"/>
</a>
</p>
<br>
<p align="center">
Highly optimized 2D|3D math library, also known as <b>OpenGL Mathematics (glm) for `C`</b>. <b>cglm</b> provides lot of utils to help math operations to be fast and quick to write. It is community friendly, feel free to bring any issues, bugs you faced.
</p>
---
#### 📚 Documentation
Almost all functions (inline versions) and parameters are documented inside the corresponding headers. <br /> Almost all functions (inline versions) and parameters are documented inside the corresponding headers. <br />
Complete documentation: http://cglm.readthedocs.io Complete documentation: http://cglm.readthedocs.io
#### Note for previous versions: #### 📌 Note for previous versions:
- _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec3_copy` - _dup (duplicate) is changed to _copy. For instance `glm_vec_dup -> glm_vec3_copy`
- OpenGL related functions are dropped to make this lib platform/third-party independent - OpenGL related functions are dropped to make this lib platform/third-party independent
@@ -28,30 +68,27 @@ you have the latest version
- **[major change]** by starting v0.7.3, inline print functions are disabled in release/production mode to eliminate print costs (see options in documentation). Print output also improved. You can disable colors if you need (see documentation) - **[major change]** by starting v0.7.3, inline print functions are disabled in release/production mode to eliminate print costs (see options in documentation). Print output also improved. You can disable colors if you need (see documentation)
- **[major change]** by starting v0.8.3, **cglm** supports alternative clipspace configuations e.g. Left Handed, Zero-to-One (_zo)... `CGLM_FORCE_DEPTH_ZERO_TO_ONE` and `CGLM_FORCE_LEFT_HANDED` is provided to control clipspace. You should be able to use **cglm** with Vulkan, DirectX and Metal now... see https://cglm.readthedocs.io/en/latest/opt.html#clipspace-option-s - **[major change]** by starting v0.8.3, **cglm** supports alternative clipspace configuations e.g. Left Handed, Zero-to-One (_zo)... `CGLM_FORCE_DEPTH_ZERO_TO_ONE` and `CGLM_FORCE_LEFT_HANDED` is provided to control clipspace. You should be able to use **cglm** with Vulkan, DirectX and Metal now... see https://cglm.readthedocs.io/en/latest/opt.html#clipspace-option-s
#### Note for C++ developers: #### 📌 Note for C++ developers:
If you are not aware of the original GLM library yet, you may also want to look at: If you are not aware of the original GLM library yet, you may also want to look at:
https://github.com/g-truc/glm https://github.com/g-truc/glm
#### Note for new comers (Important): #### 📌 Note for new comers (Important):
- `vec4` and `mat4` variables must be aligned. (There will be unaligned versions later) - `vec4` and `mat4` variables must be aligned. (There will be unaligned versions later)
- **in** and **[in, out]** parameters must be initialized (please). But **[out]** parameters not, initializing out param is also redundant - **in** and **[in, out]** parameters must be initialized (please). But **[out]** parameters not, initializing out param is also redundant
- All functions are inline if you don't want to use pre-compiled versions with glmc_ prefix, you can ignore build process. Just include headers. - All functions are inline if you don't want to use pre-compiled versions with glmc_ prefix, you can ignore build process. Just include headers.
- if your debugger takes you to cglm headers then make sure you are not trying to copy vec4 to vec3 or alig issues... - if your debugger takes you to cglm headers then make sure you are not trying to copy vec4 to vec3 or alig issues...
- Welcome! - Welcome!
#### Note for experienced developers: #### 📌 Note for experienced developers:
- Since I'm testing this library in my projects, sometimes bugs occurs; finding that bug[s] and making improvements would be more easy with multiple developer/contributor and their projects or knowledge. Consider to make some tests if you suspect something is wrong and any feedbacks, contributions and bug reports are always welcome. - Since I'm testing this library in my projects, sometimes bugs occurs; finding that bug[s] and making improvements would be more easy with multiple developer/contributor and their projects or knowledge. Consider to make some tests if you suspect something is wrong and any feedbacks, contributions and bug reports are always welcome.
#### Allocations? #### 📌 Allocations?
`cglm` doesn't alloc any memory on heap. So it doesn't provide any allocator. You should alloc memory for **out** parameters too if you pass pointer of memory location. Don't forget that **vec4** (also quat/**versor**) and **mat4** must be aligned (16-bytes), because *cglm* uses SIMD instructions to optimize most operations if available. `cglm` doesn't alloc any memory on heap. So it doesn't provide any allocator. You should alloc memory for **out** parameters too if you pass pointer of memory location. Don't forget that **vec4** (also quat/**versor**) and **mat4** must be aligned (16-bytes), because *cglm* uses SIMD instructions to optimize most operations if available.
#### Returning vector or matrix... ? #### 📌 Returning vector or matrix... ?
**cglm** supports both *ARRAY API* and *STRUCT API*, so you can return structs if you utilize struct api (`glms_`). **cglm** supports both *ARRAY API* and *STRUCT API*, so you can return structs if you utilize struct api (`glms_`).
#### Other APIs like Vulkan, Metal, Dx?
Currently *cglm* uses default clip space configuration (-1, 1) for camera functions (perspective, extract corners...), in the future other clip space configurations will be supported
<hr/> <hr/>
<table> <table>
@@ -69,7 +106,7 @@ Currently *cglm* uses default clip space configuration (-1, 1) for camera functi
</tbody> </tbody>
</table> </table>
## Features ## 🚀 Features
- **scalar** and **simd** (sse, avx, neon...) optimizations - **scalar** and **simd** (sse, avx, neon...) optimizations
- option to use different clipspaces e.g. Left Handed, Zero-to-One... (currrently right handed negative-one is default) - option to use different clipspaces e.g. Left Handed, Zero-to-One... (currrently right handed negative-one is default)
- array api and struct api, you can use arrays or structs. - array api and struct api, you can use arrays or structs.
@@ -151,7 +188,7 @@ Struct functions generally take their parameters as *values* and *return* their
The types used are actually unions that allow access to the same data multiple ways. One of those ways involves anonymous structures, available since C11. MSVC also supports it for earlier C versions out of the box and GCC/Clang do if you enable `-fms-extensions`. To explicitly enable these anonymous structures, `#define CGLM_USE_ANONYMOUS_STRUCT` to `1`, to disable them, to `0`. For backward compatibility, you can also `#define CGLM_NO_ANONYMOUS_STRUCT` (value is irrelevant) to disable them. If you don't specify explicitly, cglm will do a best guess based on your compiler and the C version you're using. The types used are actually unions that allow access to the same data multiple ways. One of those ways involves anonymous structures, available since C11. MSVC also supports it for earlier C versions out of the box and GCC/Clang do if you enable `-fms-extensions`. To explicitly enable these anonymous structures, `#define CGLM_USE_ANONYMOUS_STRUCT` to `1`, to disable them, to `0`. For backward compatibility, you can also `#define CGLM_NO_ANONYMOUS_STRUCT` (value is irrelevant) to disable them. If you don't specify explicitly, cglm will do a best guess based on your compiler and the C version you're using.
## Build ## 🔨 Build
### CMake (All platforms) ### CMake (All platforms)
```bash ```bash
@@ -403,7 +440,7 @@ You can pass matrices the same way to other APIs e.g. Vulkan, DX...
- [x] Add version info - [x] Add version info
- [ ] Unaligned operations (e.g. `glm_umat4_mul`) - [ ] Unaligned operations (e.g. `glm_umat4_mul`)
- [x] Extra documentation - [x] Extra documentation
- [ ] ARM Neon Arch (In Progress) - [x] ARM Neon Arch
## Contributors ## Contributors

BIN
cglm.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 KiB

View File

@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
# Description # Description
s.name = "cglm" s.name = "cglm"
s.version = "0.8.2" s.version = "0.8.4"
s.summary = "📽 Highly Optimized Graphics Math (glm) for C" s.summary = "📽 Highly Optimized Graphics Math (glm) for C"
s.description = <<-DESC s.description = <<-DESC
cglm is math library for graphics programming for C. See the documentation or README for all features. cglm is math library for graphics programming for C. See the documentation or README for all features.

View File

@@ -7,7 +7,7 @@
#***************************************************************************** #*****************************************************************************
AC_PREREQ([2.69]) AC_PREREQ([2.69])
AC_INIT([cglm], [0.8.3], [info@recp.me]) AC_INIT([cglm], [0.8.5], [info@recp.me])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects serial-tests]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects serial-tests])
# Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am. # Don't use the default cflags (-O2 -g), we set ours manually in Makefile.am.

View File

@@ -140,7 +140,7 @@ Functions documentation
| set up perspective projection matrix | set up perspective projection matrix
Parameters: Parameters:
| *[in]* **fovy** field of view angle | *[in]* **fovy** field of view angle (in radians)
| *[in]* **aspect** aspect ratio ( width / height ) | *[in]* **aspect** aspect ratio ( width / height )
| *[in]* **nearVal** near clipping plane | *[in]* **nearVal** near clipping plane
| *[in]* **farVal** far clipping planes | *[in]* **farVal** far clipping planes

View File

@@ -62,9 +62,9 @@ author = u'Recep Aslantas'
# built documents. # built documents.
# #
# The short X.Y version. # The short X.Y version.
version = u'0.8.3' version = u'0.8.5'
# The full version, including alpha/beta/rc tags. # The full version, including alpha/beta/rc tags.
release = u'0.8.3' release = u'0.8.5'
# The language for content autogenerated by Sphinx. Refer to documentation # The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages. # for a list of supported languages.

View File

@@ -32,6 +32,7 @@ Functions:
#. :c:func:`glm_quat` #. :c:func:`glm_quat`
#. :c:func:`glm_quatv` #. :c:func:`glm_quatv`
#. :c:func:`glm_quat_copy` #. :c:func:`glm_quat_copy`
#. :c:func:`glm_quat_from_vecs`
#. :c:func:`glm_quat_norm` #. :c:func:`glm_quat_norm`
#. :c:func:`glm_quat_normalize` #. :c:func:`glm_quat_normalize`
#. :c:func:`glm_quat_normalize_to` #. :c:func:`glm_quat_normalize_to`
@@ -123,6 +124,20 @@ Functions documentation
| *[in]* **q** source quaternion | *[in]* **q** source quaternion
| *[out]* **dest** destination quaternion | *[out]* **dest** destination quaternion
.. c:function:: void glm_quat_from_vecs(vec3 a, vec3 b, versor dest)
| compute unit quaternion needed to rotate a into b
References:
* `Finding quaternion representing the rotation from one vector to another <https://stackoverflow.com/a/11741520/183120>`_
* `Quaternion from two vectors <http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final>`_
* `Angle between vectors <http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/minorlogic.htm>`_
Parameters:
| *[in]* **a** unit vector
| *[in]* **b** unit vector
| *[in]* **dest** unit quaternion
.. c:function:: float glm_quat_norm(versor q) .. c:function:: float glm_quat_norm(versor q)
| returns norm (magnitude) of quaternion | returns norm (magnitude) of quaternion

View File

@@ -474,6 +474,9 @@ Functions documentation
possible orthogonal/perpendicular vector possible orthogonal/perpendicular vector
References:
* `On picking an orthogonal vector (and combing coconuts) <http://lolengine.net/blog/2013/09/21/picking-orthogonal-vector-combing-coconuts>`_
Parameters: Parameters:
| *[in]* **v** vector | *[in]* **v** vector
| *[out]* **dest** orthogonal/perpendicular vector | *[out]* **dest** orthogonal/perpendicular vector

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -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
*/
#ifndef cglmc_project_no_h
#define cglmc_project_no_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../../cglm.h"
CGLM_EXPORT
void
glmc_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest);
CGLM_EXPORT
void
glmc_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_project_no_h */

View File

@@ -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
*/
#ifndef cglmc_project_zo_h
#define cglmc_project_zo_h
#ifdef __cplusplus
extern "C" {
#endif
#include "../../cglm.h"
CGLM_EXPORT
void
glmc_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest);
CGLM_EXPORT
void
glmc_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest);
#ifdef __cplusplus
}
#endif
#endif /* cglmc_project_zo_h */

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -11,7 +11,7 @@
extern "C" { extern "C" {
#endif #endif
#include "../cglm.h" #include "../../cglm.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -25,6 +25,10 @@ CGLM_EXPORT
void void
glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest); glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest);
CGLM_EXPORT
void
glmc_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -37,6 +37,10 @@ CGLM_EXPORT
void void
glmc_quat_copy(versor q, versor dest); glmc_quat_copy(versor q, versor dest);
CGLM_EXPORT
void
glmc_quat_from_vecs(vec3 a, vec3 b, versor dest);
CGLM_EXPORT CGLM_EXPORT
float float
glmc_quat_norm(versor q); glmc_quat_norm(versor q);

View File

@@ -149,6 +149,18 @@ CGLM_EXPORT
void void
glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest); glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_complex_mul(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_complex_div(vec2 a, vec2 b, vec2 dest);
CGLM_EXPORT
void
glmc_vec2_complex_conjugate(vec2 a, vec2 dest);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -30,6 +30,7 @@
#include "../common.h" #include "../common.h"
#include "../plane.h" #include "../plane.h"
#include "../mat4.h"
/*! /*!
* @brief set up orthographic projection matrix * @brief set up orthographic projection matrix

View File

@@ -30,6 +30,7 @@
#include "../common.h" #include "../common.h"
#include "../plane.h" #include "../plane.h"
#include "../mat4.h"
/*! /*!
* @brief set up orthographic projection matrix with a left-hand coordinate * @brief set up orthographic projection matrix with a left-hand coordinate

View File

@@ -30,6 +30,7 @@
#include "../common.h" #include "../common.h"
#include "../plane.h" #include "../plane.h"
#include "../mat4.h"
/*! /*!
* @brief set up orthographic projection matrix * @brief set up orthographic projection matrix

View File

@@ -30,6 +30,7 @@
#include "../common.h" #include "../common.h"
#include "../plane.h" #include "../plane.h"
#include "../mat4.h"
/*! /*!
* @brief set up orthographic projection matrix with a right-hand coordinate * @brief set up orthographic projection matrix with a right-hand coordinate

View File

@@ -47,7 +47,6 @@
#define cglm_persp_lh_no_h #define cglm_persp_lh_no_h
#include "../common.h" #include "../common.h"
#include "../plane.h"
#include "persp.h" #include "persp.h"
/*! /*!

View File

@@ -47,7 +47,6 @@
#define cglm_persp_lh_zo_h #define cglm_persp_lh_zo_h
#include "../common.h" #include "../common.h"
#include "../plane.h"
#include "persp.h" #include "persp.h"
/*! /*!

View File

@@ -47,7 +47,6 @@
#define cglm_persp_rh_no_h #define cglm_persp_rh_no_h
#include "../common.h" #include "../common.h"
#include "../plane.h"
#include "persp.h" #include "persp.h"
/*! /*!

View File

@@ -47,7 +47,6 @@
#define cglm_persp_rh_zo_h #define cglm_persp_rh_zo_h
#include "../common.h" #include "../common.h"
#include "../plane.h"
#include "persp.h" #include "persp.h"
/*! /*!

View File

@@ -0,0 +1,86 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_project_no_h
#define cglm_project_no_h
#include "../common.h"
#include "../vec3.h"
#include "../vec4.h"
#include "../mat4.h"
/*!
* @brief maps the specified viewport coordinates into specified space [1]
* the matrix should contain projection matrix.
*
* if you don't have ( and don't want to have ) an inverse matrix then use
* glm_unproject version. You may use existing inverse of matrix in somewhere
* else, this is why glm_unprojecti exists to save save inversion cost
*
* [1] space:
* 1- if m = invProj: View Space
* 2- if m = invViewProj: World Space
* 3- if m = invMVP: Object Space
*
* You probably want to map the coordinates into object space
* so use invMVP as m
*
* Computing viewProj:
* glm_mat4_mul(proj, view, viewProj);
* glm_mat4_mul(viewProj, model, MVP);
* glm_mat4_inv(viewProj, invMVP);
*
* @param[in] pos point/position in viewport coordinates
* @param[in] invMat matrix (see brief)
* @param[in] vp viewport as [x, y, width, height]
* @param[out] dest unprojected coordinates
*/
CGLM_INLINE
void
glm_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) {
vec4 v;
v[0] = 2.0f * (pos[0] - vp[0]) / vp[2] - 1.0f;
v[1] = 2.0f * (pos[1] - vp[1]) / vp[3] - 1.0f;
v[2] = 2.0f * pos[2] - 1.0f;
v[3] = 1.0f;
glm_mat4_mulv(invMat, v, v);
glm_vec4_scale(v, 1.0f / v[3], v);
glm_vec3(v, dest);
}
/*!
* @brief map object coordinates to window coordinates
*
* Computing MVP:
* glm_mat4_mul(proj, view, viewProj);
* glm_mat4_mul(viewProj, model, MVP);
*
* @param[in] pos object coordinates
* @param[in] m MVP matrix
* @param[in] vp viewport as [x, y, width, height]
* @param[out] dest projected coordinates
*/
CGLM_INLINE
void
glm_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) {
CGLM_ALIGN(16) vec4 pos4;
glm_vec4(pos, 1.0f, pos4);
glm_mat4_mulv(m, pos4, pos4);
glm_vec4_scale(pos4, 1.0f / pos4[3], pos4); /* pos = pos / pos.w */
glm_vec4_scale(pos4, 0.5f, pos4);
glm_vec4_adds(pos4, 0.5f, pos4);
dest[0] = pos4[0] * vp[2] + vp[0];
dest[1] = pos4[1] * vp[3] + vp[1];
dest[2] = pos4[2];
}
#endif /* cglm_project_no_h */

View File

@@ -0,0 +1,88 @@
/*
* Copyright (c), Recep Aslantas.
*
* MIT License (MIT), http://opensource.org/licenses/MIT
* Full license can be found in the LICENSE file
*/
#ifndef cglm_project_zo_h
#define cglm_project_zo_h
#include "../common.h"
#include "../vec3.h"
#include "../vec4.h"
#include "../mat4.h"
/*!
* @brief maps the specified viewport coordinates into specified space [1]
* the matrix should contain projection matrix.
*
* if you don't have ( and don't want to have ) an inverse matrix then use
* glm_unproject version. You may use existing inverse of matrix in somewhere
* else, this is why glm_unprojecti exists to save save inversion cost
*
* [1] space:
* 1- if m = invProj: View Space
* 2- if m = invViewProj: World Space
* 3- if m = invMVP: Object Space
*
* You probably want to map the coordinates into object space
* so use invMVP as m
*
* Computing viewProj:
* glm_mat4_mul(proj, view, viewProj);
* glm_mat4_mul(viewProj, model, MVP);
* glm_mat4_inv(viewProj, invMVP);
*
* @param[in] pos point/position in viewport coordinates
* @param[in] invMat matrix (see brief)
* @param[in] vp viewport as [x, y, width, height]
* @param[out] dest unprojected coordinates
*/
CGLM_INLINE
void
glm_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) {
vec4 v;
v[0] = 2.0f * (pos[0] - vp[0]) / vp[2] - 1.0f;
v[1] = 2.0f * (pos[1] - vp[1]) / vp[3] - 1.0f;
v[2] = pos[2];
v[3] = 1.0f;
glm_mat4_mulv(invMat, v, v);
glm_vec4_scale(v, 1.0f / v[3], v);
glm_vec3(v, dest);
}
/*!
* @brief map object coordinates to window coordinates
*
* Computing MVP:
* glm_mat4_mul(proj, view, viewProj);
* glm_mat4_mul(viewProj, model, MVP);
*
* @param[in] pos object coordinates
* @param[in] m MVP matrix
* @param[in] vp viewport as [x, y, width, height]
* @param[out] dest projected coordinates
*/
CGLM_INLINE
void
glm_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest) {
CGLM_ALIGN(16) vec4 pos4;
glm_vec4(pos, 1.0f, pos4);
glm_mat4_mulv(m, pos4, pos4);
glm_vec4_scale(pos4, 1.0f / pos4[3], pos4); /* pos = pos / pos.w */
dest[2] = pos4[2];
glm_vec4_scale(pos4, 0.5f, pos4);
glm_vec4_adds(pos4, 0.5f, pos4);
dest[0] = pos4[0] * vp[2] + vp[0];
dest[1] = pos4[1] * vp[3] + vp[1];
}
#endif /* cglm_project_zo_h */

View File

@@ -37,8 +37,8 @@ glm_lookat_lh(vec3 eye, vec3 center, vec3 up, mat4 dest) {
glm_vec3_sub(center, eye, f); glm_vec3_sub(center, eye, f);
glm_vec3_normalize(f); glm_vec3_normalize(f);
glm_vec3_crossn(f, up, s); glm_vec3_crossn(up, f, s);
glm_vec3_cross(s, f, u); glm_vec3_cross(f, s, u);
dest[0][0] = s[0]; dest[0][0] = s[0];
dest[0][1] = u[0]; dest[0][1] = u[0];

View File

@@ -15,6 +15,7 @@
#ifndef cglm_view_lh_no_h #ifndef cglm_view_lh_no_h
#define cglm_view_lh_no_h #define cglm_view_lh_no_h
#include "../common.h"
#include "view_lh.h" #include "view_lh.h"
/*! /*!

View File

@@ -15,6 +15,7 @@
#ifndef cglm_view_lh_zo_h #ifndef cglm_view_lh_zo_h
#define cglm_view_lh_zo_h #define cglm_view_lh_zo_h
#include "../common.h"
#include "view_lh.h" #include "view_lh.h"
/*! /*!

View File

@@ -15,6 +15,7 @@
#ifndef cglm_view_rh_no_h #ifndef cglm_view_rh_no_h
#define cglm_view_rh_no_h #define cglm_view_rh_no_h
#include "../common.h"
#include "view_rh.h" #include "view_rh.h"
/*! /*!

View File

@@ -15,6 +15,7 @@
#ifndef cglm_view_rh_zo_h #ifndef cglm_view_rh_zo_h
#define cglm_view_rh_zo_h #define cglm_view_rh_zo_h
#include "../common.h"
#include "view_rh.h" #include "view_rh.h"
/*! /*!

View File

@@ -44,7 +44,7 @@
#ifndef CGLM_USE_DEFAULT_EPSILON #ifndef CGLM_USE_DEFAULT_EPSILON
# ifndef GLM_FLT_EPSILON # ifndef GLM_FLT_EPSILON
# define GLM_FLT_EPSILON 1e-6 # define GLM_FLT_EPSILON 1e-5
# endif # endif
#else #else
# define GLM_FLT_EPSILON FLT_EPSILON # define GLM_FLT_EPSILON FLT_EPSILON

View File

@@ -13,6 +13,17 @@
#include "vec4.h" #include "vec4.h"
#include "mat4.h" #include "mat4.h"
#ifndef CGLM_CLIPSPACE_INCLUDE_ALL
# if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT
# include "clipspace/project_zo.h"
# elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT
# include "clipspace/project_no.h"
# endif
#else
# include "clipspace/project_zo.h"
# include "clipspace/project_no.h"
#endif
/*! /*!
* @brief maps the specified viewport coordinates into specified space [1] * @brief maps the specified viewport coordinates into specified space [1]
* the matrix should contain projection matrix. * the matrix should contain projection matrix.
@@ -42,16 +53,11 @@
CGLM_INLINE CGLM_INLINE
void void
glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) { glm_unprojecti(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) {
vec4 v; #if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT
glm_unprojecti_zo(pos, invMat, vp, dest);
v[0] = 2.0f * (pos[0] - vp[0]) / vp[2] - 1.0f; #elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT
v[1] = 2.0f * (pos[1] - vp[1]) / vp[3] - 1.0f; glm_unprojecti_no(pos, invMat, vp, dest);
v[2] = 2.0f * pos[2] - 1.0f; #endif
v[3] = 1.0f;
glm_mat4_mulv(invMat, v, v);
glm_vec4_scale(v, 1.0f / v[3], v);
glm_vec3(v, dest);
} }
/*! /*!
@@ -101,18 +107,44 @@ glm_unproject(vec3 pos, mat4 m, vec4 vp, vec3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { glm_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) {
CGLM_ALIGN(16) vec4 pos4, vone = GLM_VEC4_ONE_INIT; #if CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_ZO_BIT
glm_project_zo(pos, m, vp, dest);
#elif CGLM_CONFIG_CLIP_CONTROL & CGLM_CLIP_CONTROL_NO_BIT
glm_project_no(pos, m, vp, dest);
#endif
}
glm_vec4(pos, 1.0f, pos4); /*!
* @brief define a picking region
*
* @param[in] center center [x, y] of a picking region in window coordinates
* @param[in] size size [width, height] of the picking region in window coordinates
* @param[in] vp viewport as [x, y, width, height]
* @param[out] dest projected coordinates
*/
CGLM_INLINE
void
glm_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest) {
mat4 res;
vec3 v;
glm_mat4_mulv(m, pos4, pos4); if (size[0] <= 0.0f || size[1] <= 0.0f)
glm_vec4_scale(pos4, 1.0f / pos4[3], pos4); /* pos = pos / pos.w */ return;
glm_vec4_add(pos4, vone, pos4);
glm_vec4_scale(pos4, 0.5f, pos4); /* Translate and scale the picked region to the entire window */
v[0] = (vp[2] - 2.0f * (center[0] - vp[0])) / size[0];
v[1] = (vp[3] - 2.0f * (center[1] - vp[1])) / size[1];
v[2] = 0.0f;
dest[0] = pos4[0] * vp[2] + vp[0]; glm_translate_make(res, v);
dest[1] = pos4[1] * vp[3] + vp[1];
dest[2] = pos4[2]; v[0] = vp[2] / size[0];
v[1] = vp[3] / size[1];
v[2] = 1.0f;
glm_scale(res, v);
glm_mat4_copy(res, dest);
} }
#endif /* cglm_project_h */ #endif /* cglm_project_h */

View File

@@ -16,6 +16,7 @@
CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z); CGLM_INLINE void glm_quat(versor q, float angle, float x, float y, float z);
CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis); CGLM_INLINE void glm_quatv(versor q, float angle, vec3 axis);
CGLM_INLINE void glm_quat_copy(versor q, versor dest); CGLM_INLINE void glm_quat_copy(versor q, versor dest);
CGLM_INLINE void glm_quat_from_vecs(vec3 a, vec3 b, versor dest);
CGLM_INLINE float glm_quat_norm(versor q); CGLM_INLINE float glm_quat_norm(versor q);
CGLM_INLINE void glm_quat_normalize(versor q); CGLM_INLINE void glm_quat_normalize(versor q);
CGLM_INLINE void glm_quat_normalize_to(versor q, versor dest); CGLM_INLINE void glm_quat_normalize_to(versor q, versor dest);
@@ -59,6 +60,7 @@
#include "mat4.h" #include "mat4.h"
#include "mat3.h" #include "mat3.h"
#include "affine-mat.h" #include "affine-mat.h"
#include "affine.h"
#ifdef CGLM_SSE_FP #ifdef CGLM_SSE_FP
# include "simd/sse2/quat.h" # include "simd/sse2/quat.h"
@@ -68,17 +70,7 @@
# include "simd/neon/quat.h" # include "simd/neon/quat.h"
#endif #endif
CGLM_INLINE CGLM_INLINE void glm_quat_normalize(versor q);
void
glm_mat4_mulv(mat4 m, vec4 v, vec4 dest);
CGLM_INLINE
void
glm_mul_rot(mat4 m1, mat4 m2, mat4 dest);
CGLM_INLINE
void
glm_translate(mat4 m, vec3 v);
/* /*
* IMPORTANT: * IMPORTANT:
@@ -195,10 +187,41 @@ glm_quat_copy(versor q, versor dest) {
glm_vec4_copy(q, dest); glm_vec4_copy(q, dest);
} }
/*!
* @brief compute quaternion rotating vector A to vector B
*
* @param[in] a vec3 (must have unit length)
* @param[in] b vec3 (must have unit length)
* @param[out] dest quaternion (of unit length)
*/
CGLM_INLINE
void
glm_quat_from_vecs(vec3 a, vec3 b, versor dest) {
CGLM_ALIGN(8) vec3 axis;
float cos_theta;
float cos_half_theta;
cos_theta = glm_vec3_dot(a, b);
if (cos_theta >= 1.f - GLM_FLT_EPSILON) { /* a ∥ b */
glm_quat_identity(dest);
return;
}
if (cos_theta < -1.f + GLM_FLT_EPSILON) { /* angle(a, b) = π */
glm_vec3_ortho(a, axis);
cos_half_theta = 0.f; /* cos π/2 */
} else {
glm_vec3_cross(a, b, axis);
cos_half_theta = 1.0f + cos_theta; /* cos 0 + cos θ */
}
glm_quat_init(dest, axis[0], axis[1], axis[2], cos_half_theta);
glm_quat_normalize(dest);
}
/*! /*!
* @brief returns norm (magnitude) of quaternion * @brief returns norm (magnitude) of quaternion
* *
* @param[out] q quaternion * @param[in] q quaternion
*/ */
CGLM_INLINE CGLM_INLINE
float float

View File

@@ -34,7 +34,7 @@
#endif #endif
#if defined(__SSE3__) #if defined(__SSE3__)
# include <x86intrin.h> # include <pmmintrin.h>
# ifndef CGLM_SIMD_x86 # ifndef CGLM_SIMD_x86
# define CGLM_SIMD_x86 # define CGLM_SIMD_x86
# endif # endif

View File

@@ -86,13 +86,12 @@ CGLM_INLINE
void void
glm_inv_tr_neon(mat4 mat) { glm_inv_tr_neon(mat4 mat) {
float32x4x4_t vmat; float32x4x4_t vmat;
glmm_128 r0, r1, r2, r3, x0; glmm_128 r0, r1, r2, x0;
vmat = vld4q_f32(mat[0]); vmat = vld4q_f32(mat[0]);
r0 = vmat.val[0]; r0 = vmat.val[0];
r1 = vmat.val[1]; r1 = vmat.val[1];
r2 = vmat.val[2]; r2 = vmat.val[2];
r3 = vmat.val[3];
x0 = glmm_fmadd(r0, glmm_splat_w(r0), x0 = glmm_fmadd(r0, glmm_splat_w(r0),
glmm_fmadd(r1, glmm_splat_w(r1), glmm_fmadd(r1, glmm_splat_w(r1),

View File

@@ -101,4 +101,20 @@ glms_project(vec3s pos, mat4s m, vec4s vp) {
return r; return r;
} }
/*!
* @brief define a picking region
*
* @param[in] center center [x, y] of a picking region in window coordinates
* @param[in] size size [width, height] of the picking region in window coordinates
* @param[in] vp viewport as [x, y, width, height]
* @returns projected coordinates
*/
CGLM_INLINE
mat4s
glms_pickmatrix(vec2s center, vec2s size, vec4s vp) {
mat4s res;
glm_pickmatrix(center.raw, size.raw, vp.raw, res.raw);
return res;
}
#endif /* cglms_projects_h */ #endif /* cglms_projects_h */

View File

@@ -16,6 +16,7 @@
CGLM_INLINE versors glms_quat_init(float x, float y, float z, float w) CGLM_INLINE versors glms_quat_init(float x, float y, float z, float w)
CGLM_INLINE versors glms_quatv(float angle, vec3s axis) CGLM_INLINE versors glms_quatv(float angle, vec3s axis)
CGLM_INLINE versors glms_quat(float angle, float x, float y, float z) CGLM_INLINE versors glms_quat(float angle, float x, float y, float z)
CGLM_INLINE versors glms_quat_from_vecs(vec3s a, vec3s b)
CGLM_INLINE float glms_quat_norm(versors q) CGLM_INLINE float glms_quat_norm(versors q)
CGLM_INLINE versors glms_quat_normalize(versors q) CGLM_INLINE versors glms_quat_normalize(versors q)
CGLM_INLINE float glms_quat_dot(versors p, versors q) CGLM_INLINE float glms_quat_dot(versors p, versors q)
@@ -147,10 +148,25 @@ glms_quat(float angle, float x, float y, float z) {
return dest; return dest;
} }
/*!
* @brief compute quaternion rotating vector A to vector B
*
* @param[in] a vec3 (must have unit length)
* @param[in] b vec3 (must have unit length)
* @returns quaternion (of unit length)
*/
CGLM_INLINE
versors
glms_quat_from_vecs(vec3s a, vec3s b) {
versors dest;
glm_quat_from_vecs(a.raw, b.raw, dest.raw);
return dest;
}
/*! /*!
* @brief returns norm (magnitude) of quaternion * @brief returns norm (magnitude) of quaternion
* *
* @param[out] q quaternion * @param[in] q quaternion
*/ */
CGLM_INLINE CGLM_INLINE
float float
@@ -410,7 +426,7 @@ glms_quat_lerpc(versors from, versors to, float t) {
* @param[in] from from * @param[in] from from
* @param[in] to to * @param[in] to to
* @param[in] t interpolant (amount) * @param[in] t interpolant (amount)
* @param[out] dest result quaternion * @returns result quaternion
*/ */
CGLM_INLINE CGLM_INLINE
versors versors

View File

@@ -195,4 +195,45 @@ glms_vec2_sqrt(vec2s v) {
return r; return r;
} }
/*!
* @brief treat vectors as complex numbers and multiply them as such.
*
* @param[in] a left number
* @param[in] b right number
* @param[out] dest destination number
*/
CGLM_INLINE
vec2s
glms_vec2_complex_mul(vec2s a, vec2s b, vec2s dest) {
glm_vec2_complex_mul(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief treat vectors as complex numbers and divide them as such.
*
* @param[in] a left number (numerator)
* @param[in] b right number (denominator)
* @param[out] dest destination number
*/
CGLM_INLINE
vec2s
glms_vec2_complex_div(vec2s a, vec2s b, vec2s dest) {
glm_vec2_complex_div(a.raw, b.raw, dest.raw);
return dest;
}
/*!
* @brief treat the vector as a complex number and conjugate it as such.
*
* @param[in] a the number
* @param[out] dest destination number
*/
CGLM_INLINE
vec2s
glms_vec2_complex_conjugate(vec2s a, vec2s dest) {
glm_vec2_complex_conjugate(a.raw, dest.raw);
return dest;
}
#endif /* cglms_vec2s_ext_h */ #endif /* cglms_vec2s_ext_h */

View File

@@ -47,6 +47,21 @@ typedef union vec2s {
float x; float x;
float y; float y;
}; };
struct {
float r;
float i;
};
struct {
float u;
float v;
};
struct {
float s;
float t;
};
#endif #endif
} vec2s; } vec2s;
@@ -58,9 +73,40 @@ typedef union vec3s {
float y; float y;
float z; float z;
}; };
struct {
float r;
float g;
float b;
};
#endif #endif
} vec3s; } vec3s;
typedef union ivec2s {
ivec2 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
int x;
int y;
};
struct {
int r;
int i;
};
struct {
int u;
int v;
};
struct {
int s;
int t;
};
#endif
} ivec2s;
typedef union ivec3s { typedef union ivec3s {
ivec3 raw; ivec3 raw;
#if CGLM_USE_ANONYMOUS_STRUCT #if CGLM_USE_ANONYMOUS_STRUCT
@@ -69,9 +115,34 @@ typedef union ivec3s {
int y; int y;
int z; int z;
}; };
struct {
int r;
int g;
int b;
};
#endif #endif
} ivec3s; } ivec3s;
typedef union ivec4s {
ivec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT
struct {
int x;
int y;
int z;
int w;
};
struct {
int r;
int g;
int b;
int a;
};
#endif
} ivec4s;
typedef union CGLM_ALIGN_IF(16) vec4s { typedef union CGLM_ALIGN_IF(16) vec4s {
vec4 raw; vec4 raw;
#if CGLM_USE_ANONYMOUS_STRUCT #if CGLM_USE_ANONYMOUS_STRUCT
@@ -81,6 +152,13 @@ typedef union CGLM_ALIGN_IF(16) vec4s {
float z; float z;
float w; float w;
}; };
struct {
float r;
float g;
float b;
float a;
};
#endif #endif
} vec4s; } vec4s;

View File

@@ -42,9 +42,12 @@
#define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \ #define CGLM_CASTPTR_ASSUME_ALIGNED(expr, type) \
((type*)CGLM_ASSUME_ALIGNED((expr), __alignof__(type))) ((type*)CGLM_ASSUME_ALIGNED((expr), __alignof__(type)))
typedef int ivec2[2];
typedef int ivec3[3];
typedef int ivec4[4];
typedef float vec2[2]; typedef float vec2[2];
typedef float vec3[3]; typedef float vec3[3];
typedef int ivec3[3];
typedef CGLM_ALIGN_IF(16) float vec4[4]; typedef CGLM_ALIGN_IF(16) float vec4[4];
typedef vec4 versor; /* |x, y, z, w| -> w is the last */ typedef vec4 versor; /* |x, y, z, w| -> w is the last */
typedef vec3 mat3[3]; typedef vec3 mat3[3];

View File

@@ -20,6 +20,9 @@
CGLM_INLINE bool glm_vec2_isvalid(vec2 v); CGLM_INLINE bool glm_vec2_isvalid(vec2 v);
CGLM_INLINE void glm_vec2_sign(vec2 v, vec2 dest); CGLM_INLINE void glm_vec2_sign(vec2 v, vec2 dest);
CGLM_INLINE void glm_vec2_sqrt(vec2 v, vec2 dest); CGLM_INLINE void glm_vec2_sqrt(vec2 v, vec2 dest);
CGLM_INLINE void glm_vec2_complex_mul(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_complex_div(vec2 a, vec2 b, vec2 dest)
CGLM_INLINE void glm_vec2_complex_conjugate(vec2 a, vec2 dest)
*/ */
#ifndef cglm_vec2_ext_h #ifndef cglm_vec2_ext_h
@@ -186,4 +189,53 @@ glm_vec2_sqrt(vec2 v, vec2 dest) {
dest[1] = sqrtf(v[1]); dest[1] = sqrtf(v[1]);
} }
/*!
* @brief treat vectors as complex numbers and multiply them as such.
*
* @param[in] a left number
* @param[in] b right number
* @param[out] dest destination number
*/
CGLM_INLINE
void
glm_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) {
float tr, ti;
tr = a[0] * b[0] - a[1] * b[1];
ti = a[0] * b[1] + a[1] * b[0];
dest[0] = tr;
dest[1] = ti;
}
/*!
* @brief treat vectors as complex numbers and divide them as such.
*
* @param[in] a left number (numerator)
* @param[in] b right number (denominator)
* @param[out] dest destination number
*/
CGLM_INLINE
void
glm_vec2_complex_div(vec2 a, vec2 b, vec2 dest) {
float tr, ti;
float const ibnorm2 = 1.0f / (b[0] * b[0] + b[1] * b[1]);
tr = ibnorm2 * (a[0] * b[0] + a[1] * b[1]);
ti = ibnorm2 * (a[1] * b[0] - a[0] * b[1]);
dest[0] = tr;
dest[1] = ti;
}
/*!
* @brief treat the vector as a complex number and conjugate it as such.
*
* @param[in] a the number
* @param[out] dest destination number
*/
CGLM_INLINE
void
glm_vec2_complex_conjugate(vec2 a, vec2 dest) {
dest[0] = a[0];
dest[1] = -a[1];
}
#endif /* cglm_vec2_ext_h */ #endif /* cglm_vec2_ext_h */

View File

@@ -578,10 +578,12 @@ glm_vec3_normalize_to(vec3 v, vec3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_vec3_cross(vec3 a, vec3 b, vec3 dest) { glm_vec3_cross(vec3 a, vec3 b, vec3 dest) {
vec3 c;
/* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */ /* (u2.v3 - u3.v2, u3.v1 - u1.v3, u1.v2 - u2.v1) */
dest[0] = a[1] * b[2] - a[2] * b[1]; c[0] = a[1] * b[2] - a[2] * b[1];
dest[1] = a[2] * b[0] - a[0] * b[2]; c[1] = a[2] * b[0] - a[0] * b[2];
dest[2] = a[0] * b[1] - a[1] * b[0]; c[2] = a[0] * b[1] - a[1] * b[0];
glm_vec3_copy(c, dest);
} }
/*! /*!
@@ -807,9 +809,10 @@ glm_vec3_minv(vec3 a, vec3 b, vec3 dest) {
CGLM_INLINE CGLM_INLINE
void void
glm_vec3_ortho(vec3 v, vec3 dest) { glm_vec3_ortho(vec3 v, vec3 dest) {
dest[0] = v[1] - v[2]; float ignore;
dest[1] = v[2] - v[0]; float f = modff(fabsf(v[0]) + 0.5f, &ignore);
dest[2] = v[0] - v[1]; vec3 result = {-v[1], v[0] - f * v[2], f * v[1]};
glm_vec3_copy(result, dest);
} }
/*! /*!

View File

@@ -10,6 +10,6 @@
#define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MAJOR 0
#define CGLM_VERSION_MINOR 8 #define CGLM_VERSION_MINOR 8
#define CGLM_VERSION_PATCH 3 #define CGLM_VERSION_PATCH 5
#endif /* cglm_version_h */ #endif /* cglm_version_h */

View File

@@ -1,5 +1,5 @@
project('cglm', 'c', project('cglm', 'c',
version : '0.8.3', version : '0.8.5',
license : 'mit', license : 'mit',
default_options : [ default_options : [
'c_std=c11', 'c_std=c11',

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * 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/clipspace/ortho_lh_no.h"
#include "../../include/cglm/call/clipspace/ortho_lh_no.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * 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/clipspace/ortho_lh_zo.h"
#include "../../include/cglm/call/clipspace/ortho_lh_zo.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * 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/clipspace/ortho_rh_no.h"
#include "../../include/cglm/call/clipspace/ortho_rh_no.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * 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/clipspace/ortho_rh_zo.h"
#include "../../include/cglm/call/clipspace/ortho_rh_zo.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -6,6 +6,7 @@
*/ */
#include "../../include/cglm/clipspace/persp_lh_no.h" #include "../../include/cglm/clipspace/persp_lh_no.h"
#include "../../include/cglm/call/clipspace/persp_lh_no.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -6,6 +6,7 @@
*/ */
#include "../../include/cglm/clipspace/persp_lh_zo.h" #include "../../include/cglm/clipspace/persp_lh_zo.h"
#include "../../include/cglm/call/clipspace/persp_lh_zo.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -6,6 +6,7 @@
*/ */
#include "../../include/cglm/clipspace/persp_rh_no.h" #include "../../include/cglm/clipspace/persp_rh_no.h"
#include "../../include/cglm/call/clipspace/persp_rh_no.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -6,6 +6,7 @@
*/ */
#include "../../include/cglm/clipspace/persp_rh_zo.h" #include "../../include/cglm/clipspace/persp_rh_zo.h"
#include "../../include/cglm/call/clipspace/persp_rh_zo.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -0,0 +1,21 @@
/*
* 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/project_no.h"
#include "../../include/cglm/call/clipspace/project_no.h"
CGLM_EXPORT
void
glmc_unprojecti_no(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) {
glm_unprojecti_no(pos, invMat, vp, dest);
}
CGLM_EXPORT
void
glmc_project_no(vec3 pos, mat4 m, vec4 vp, vec3 dest) {
glm_project_no(pos, m, vp, dest);
}

View File

@@ -0,0 +1,21 @@
/*
* 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/project_zo.h"
#include "../../include/cglm/call/clipspace/project_zo.h"
CGLM_EXPORT
void
glmc_unprojecti_zo(vec3 pos, mat4 invMat, vec4 vp, vec3 dest) {
glm_unprojecti_zo(pos, invMat, vp, dest);
}
CGLM_EXPORT
void
glmc_project_zo(vec3 pos, mat4 m, vec4 vp, vec3 dest) {
glm_project_zo(pos, m, vp, dest);
}

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * 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/clipspace/view_lh_no.h"
#include "../../include/cglm/call/clipspace/view_lh_no.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * 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/clipspace/view_lh_zo.h"
#include "../../include/cglm/call/clipspace/view_lh_zo.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * 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/clipspace/view_rh_no.h"
#include "../../include/cglm/call/clipspace/view_rh_no.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -5,8 +5,8 @@
* Full license can be found in the LICENSE file * 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/clipspace/view_rh_zo.h"
#include "../../include/cglm/call/clipspace/view_rh_zo.h"
CGLM_EXPORT CGLM_EXPORT
void void

View File

@@ -25,3 +25,9 @@ void
glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) { glmc_project(vec3 pos, mat4 m, vec4 vp, vec3 dest) {
glm_project(pos, m, vp, dest); glm_project(pos, m, vp, dest);
} }
CGLM_EXPORT
void
glmc_pickmatrix(vec2 center, vec2 size, vec4 vp, mat4 dest) {
glm_pickmatrix(center, size, vp, dest);
}

View File

@@ -44,6 +44,12 @@ glmc_quat_copy(versor q, versor dest) {
glm_quat_copy(q, dest); glm_quat_copy(q, dest);
} }
CGLM_EXPORT
void
glmc_quat_from_vecs(vec3 a, vec3 b, versor dest) {
glm_quat_from_vecs(a, b, dest);
}
CGLM_EXPORT CGLM_EXPORT
float float
glmc_quat_norm(versor q) { glmc_quat_norm(versor q) {

View File

@@ -211,3 +211,21 @@ void
glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) { glmc_vec2_lerp(vec2 from, vec2 to, float t, vec2 dest) {
glm_vec2_lerp(from, to, t, dest); glm_vec2_lerp(from, to, t, dest);
} }
CGLM_EXPORT
void
glmc_vec2_complex_mul(vec2 a, vec2 b, vec2 dest) {
glm_vec2_complex_mul(a, b, dest);
}
CGLM_EXPORT
void
glmc_vec2_complex_div(vec2 a, vec2 b, vec2 dest) {
glm_vec2_complex_div(a, b, dest);
}
CGLM_EXPORT
void
glmc_vec2_complex_conjugate(vec2 a, vec2 dest) {
glm_vec2_complex_conjugate(a, dest);
}

View File

@@ -79,22 +79,20 @@ main(int argc, const char * argv[]) {
if (failed == 0) { if (failed == 0) {
fprintf(stderr, fprintf(stderr,
BOLDGREEN "\n All tests are passed " FINAL_TEXT "\n" RESET); BOLDGREEN "\n All tests passed " FINAL_TEXT "\n" RESET);
} }
fprintf(stderr, fprintf(stderr,
CYAN "\ncglm test results (%0.2fs):\n" RESET CYAN "\ncglm test results (%0.2fs):\n" RESET
"--------------------------\n" "--------------------------\n"
MAGENTA "%d" RESET " tests are runned, " MAGENTA "%d" RESET " tests ran, "
GREEN "%d" RESET " %s passed, " GREEN "%d" RESET " passed, "
RED "%d" RESET " %s failed\n\n" RESET, RED "%d" RESET " failed\n\n" RESET,
total, total,
count, count,
passed, passed,
passed > 1 ? "are" : "is", failed);
failed,
failed > 1 ? "are" : "is");
return failed; return failed;
} }

View File

@@ -151,6 +151,59 @@ TEST_IMPL(GLM_PREFIX, quat_copy) {
TEST_SUCCESS TEST_SUCCESS
} }
TEST_IMPL(GLM_PREFIX, quat_from_vecs) {
versor q1, q2, q3, q4, q5, q6, q7;
vec3 v1 = {1.f, 0.f, 0.f}, v2 = {1.f, 0.f, 0.f}; /* parallel */
vec3 v3 = {0.f, 1.f, 0.f}, v4 = {1.f, 0.f, 0.f}; /* perpendicular */
vec3 v5 = {0.f, 0.f, 1.f}, v6 = {0.f, 0.f, -1.f}; /* straight */
vec3 v7, v8; /* random */
vec3 v9 = {0.57735026f, 0.57735026f, 0.57735026f}, /* acute */
v10 = {0.70710678f, 0.70710678f, 0.f};
vec3 v11 = {0.87287156f, 0.21821789f, 0.43643578f}, /* obtuse */
v12 = {-0.87287156f, 0.21821789f, 0.43643578f};
vec3 v13 = GLM_VEC3_ZERO_INIT; /* zero */
GLM(quat_from_vecs)(v1, v2, q1);
ASSERTIFY(test_assert_quat_eq_identity(q1))
GLM(quat_from_vecs)(v3, v4, q2);
GLM(quat_rotatev)(q2, v3, v3);
ASSERT(test_eq(GLM(vec3_dot)(v3, v4), 1.f))
ASSERT(test_eq(q2[0], 0.f))
ASSERT(test_eq(q2[1], 0.f))
ASSERT(test_eq(q2[2], -0.707106781187f))
ASSERT(test_eq(q2[3], 0.707106781187f))
GLM(quat_from_vecs)(v5, v6, q3);
GLM(quat_rotatev)(q3, v5, v5);
ASSERT(test_eq(GLM(vec3_dot)(v5, v6), 1.f))
ASSERT(test_eq(q3[0], 0.f))
ASSERT(test_eq(q3[1], -1.f))
ASSERT(test_eq(q3[2], 0.f))
ASSERT(test_eq(q3[3], 0.f))
test_rand_vec3(v7);
test_rand_vec3(v8);
GLM(vec3_normalize(v7));
GLM(vec3_normalize(v8));
GLM(quat_from_vecs)(v7, v8, q4);
GLM(quat_rotatev)(q4, v7, v7);
ASSERT(test_eq(GLM(vec3_dot)(v7, v8), 1.f))
GLM(quat_from_vecs)(v9, v10, q5);
GLM(quat_rotatev)(q5, v9, v9);
ASSERT(test_eq(GLM(vec3_dot)(v9, v10), 1.f))
GLM(quat_from_vecs)(v11, v12, q6);
GLM(quat_rotatev)(q6, v11, v11);
ASSERT(test_eq(GLM(vec3_dot)(v11, v12), 1.f))
GLM(quat_from_vecs)(v13, v1, q7);
ASSERTIFY(test_assert_quat_eq_identity(q7))
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, quat_norm) { TEST_IMPL(GLM_PREFIX, quat_norm) {
versor a = {10.0f, 9.0f, 8.0f, 78.0f}; versor a = {10.0f, 9.0f, 8.0f, 78.0f};
float n1, n2; float n1, n2;

View File

@@ -594,3 +594,32 @@ TEST_IMPL(GLM_PREFIX, vec2_lerp) {
TEST_SUCCESS TEST_SUCCESS
} }
TEST_IMPL(GLM_PREFIX, vec2_complex_mul) {
vec2 v1 = { 3.0f, 5.0f },
v2 = { 7.0f, 11.0f },
v3 = { cosf(M_PI/4.0f), sinf(M_PI/4.0f) };
GLM(vec2_complex_mul)(v1, v2, v2);
ASSERTIFY(test_assert_vec2_eq(v2, (vec2){ -34, 68 }))
GLM(vec2_complex_mul)(v3, v3, v3);
ASSERTIFY(test_assert_vec2_eq(v3, (vec2){ 0.0f, 1.0f }))
TEST_SUCCESS
}
TEST_IMPL(GLM_PREFIX, vec2_complex_div) {
vec2 v1 = { -34.0f, 68.0f },
v2 = { 3.0f, 5.0f },
v3 = { cosf(M_PI/4.0f), sinf(M_PI/4.0f) },
v4 = { cosf(M_PI/4.0f), -sinf(M_PI/4.0f) };
GLM(vec2_complex_div)(v1, v2, v2);
ASSERTIFY(test_assert_vec2_eq(v2, (vec2){ 7.0f, 11.0f }))
GLM(vec2_complex_div)(v3, v4, v4);
ASSERTIFY(test_assert_vec2_eq(v4, (vec2){ 0.0f, 1.0f }))
TEST_SUCCESS
}

View File

@@ -1123,8 +1123,8 @@ TEST_IMPL(GLM_PREFIX, vec3_minv) {
} }
TEST_IMPL(GLM_PREFIX, vec3_ortho) { TEST_IMPL(GLM_PREFIX, vec3_ortho) {
vec3 v1, v2, v3; vec3 v1, v2, v3, v4 = {1.f, 1.f, 1.f};
vec3 v5, v6, v7; vec3 v5, v6, v7, v8;
float a; float a;
test_rand_vec3(v1); test_rand_vec3(v1);
@@ -1134,6 +1134,7 @@ TEST_IMPL(GLM_PREFIX, vec3_ortho) {
GLM(vec3_ortho)(v1, v5); GLM(vec3_ortho)(v1, v5);
GLM(vec3_ortho)(v2, v6); GLM(vec3_ortho)(v2, v6);
GLM(vec3_ortho)(v3, v7); GLM(vec3_ortho)(v3, v7);
GLM(vec3_ortho)(v4, v8);
a = glm_vec3_angle(v1, v5); a = glm_vec3_angle(v1, v5);
ASSERT(!isinf(a)) ASSERT(!isinf(a))
@@ -1150,6 +1151,11 @@ TEST_IMPL(GLM_PREFIX, vec3_ortho) {
ASSERT(!isnan(a)) ASSERT(!isnan(a))
ASSERT(test_eq(a, GLM_PI_2f)) ASSERT(test_eq(a, GLM_PI_2f))
a = glm_vec3_angle(v4, v8);
ASSERT(!isinf(a))
ASSERT(!isnan(a))
ASSERT(test_eq(a, GLM_PI_2f))
TEST_SUCCESS TEST_SUCCESS
} }

View File

@@ -297,6 +297,7 @@ TEST_DECLARE(glm_quat_rotatev)
TEST_DECLARE(glm_quat_rotate) TEST_DECLARE(glm_quat_rotate)
TEST_DECLARE(glm_quat_rotate_at) TEST_DECLARE(glm_quat_rotate_at)
TEST_DECLARE(glm_quat_rotate_atm) TEST_DECLARE(glm_quat_rotate_atm)
TEST_DECLARE(glm_quat_from_vecs)
TEST_DECLARE(glmc_quat_identity) TEST_DECLARE(glmc_quat_identity)
TEST_DECLARE(glmc_quat_identity_array) TEST_DECLARE(glmc_quat_identity_array)
@@ -334,6 +335,7 @@ TEST_DECLARE(glmc_quat_rotatev)
TEST_DECLARE(glmc_quat_rotate) TEST_DECLARE(glmc_quat_rotate)
TEST_DECLARE(glmc_quat_rotate_at) TEST_DECLARE(glmc_quat_rotate_at)
TEST_DECLARE(glmc_quat_rotate_atm) TEST_DECLARE(glmc_quat_rotate_atm)
TEST_DECLARE(glmc_quat_from_vecs)
/* bezier */ /* bezier */
TEST_DECLARE(bezier) TEST_DECLARE(bezier)
@@ -380,6 +382,8 @@ TEST_DECLARE(glm_vec2_maxv)
TEST_DECLARE(glm_vec2_minv) TEST_DECLARE(glm_vec2_minv)
TEST_DECLARE(glm_vec2_clamp) TEST_DECLARE(glm_vec2_clamp)
TEST_DECLARE(glm_vec2_lerp) TEST_DECLARE(glm_vec2_lerp)
TEST_DECLARE(glm_vec2_complex_mul)
TEST_DECLARE(glm_vec2_complex_div)
TEST_DECLARE(glmc_vec2) TEST_DECLARE(glmc_vec2)
@@ -416,6 +420,8 @@ TEST_DECLARE(glmc_vec2_maxv)
TEST_DECLARE(glmc_vec2_minv) TEST_DECLARE(glmc_vec2_minv)
TEST_DECLARE(glmc_vec2_clamp) TEST_DECLARE(glmc_vec2_clamp)
TEST_DECLARE(glmc_vec2_lerp) TEST_DECLARE(glmc_vec2_lerp)
TEST_DECLARE(glmc_vec2_complex_mul)
TEST_DECLARE(glmc_vec2_complex_div)
/* vec3 */ /* vec3 */
TEST_DECLARE(MACRO_GLM_VEC3_ONE_INIT) TEST_DECLARE(MACRO_GLM_VEC3_ONE_INIT)
@@ -1025,6 +1031,7 @@ TEST_LIST {
TEST_ENTRY(glm_quat_rotate) TEST_ENTRY(glm_quat_rotate)
TEST_ENTRY(glm_quat_rotate_at) TEST_ENTRY(glm_quat_rotate_at)
TEST_ENTRY(glm_quat_rotate_atm) TEST_ENTRY(glm_quat_rotate_atm)
TEST_ENTRY(glm_quat_from_vecs)
TEST_ENTRY(glmc_quat_identity) TEST_ENTRY(glmc_quat_identity)
TEST_ENTRY(glmc_quat_identity_array) TEST_ENTRY(glmc_quat_identity_array)
@@ -1062,6 +1069,7 @@ TEST_LIST {
TEST_ENTRY(glmc_quat_rotate) TEST_ENTRY(glmc_quat_rotate)
TEST_ENTRY(glmc_quat_rotate_at) TEST_ENTRY(glmc_quat_rotate_at)
TEST_ENTRY(glmc_quat_rotate_atm) TEST_ENTRY(glmc_quat_rotate_atm)
TEST_ENTRY(glmc_quat_from_vecs)
/* bezier */ /* bezier */
TEST_ENTRY(bezier) TEST_ENTRY(bezier)
@@ -1108,6 +1116,8 @@ TEST_LIST {
TEST_ENTRY(glm_vec2_minv) TEST_ENTRY(glm_vec2_minv)
TEST_ENTRY(glm_vec2_clamp) TEST_ENTRY(glm_vec2_clamp)
TEST_ENTRY(glm_vec2_lerp) TEST_ENTRY(glm_vec2_lerp)
TEST_ENTRY(glm_vec2_complex_mul)
TEST_ENTRY(glm_vec2_complex_div)
TEST_ENTRY(glmc_vec2) TEST_ENTRY(glmc_vec2)
TEST_ENTRY(glmc_vec2_copy) TEST_ENTRY(glmc_vec2_copy)
@@ -1143,6 +1153,8 @@ TEST_LIST {
TEST_ENTRY(glmc_vec2_minv) TEST_ENTRY(glmc_vec2_minv)
TEST_ENTRY(glmc_vec2_clamp) TEST_ENTRY(glmc_vec2_clamp)
TEST_ENTRY(glmc_vec2_lerp) TEST_ENTRY(glmc_vec2_lerp)
TEST_ENTRY(glmc_vec2_complex_mul)
TEST_ENTRY(glmc_vec2_complex_div)
/* vec3 */ /* vec3 */
/* Macros */ /* Macros */

View File

@@ -32,6 +32,8 @@
<ClCompile Include="..\src\clipspace\persp_lh_zo.c" /> <ClCompile Include="..\src\clipspace\persp_lh_zo.c" />
<ClCompile Include="..\src\clipspace\persp_rh_no.c" /> <ClCompile Include="..\src\clipspace\persp_rh_no.c" />
<ClCompile Include="..\src\clipspace\persp_rh_zo.c" /> <ClCompile Include="..\src\clipspace\persp_rh_zo.c" />
<ClCompile Include="..\src\clipspace\project_no.c" />
<ClCompile Include="..\src\clipspace\project_zo.c" />
<ClCompile Include="..\src\clipspace\view_lh_no.c" /> <ClCompile Include="..\src\clipspace\view_lh_no.c" />
<ClCompile Include="..\src\clipspace\view_lh_zo.c" /> <ClCompile Include="..\src\clipspace\view_lh_zo.c" />
<ClCompile Include="..\src\clipspace\view_rh_no.c" /> <ClCompile Include="..\src\clipspace\view_rh_no.c" />
@@ -74,6 +76,8 @@
<ClInclude Include="..\include\cglm\call\clipspace\persp_lh_zo.h" /> <ClInclude Include="..\include\cglm\call\clipspace\persp_lh_zo.h" />
<ClInclude Include="..\include\cglm\call\clipspace\persp_rh_no.h" /> <ClInclude Include="..\include\cglm\call\clipspace\persp_rh_no.h" />
<ClInclude Include="..\include\cglm\call\clipspace\persp_rh_zo.h" /> <ClInclude Include="..\include\cglm\call\clipspace\persp_rh_zo.h" />
<ClInclude Include="..\include\cglm\call\clipspace\project_no.h" />
<ClInclude Include="..\include\cglm\call\clipspace\project_zo.h" />
<ClInclude Include="..\include\cglm\call\clipspace\view_lh_no.h" /> <ClInclude Include="..\include\cglm\call\clipspace\view_lh_no.h" />
<ClInclude Include="..\include\cglm\call\clipspace\view_lh_zo.h" /> <ClInclude Include="..\include\cglm\call\clipspace\view_lh_zo.h" />
<ClInclude Include="..\include\cglm\call\clipspace\view_rh_no.h" /> <ClInclude Include="..\include\cglm\call\clipspace\view_rh_no.h" />
@@ -105,6 +109,8 @@
<ClInclude Include="..\include\cglm\clipspace\persp_lh_zo.h" /> <ClInclude Include="..\include\cglm\clipspace\persp_lh_zo.h" />
<ClInclude Include="..\include\cglm\clipspace\persp_rh_no.h" /> <ClInclude Include="..\include\cglm\clipspace\persp_rh_no.h" />
<ClInclude Include="..\include\cglm\clipspace\persp_rh_zo.h" /> <ClInclude Include="..\include\cglm\clipspace\persp_rh_zo.h" />
<ClInclude Include="..\include\cglm\clipspace\project_no.h" />
<ClInclude Include="..\include\cglm\clipspace\project_zo.h" />
<ClInclude Include="..\include\cglm\clipspace\view_lh.h" /> <ClInclude Include="..\include\cglm\clipspace\view_lh.h" />
<ClInclude Include="..\include\cglm\clipspace\view_lh_no.h" /> <ClInclude Include="..\include\cglm\clipspace\view_lh_no.h" />
<ClInclude Include="..\include\cglm\clipspace\view_lh_zo.h" /> <ClInclude Include="..\include\cglm\clipspace\view_lh_zo.h" />

View File

@@ -142,6 +142,12 @@
<ClCompile Include="..\src\clipspace\view_rh_zo.c"> <ClCompile Include="..\src\clipspace\view_rh_zo.c">
<Filter>src\clipspace</Filter> <Filter>src\clipspace</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\src\clipspace\project_no.c">
<Filter>src\clipspace</Filter>
</ClCompile>
<ClCompile Include="..\src\clipspace\project_zo.c">
<Filter>src\clipspace</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\src\config.h"> <ClInclude Include="..\src\config.h">
@@ -540,5 +546,17 @@
<ClInclude Include="..\include\cglm\struct\clipspace\view_rh_zo.h"> <ClInclude Include="..\include\cglm\struct\clipspace\view_rh_zo.h">
<Filter>include\cglm\struct\clipspace</Filter> <Filter>include\cglm\struct\clipspace</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\include\cglm\clipspace\project_no.h">
<Filter>include\cglm\clipspace</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\clipspace\project_zo.h">
<Filter>include\cglm\clipspace</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\call\clipspace\project_no.h">
<Filter>include\cglm\call\clipspace</Filter>
</ClInclude>
<ClInclude Include="..\include\cglm\call\clipspace\project_zo.h">
<Filter>include\cglm\call\clipspace</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>