mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
34e5704fe8 | ||
|
|
672523e5af | ||
|
|
8427d02a9b | ||
|
|
a2bd00df32 | ||
|
|
4c8f7f310c | ||
|
|
9096fa6bab | ||
|
|
29c3837672 | ||
|
|
4530e0381b | ||
|
|
6cf1fb8992 | ||
|
|
9ed4e41afd | ||
|
|
28d24da6df | ||
|
|
ef22e2063f | ||
|
|
5a48aad1b0 | ||
|
|
07aee82125 | ||
|
|
abbeb274c5 | ||
|
|
814adf11de | ||
|
|
d0d1e46533 | ||
|
|
03b4594d9e | ||
|
|
01e2b74a29 | ||
|
|
ee5050f43c | ||
|
|
b5802b99b2 | ||
|
|
8b958e9600 | ||
|
|
aa071b2a6b | ||
|
|
479e7d4240 | ||
|
|
38c6188e12 | ||
|
|
c330b47ded | ||
|
|
2e8162b133 | ||
|
|
afdcae08dd | ||
|
|
32d1c96dc0 | ||
|
|
4d2ba464a0 | ||
|
|
398e47070b | ||
|
|
619ac4ce9a | ||
|
|
e83940f3b1 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -78,3 +78,4 @@ confdefs.h
|
|||||||
*.xcuserdatad
|
*.xcuserdatad
|
||||||
.idea
|
.idea
|
||||||
cmake-build-debug
|
cmake-build-debug
|
||||||
|
*.o.tmp
|
||||||
|
|||||||
@@ -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.4 LANGUAGES C)
|
||||||
|
|
||||||
set(CMAKE_C_STANDARD 11)
|
set(CMAKE_C_STANDARD 11)
|
||||||
set(CMAKE_C_STANDARD_REQUIRED YES)
|
set(CMAKE_C_STANDARD_REQUIRED YES)
|
||||||
|
|||||||
4
CREDITS
4
CREDITS
@@ -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
|
||||||
|
|||||||
24
Makefile.am
24
Makefile.am
@@ -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,7 +220,9 @@ 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 \
|
||||||
|
|||||||
79
README.md
79
README.md
@@ -1,19 +1,59 @@
|
|||||||
# 🎥 OpenGL Mathematics (glm) for `C`
|
# 🎥 OpenGL Mathematics (glm) for `C`
|
||||||
[](https://travis-ci.com/recp/cglm)
|
|
||||||
[](https://ci.appveyor.com/project/recp/cglm/branch/master)
|
|
||||||
[](http://cglm.readthedocs.io/en/latest/?badge=latest)
|
|
||||||
[](https://coveralls.io/github/recp/cglm?branch=master)
|
|
||||||
[](https://codecov.io/gh/recp/cglm)
|
|
||||||
[](https://www.codacy.com/app/recp/cglm?utm_source=github.com&utm_medium=referral&utm_content=recp/cglm&utm_campaign=Badge_Grade)
|
|
||||||
[](#backers)
|
|
||||||
[](#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&utm_medium=referral&utm_content=recp/cglm&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
|
||||||
|
|||||||
@@ -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.
|
||||||
|
|||||||
@@ -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.4], [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.
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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.4'
|
||||||
# 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.4'
|
||||||
|
|
||||||
# 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.
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
27
include/cglm/call/clipspace/project_no.h
Normal file
27
include/cglm/call/clipspace/project_no.h
Normal 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 */
|
||||||
27
include/cglm/call/clipspace/project_zo.h
Normal file
27
include/cglm/call/clipspace/project_zo.h
Normal 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 */
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../cglm.h"
|
#include "../../cglm.h"
|
||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
void
|
void
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
86
include/cglm/clipspace/project_no.h
Normal file
86
include/cglm/clipspace/project_no.h
Normal 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 */
|
||||||
88
include/cglm/clipspace/project_zo.h
Normal file
88
include/cglm/clipspace/project_zo.h
Normal 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 */
|
||||||
@@ -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"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -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"
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -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(vec3 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);
|
|
||||||
|
|
||||||
dest[0] = pos4[0] * vp[2] + vp[0];
|
/* Translate and scale the picked region to the entire window */
|
||||||
dest[1] = pos4[1] * vp[3] + vp[1];
|
v[0] = (vp[2] - 2.0f * (center[0] - vp[0])) / size[0];
|
||||||
dest[2] = pos4[2];
|
v[1] = (vp[3] - 2.0f * (center[1] - vp[1])) / size[1];
|
||||||
|
v[2] = 0.0f;
|
||||||
|
|
||||||
|
glm_translate_make(res, v);
|
||||||
|
|
||||||
|
v[0] = vp[2] / size[0];
|
||||||
|
v[1] = vp[3] / size[1];
|
||||||
|
v[2] = 1.0f;
|
||||||
|
|
||||||
|
glm_scale(res, v);
|
||||||
|
|
||||||
|
glm_mat4_copy(res, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* cglm_project_h */
|
#endif /* cglm_project_h */
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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(vec3s 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 */
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -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 4
|
||||||
|
|
||||||
#endif /* cglm_version_h */
|
#endif /* cglm_version_h */
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
project('cglm', 'c',
|
project('cglm', 'c',
|
||||||
version : '0.8.3',
|
version : '0.8.4',
|
||||||
license : 'mit',
|
license : 'mit',
|
||||||
default_options : [
|
default_options : [
|
||||||
'c_std=c11',
|
'c_std=c11',
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
21
src/clipspace/project_no.c
Normal file
21
src/clipspace/project_no.c
Normal 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);
|
||||||
|
}
|
||||||
21
src/clipspace/project_zo.c
Normal file
21
src/clipspace/project_zo.c
Normal 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);
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -1025,6 +1027,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 +1065,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)
|
||||||
|
|||||||
@@ -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" />
|
||||||
|
|||||||
@@ -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>
|
||||||
Reference in New Issue
Block a user