mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
Compare commits
90 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f8784ffe8a | ||
|
|
cf8dc82783 | ||
|
|
9af0ebd142 | ||
|
|
82a195f26a | ||
|
|
6abe3f05ab | ||
|
|
f53fd45026 | ||
|
|
c67158ac59 | ||
|
|
af7f8a5436 | ||
|
|
c3b5bb869a | ||
|
|
d6c34d3330 | ||
|
|
13a742f48c | ||
|
|
0330be853c | ||
|
|
5cb800bf29 | ||
|
|
1d19948f30 | ||
|
|
d89c01b39f | ||
|
|
b9aa14d25e | ||
|
|
8ad273475f | ||
|
|
c8211b3a62 | ||
|
|
11dae5126b | ||
|
|
390a5035a8 | ||
|
|
267348af03 | ||
|
|
f9abf2a7df | ||
|
|
f0ffef7820 | ||
|
|
4b9b7aeb20 | ||
|
|
1a74361dfb | ||
|
|
c83f25343f | ||
|
|
f3ea5b4f3e | ||
|
|
9987e1374b | ||
|
|
464b2178ce | ||
|
|
c253769fcd | ||
|
|
b893c79086 | ||
|
|
2336256808 | ||
|
|
52df54e306 | ||
|
|
381e66349a | ||
|
|
7cdeada701 | ||
|
|
841257a208 | ||
|
|
212cf3b22d | ||
|
|
ca9b8ceac3 | ||
|
|
5b0e161502 | ||
|
|
fb23d1998e | ||
|
|
b2084fbacf | ||
|
|
2ea9308361 | ||
|
|
56cbacd9f6 | ||
|
|
1700187f65 | ||
|
|
36024367bc | ||
|
|
dcf5b5c1c4 | ||
|
|
ce09e543ef | ||
|
|
f2073b2277 | ||
|
|
7c10840a85 | ||
|
|
37c2650b0a | ||
|
|
3a48e4cd84 | ||
|
|
378e26140e | ||
|
|
7b25cbb9cb | ||
|
|
bffe103c37 | ||
|
|
51ffe09589 | ||
|
|
d7b37ba245 | ||
|
|
d0671b3e7a | ||
|
|
e98311259c | ||
|
|
37cf6b3206 | ||
|
|
a062f002a0 | ||
|
|
9c57d4b247 | ||
|
|
9fe5efb410 | ||
|
|
495afb8a3d | ||
|
|
ba694f4aec | ||
|
|
8ac767fd2c | ||
|
|
e5fd735e62 | ||
|
|
7797ee7b06 | ||
|
|
78f38db480 | ||
|
|
79087a9813 | ||
|
|
a1283282ef | ||
|
|
0377b99f80 | ||
|
|
971d753392 | ||
|
|
033d0b0fed | ||
|
|
39dc61af54 | ||
|
|
f4f9d85caa | ||
|
|
92f196965e | ||
|
|
fbcbccbf01 | ||
|
|
cf41151534 | ||
|
|
3af861b61e | ||
|
|
0ed88cfda8 | ||
|
|
551ed1bd20 | ||
|
|
a328317c70 | ||
|
|
5aa047efdf | ||
|
|
32e5784564 | ||
|
|
80c2b3712d | ||
|
|
176cc28510 | ||
|
|
712cbee580 | ||
|
|
981fd5ee44 | ||
|
|
092da3e189 | ||
|
|
9ab9e95ce5 |
24
.github/workflows/ccpp.yml
vendored
24
.github/workflows/ccpp.yml
vendored
@@ -1,24 +0,0 @@
|
||||
name: C/C++ CI
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macOS-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: dependencies
|
||||
run: sh ./build-deps.sh
|
||||
- name: autogen
|
||||
run: sh autogen.sh
|
||||
- name: configure
|
||||
run: ./configure
|
||||
- name: make
|
||||
run: make
|
||||
- name: make check
|
||||
run: make check
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -51,7 +51,6 @@ cscope.*
|
||||
test/*.trs
|
||||
test/test_*
|
||||
*.log
|
||||
test-*
|
||||
test/.libs/*
|
||||
test/tests
|
||||
cglm_arm/*
|
||||
@@ -71,3 +70,5 @@ win/x85
|
||||
win/Debug
|
||||
cglm-test-ios*
|
||||
/cglm.pc
|
||||
test-driver
|
||||
Default-568h@2x.png
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +0,0 @@
|
||||
[submodule "test/lib/cmocka"]
|
||||
path = test/lib/cmocka
|
||||
url = git://git.cryptomilk.org/projects/cmocka.git
|
||||
|
||||
10
.travis.yml
10
.travis.yml
@@ -37,10 +37,9 @@ branches:
|
||||
- master
|
||||
|
||||
script:
|
||||
- sh ./build-deps.sh
|
||||
- sh ./autogen.sh
|
||||
- if [[ "$CC" == "gcc" && "$CODE_COVERAGE" == "ON" ]]; then
|
||||
./configure CFLAGS="-ftest-coverage -fprofile-arcs";
|
||||
./configure CFLAGS="-ftest-coverage -fprofile-arcs -coverage";
|
||||
else
|
||||
./configure;
|
||||
fi
|
||||
@@ -55,8 +54,9 @@ after_success:
|
||||
--exclude lib
|
||||
--exclude test
|
||||
--gcov-options '\-lp'
|
||||
--verbose;
|
||||
--verbose &&
|
||||
bash <(curl -s https://codecov.io/bash);
|
||||
fi
|
||||
|
||||
after_failure:
|
||||
- cat ./test-suite.log
|
||||
# after_failure:
|
||||
# - cat ./test-suite.log
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
# CONTRIBUTING
|
||||
|
||||
Any contributions (code, documentation, ...) are welcome. This project uses [cmocka](http://cmocka.org) for testing, you may need to check their documentation
|
||||
Any contributions (code, documentation, ...) are welcome.
|
||||
|
||||
# New Features
|
||||
- This library may not accept all new features, it is better to create an issue and get approval before coding
|
||||
- You must add test for every new feature
|
||||
- The feature must be compiled in both UNIX/POSIX systems (e.g. macos, linux...) and Windows
|
||||
- The feature must be compiled on both UNIX/POSIX systems (e.g. macos, linux...) and Windows
|
||||
|
||||
# Code Style
|
||||
This library is written with C99, don't try to add C++ files (yes it can compiled into lib),
|
||||
|
||||
30
Makefile.am
30
Makefile.am
@@ -7,23 +7,21 @@
|
||||
#******************************************************************************
|
||||
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
AM_CFLAGS = -Wall \
|
||||
-std=gnu99 \
|
||||
-std=gnu11 \
|
||||
-O3 \
|
||||
-Wstrict-aliasing=2 \
|
||||
-fstrict-aliasing \
|
||||
-pedantic
|
||||
-pedantic \
|
||||
-Werror=strict-prototypes
|
||||
|
||||
lib_LTLIBRARIES = libcglm.la
|
||||
libcglm_la_LDFLAGS = -no-undefined -version-info 0:1:0
|
||||
|
||||
checkLDFLAGS = -L./.libs \
|
||||
-L./test/lib/cmocka/build/src \
|
||||
-lcmocka \
|
||||
-lm \
|
||||
-lcglm
|
||||
checkCFLAGS = -I./test/lib/cmocka/include \
|
||||
checkCFLAGS = $(AM_CFLAGS) \
|
||||
-I./include
|
||||
|
||||
check_PROGRAMS = test/tests
|
||||
@@ -34,14 +32,16 @@ test_tests_CFLAGS = $(checkCFLAGS)
|
||||
|
||||
cglmdir=$(includedir)/cglm
|
||||
cglm_HEADERS = include/cglm/version.h \
|
||||
include/cglm/common.h \
|
||||
include/cglm/types.h \
|
||||
include/cglm/types-struct.h \
|
||||
include/cglm/cglm.h \
|
||||
include/cglm/call.h \
|
||||
include/cglm/struct.h \
|
||||
include/cglm/cam.h \
|
||||
include/cglm/io.h \
|
||||
include/cglm/mat4.h \
|
||||
include/cglm/mat3.h \
|
||||
include/cglm/types.h \
|
||||
include/cglm/common.h \
|
||||
include/cglm/affine.h \
|
||||
include/cglm/vec3.h \
|
||||
include/cglm/vec3-ext.h \
|
||||
@@ -60,8 +60,7 @@ cglm_HEADERS = include/cglm/version.h \
|
||||
include/cglm/ease.h \
|
||||
include/cglm/curve.h \
|
||||
include/cglm/bezier.h \
|
||||
include/cglm/types-struct.h \
|
||||
include/cglm/struct.h
|
||||
include/cglm/applesimd.h
|
||||
|
||||
cglm_calldir=$(includedir)/cglm/call
|
||||
cglm_call_HEADERS = include/cglm/call/mat4.h \
|
||||
@@ -140,8 +139,8 @@ libcglm_la_SOURCES=\
|
||||
src/bezier.c
|
||||
|
||||
test_tests_SOURCES=\
|
||||
test/runner.c \
|
||||
test/src/test_common.c \
|
||||
test/src/test_main.c \
|
||||
test/src/test_mat4.c \
|
||||
test/src/test_cam.c \
|
||||
test/src/test_project.c \
|
||||
@@ -152,7 +151,8 @@ test_tests_SOURCES=\
|
||||
test/src/test_vec3.c \
|
||||
test/src/test_mat3.c \
|
||||
test/src/test_affine.c \
|
||||
test/src/test_bezier.c
|
||||
test/src/test_bezier.c \
|
||||
test/src/test_struct.c
|
||||
|
||||
pkgconfig_DATA=cglm.pc
|
||||
|
||||
@@ -160,7 +160,7 @@ pkgconfig_DATA=cglm.pc
|
||||
# the source directory that post-build.sh is in. When not
|
||||
# using a prefix, $VPATH will be unset, so we need to fall
|
||||
# back to using . to run the script.
|
||||
export VPATH
|
||||
#export VPATH
|
||||
|
||||
all-local:
|
||||
sh $${VPATH:-.}/post-build.sh
|
||||
# all-local:
|
||||
# sh $${VPATH:-.}/post-build.sh
|
||||
|
||||
31
README.md
31
README.md
@@ -3,6 +3,7 @@
|
||||
[](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)
|
||||
@@ -32,7 +33,7 @@ https://github.com/g-truc/glm
|
||||
#### Note for new comers (Important):
|
||||
- `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
|
||||
- All functions are inline if you don't want to use pre-compiled versions with glmc_ prefix, you can ignore build process. Just incliude 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...
|
||||
- Welcome!
|
||||
|
||||
@@ -87,6 +88,7 @@ Currently *cglm* uses default clip space configuration (-1, 1) for camera functi
|
||||
- easing functions
|
||||
- curves
|
||||
- curve interpolation helpers (S*M*C, deCasteljau...)
|
||||
- helpers to convert cglm types to Apple's simd library to pass cglm types to Metal GL without packing them on both sides
|
||||
- and others...
|
||||
|
||||
<hr />
|
||||
@@ -129,20 +131,31 @@ glm_mul(T, R, modelMat);
|
||||
glm_inv_tr(modelMat);
|
||||
```
|
||||
|
||||
### Struct API
|
||||
|
||||
The struct API works as follows, note the `s` suffix on types, the `glms_` prefix on functions and the `GLMS_` prefix on constants:
|
||||
|
||||
```C
|
||||
#include <cglm/struct.h>
|
||||
|
||||
mat4s mat = GLMS_MAT4_IDENTITY_INIT;
|
||||
mat4s inv = glms_mat4_inv(mat);
|
||||
```
|
||||
|
||||
Struct functions generally take their parameters as *values* and *return* their results, rather than taking pointers and writing to out parameters. That means your parameters can usually be `const`, if you're into that.
|
||||
|
||||
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
|
||||
|
||||
### Unix (Autotools)
|
||||
|
||||
```bash
|
||||
$ sh ./build-deps.sh # run only once (dependencies) [Optional].
|
||||
$ # You can pass this step if you don't want to run `make check` for tests.
|
||||
$ # cglm uses cmocka for tests and it may reqiure cmake for building it
|
||||
$
|
||||
$ sh autogen.sh
|
||||
$ ./configure
|
||||
$ make
|
||||
$ make check # [Optional] (if you run `sh ./build-deps.sh`)
|
||||
$ [sudo] make install
|
||||
$ make check # [Optional]
|
||||
$ [sudo] make install # [Optional]
|
||||
```
|
||||
|
||||
This will also install pkg-config files so you can use
|
||||
@@ -170,6 +183,10 @@ if `msbuild` won't work (because of multi version VS) then try to build with `de
|
||||
$ devenv cglm.sln /Build Release
|
||||
```
|
||||
|
||||
#### Running Tests on Windows
|
||||
|
||||
You can see test project in same visual studio solution file. It is enough to run that project to run tests.
|
||||
|
||||
### Building Docs
|
||||
First you need install Sphinx: http://www.sphinx-doc.org/en/master/usage/installation.html
|
||||
then:
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# Copyright (c), Recep Aslantas.
|
||||
#
|
||||
# MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
# Full license can be found in the LICENSE file
|
||||
#
|
||||
|
||||
# check if deps are pulled
|
||||
git submodule update --init --recursive
|
||||
|
||||
cd $(dirname "$0")
|
||||
|
||||
# general deps: gcc make autoconf automake libtool cmake
|
||||
|
||||
# test - cmocka
|
||||
cd ./test/lib/cmocka
|
||||
rm -rf build
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Debug ..
|
||||
make -j8
|
||||
cd ../../../../
|
||||
@@ -2,7 +2,7 @@ Pod::Spec.new do |s|
|
||||
|
||||
# Description
|
||||
s.name = "cglm"
|
||||
s.version = "0.5.1"
|
||||
s.version = "0.6.1"
|
||||
s.summary = "📽 Optimized OpenGL/Graphics Math (glm) for C"
|
||||
s.description = <<-DESC
|
||||
cglm is math library for graphics programming for C. It is similar to original glm but it is written for C instead of C++ (you can use here too). See the documentation or README for all features.
|
||||
|
||||
@@ -7,8 +7,11 @@
|
||||
#*****************************************************************************
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([cglm], [0.6.0], [info@recp.me])
|
||||
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
|
||||
AC_INIT([cglm], [0.6.2], [info@recp.me])
|
||||
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.
|
||||
: ${CFLAGS=""}
|
||||
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
AC_CONFIG_SRCDIR([src/])
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
Build cglm
|
||||
================================
|
||||
|
||||
| **cglm** does not have external dependencies except for unit testing. When you pulled **cglm** repo with submodules all dependencies will be pulled too. `build-deps.sh` will pull all dependencies/submodules and build for you.
|
||||
|
||||
External dependencies:
|
||||
* cmocka - for unit testing
|
||||
| **cglm** does not have any external dependencies.
|
||||
|
||||
**NOTE:**
|
||||
If you only need to inline versions, you don't need to build **cglm**, you don't need to link it to your program.
|
||||
@@ -16,8 +13,6 @@ Unix (Autotools):
|
||||
.. code-block:: bash
|
||||
:linenos:
|
||||
|
||||
$ sh ./build-deps.sh # run this only once (dependencies)
|
||||
|
||||
$ sh autogen.sh
|
||||
$ ./configure
|
||||
$ make
|
||||
@@ -65,4 +60,3 @@ Example build:
|
||||
|
||||
$ cd cglm/docs
|
||||
$ sphinx-build source build
|
||||
|
||||
|
||||
@@ -62,9 +62,9 @@ author = u'Recep Aslantas'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'0.6.0'
|
||||
version = u'0.6.2'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'0.6.0'
|
||||
release = u'0.6.2'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
||||
@@ -57,6 +57,13 @@ For instance you may called **glm_vec4_** functions for **vec3** data type.
|
||||
It will try to write 32 byte but since **vec3** is 24 byte it should throw
|
||||
memory access error or exit the app without saying anything.
|
||||
|
||||
**UPDATE - IMPORTANT:**
|
||||
|
||||
| On MSVC or some other compilers, if alignment is enabled (default) then double check alignment requirements if you got a crash.
|
||||
|
||||
| If you send GLM_VEC4_ONE or similar macros directly to a function, it may be crashed.
|
||||
| Because compiler may not apply alignment as defined on **typedef** to that macro while passing it (on stack) to a function.
|
||||
|
||||
Wrong Results:
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
95
include/cglm/applesimd.h
Normal file
95
include/cglm/applesimd.h
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#ifndef cglm_applesimd_h
|
||||
#define cglm_applesimd_h
|
||||
#if defined(__APPLE__) \
|
||||
&& defined(SIMD_COMPILER_HAS_REQUIRED_FEATURES) \
|
||||
&& defined(SIMD_BASE) \
|
||||
&& defined(SIMD_TYPES) \
|
||||
&& defined(SIMD_VECTOR_TYPES)
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/*!
|
||||
* @brief converts mat4 to Apple's simd type simd_float4x4
|
||||
* @return simd_float4x4
|
||||
*/
|
||||
CGLM_INLINE
|
||||
simd_float4x4
|
||||
glm_mat4_applesimd(mat4 m) {
|
||||
simd_float4x4 t;
|
||||
|
||||
t.columns[0][0] = m[0][0];
|
||||
t.columns[0][1] = m[0][1];
|
||||
t.columns[0][2] = m[0][2];
|
||||
t.columns[0][3] = m[0][3];
|
||||
|
||||
t.columns[1][0] = m[1][0];
|
||||
t.columns[1][1] = m[1][1];
|
||||
t.columns[1][2] = m[1][2];
|
||||
t.columns[1][3] = m[1][3];
|
||||
|
||||
t.columns[2][0] = m[2][0];
|
||||
t.columns[2][1] = m[2][1];
|
||||
t.columns[2][2] = m[2][2];
|
||||
t.columns[2][3] = m[2][3];
|
||||
|
||||
t.columns[3][0] = m[3][0];
|
||||
t.columns[3][1] = m[3][1];
|
||||
t.columns[3][2] = m[3][2];
|
||||
t.columns[3][3] = m[3][3];
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief converts mat3 to Apple's simd type simd_float3x3
|
||||
* @return simd_float3x3
|
||||
*/
|
||||
CGLM_INLINE
|
||||
simd_float3x3
|
||||
glm_mat3_applesimd(mat3 m) {
|
||||
simd_float3x3 t;
|
||||
|
||||
t.columns[0][0] = m[0][0];
|
||||
t.columns[0][1] = m[0][1];
|
||||
t.columns[0][2] = m[0][2];
|
||||
|
||||
t.columns[1][0] = m[1][0];
|
||||
t.columns[1][1] = m[1][1];
|
||||
t.columns[1][2] = m[1][2];
|
||||
|
||||
t.columns[2][0] = m[2][0];
|
||||
t.columns[2][1] = m[2][1];
|
||||
t.columns[2][2] = m[2][2];
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief converts vec4 to Apple's simd type simd_float4
|
||||
* @return simd_float4
|
||||
*/
|
||||
CGLM_INLINE
|
||||
simd_float4
|
||||
glm_vec4_applesimd(vec4 v) {
|
||||
return (simd_float4){v[0], v[1], v[2], v[3]};
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief converts vec3 to Apple's simd type simd_float3
|
||||
* @return v
|
||||
*/
|
||||
CGLM_INLINE
|
||||
simd_float3
|
||||
glm_vec3_applesimd(vec3 v) {
|
||||
return (simd_float3){v[0], v[1], v[2]};
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* cglm_applesimd_h */
|
||||
@@ -22,9 +22,9 @@
|
||||
#define GLM_BEZIER_MAT ((mat4)GLM_BEZIER_MAT_INIT)
|
||||
#define GLM_HERMITE_MAT ((mat4)GLM_HERMITE_MAT_INIT)
|
||||
|
||||
#define CGLM_DECASTEL_EPS 1e-9
|
||||
#define CGLM_DECASTEL_MAX 1000
|
||||
#define CGLM_DECASTEL_SMALL 1e-20
|
||||
#define CGLM_DECASTEL_EPS 1e-9f
|
||||
#define CGLM_DECASTEL_MAX 1000.0f
|
||||
#define CGLM_DECASTEL_SMALL 1e-20f
|
||||
|
||||
/*!
|
||||
* @brief cubic bezier interpolation
|
||||
|
||||
@@ -24,6 +24,10 @@ CGLM_EXPORT
|
||||
void
|
||||
glmc_mat3_identity(mat3 mat);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat3_zero(mat3 mat);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat3_identity_array(mat3 * __restrict mat, size_t count);
|
||||
|
||||
@@ -33,6 +33,10 @@ CGLM_EXPORT
|
||||
void
|
||||
glmc_mat4_identity_array(mat4 * __restrict mat, size_t count);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat4_zero(mat4 mat);
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat4_pick3(mat4 mat, mat3 dest);
|
||||
|
||||
@@ -446,6 +446,9 @@ glm_mat4_quat(mat4 m, versor dest) {
|
||||
/*!
|
||||
* @brief multiply vector with mat4
|
||||
*
|
||||
* actually the result is vec4, after multiplication the last component
|
||||
* is trimmed. if you need it don't use this func.
|
||||
*
|
||||
* @param[in] m mat4(affine transform)
|
||||
* @param[in] v vec3
|
||||
* @param[in] last 4th item to make it vec4
|
||||
|
||||
@@ -34,17 +34,19 @@ glmm_hadd(float32x4_t v) {
|
||||
static inline
|
||||
float
|
||||
glmm_hmin(float32x4_t v) {
|
||||
v = vpmin_f32(vget_low_f32(v), vget_high_f32(v));
|
||||
v = vpmin_f32(v, v);
|
||||
return vget_lane_f32(v, 0);
|
||||
float32x2_t t;
|
||||
t = vpmin_f32(vget_low_f32(v), vget_high_f32(v));
|
||||
t = vpmin_f32(t, t);
|
||||
return vget_lane_f32(t, 0);
|
||||
}
|
||||
|
||||
static inline
|
||||
float
|
||||
glmm_hmax(float32x4_t v) {
|
||||
v = vpmax_f32(vget_low_f32(v), vget_high_f32(v));
|
||||
v = vpmax_f32(v, v);
|
||||
return vget_lane_f32(v, 0);
|
||||
float32x2_t t;
|
||||
t = vpmax_f32(vget_low_f32(v), vget_high_f32(v));
|
||||
t = vpmax_f32(t, t);
|
||||
return vget_lane_f32(t, 0);
|
||||
}
|
||||
|
||||
static inline
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
CGLM_INLINE mat4s glms_scale_make(vec3s v);
|
||||
CGLM_INLINE mat4s glms_scale(mat4s m, vec3s v);
|
||||
CGLM_INLINE mat4s glms_scale_uni(mat4s m, float s);
|
||||
CGLM_INLINE mat4s glmx_rotate_x(mat4s m, float angle);
|
||||
CGLM_INLINE mat4s glms_rotate_x(mat4s m, float angle);
|
||||
CGLM_INLINE mat4s glms_rotate_y(mat4s m, float angle);
|
||||
CGLM_INLINE mat4s glms_rotate_z(mat4s m, float angle);
|
||||
CGLM_INLINE mat4s glms_rotate_make(float angle, vec3s axis);
|
||||
@@ -169,7 +169,7 @@ glms_scale_uni(mat4s m, float s) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat4s
|
||||
glmx_rotate_x(mat4s m, float angle) {
|
||||
glms_rotate_x(mat4s m, float angle) {
|
||||
mat4s r;
|
||||
glm_rotate_x(m.raw, angle, r.raw);
|
||||
return r;
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
|
||||
Functions:
|
||||
CGLM_INLINE mat3s glms_mat3_copy(mat3s mat);
|
||||
CGLM_INLINE mat3s glms_mat3_identity();
|
||||
CGLM_INLINE mat3s glms_mat3_identity(void);
|
||||
CGLM_INLINE void glms_mat3_identity_array(mat3s * __restrict mat, size_t count);
|
||||
CGLM_INLINE mat3s glms_mat3_zero();
|
||||
CGLM_INLINE mat3s glms_mat3_zero(void);
|
||||
CGLM_INLINE mat3s glms_mat3_mul(mat3s m1, mat3s m2);
|
||||
CGLM_INLINE ma3s glms_mat3_transpose(mat3s m);
|
||||
CGLM_INLINE vec3s glms_mat3_mulv(mat3s m, vec3s v);
|
||||
@@ -38,12 +38,8 @@
|
||||
#include "../mat3.h"
|
||||
#include "vec3.h"
|
||||
|
||||
#define GLMS_MAT3_IDENTITY_INIT {1.0f, 0.0f, 0.0f, \
|
||||
0.0f, 1.0f, 0.0f, \
|
||||
0.0f, 0.0f, 1.0f}
|
||||
#define GLMS_MAT3_ZERO_INIT {0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f}
|
||||
#define GLMS_MAT3_IDENTITY_INIT {GLM_MAT3_IDENTITY_INIT}
|
||||
#define GLMS_MAT3_ZERO_INIT {GLM_MAT3_ZERO_INIT}
|
||||
|
||||
/* for C only */
|
||||
#define GLMS_MAT3_IDENTITY ((mat3s)GLMS_MAT3_IDENTITY_INIT)
|
||||
@@ -79,7 +75,7 @@ glms_mat3_copy(mat3s mat) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat3s
|
||||
glms_mat3_identity() {
|
||||
glms_mat3_identity(void) {
|
||||
mat3s r;
|
||||
glm_mat3_identity(r.raw);
|
||||
return r;
|
||||
@@ -111,7 +107,7 @@ glms_mat3_identity_array(mat3s * __restrict mat, size_t count) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat3s
|
||||
glms_mat3_zero() {
|
||||
glms_mat3_zero(void) {
|
||||
mat3s r;
|
||||
glm_mat3_zero(r.raw);
|
||||
return r;
|
||||
|
||||
@@ -20,9 +20,9 @@
|
||||
Functions:
|
||||
CGLM_INLINE mat4s glms_mat4_ucopy(mat4s mat);
|
||||
CGLM_INLINE mat4s glms_mat4_copy(mat4s mat);
|
||||
CGLM_INLINE mat4s glms_mat4_identity();
|
||||
CGLM_INLINE mat4s glms_mat4_identity(void);
|
||||
CGLM_INLINE void glms_mat4_identity_array(mat4s * __restrict mat, size_t count);
|
||||
CGLM_INLINE mat4s glms_mat4_zero();
|
||||
CGLM_INLINE mat4s glms_mat4_zero(void);
|
||||
CGLM_INLINE mat3s glms_mat4_pick3(mat4s mat);
|
||||
CGLM_INLINE mat3s glms_mat4_pick3t(mat4s mat);
|
||||
CGLM_INLINE mat4s glms_mat4_ins3(mat3s mat);
|
||||
@@ -53,15 +53,8 @@
|
||||
#include "vec4.h"
|
||||
#include "vec3.h"
|
||||
|
||||
#define GLMS_MAT4_IDENTITY_INIT {1.0f, 0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 1.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 1.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f, 1.0f}
|
||||
|
||||
#define GLMS_MAT4_ZERO_INIT {0.0f, 0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f, 0.0f, \
|
||||
0.0f, 0.0f, 0.0f, 0.0f}
|
||||
#define GLMS_MAT4_IDENTITY_INIT {GLM_MAT4_IDENTITY_INIT}
|
||||
#define GLMS_MAT4_ZERO_INIT {GLM_MAT4_ZERO_INIT}
|
||||
|
||||
/* for C only */
|
||||
#define GLMS_MAT4_IDENTITY ((mat4s)GLMS_MAT4_IDENTITY_INIT)
|
||||
@@ -114,7 +107,7 @@ glms_mat4_copy(mat4s mat) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat4s
|
||||
glms_mat4_identity() {
|
||||
glms_mat4_identity(void) {
|
||||
mat4s r;
|
||||
glm_mat4_identity(r.raw);
|
||||
return r;
|
||||
@@ -146,7 +139,7 @@ glms_mat4_identity_array(mat4s * __restrict mat, size_t count) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
mat4s
|
||||
glms_mat4_zero() {
|
||||
glms_mat4_zero(void) {
|
||||
mat4s r;
|
||||
glm_mat4_zero(r.raw);
|
||||
return r;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
GLMS_QUAT_IDENTITY
|
||||
|
||||
Functions:
|
||||
CGLM_INLINE versors glms_quat_identity()
|
||||
CGLM_INLINE versors glms_quat_identity(void)
|
||||
CGLM_INLINE void glms_quat_identity_array(versor *q, size_t count)
|
||||
CGLM_INLINE versors glms_quat_init(float x, float y, float z, float w)
|
||||
CGLM_INLINE versors glms_quatv(float angle, vec3s axis)
|
||||
@@ -62,7 +62,7 @@
|
||||
* ----------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#define GLMS_QUAT_IDENTITY_INIT GLM_QUAT_IDENTITY_INIT
|
||||
#define GLMS_QUAT_IDENTITY_INIT {GLM_QUAT_IDENTITY_INIT}
|
||||
#define GLMS_QUAT_IDENTITY ((versors)GLMS_QUAT_IDENTITY_INIT)
|
||||
|
||||
/*!
|
||||
@@ -72,7 +72,7 @@
|
||||
*/
|
||||
CGLM_INLINE
|
||||
versors
|
||||
glms_quat_identity() {
|
||||
glms_quat_identity(void) {
|
||||
versors dest;
|
||||
glm_quat_identity(dest.raw);
|
||||
return dest;
|
||||
@@ -251,7 +251,7 @@ CGLM_INLINE
|
||||
vec3s
|
||||
glms_quat_imagn(versors q) {
|
||||
vec3s dest;
|
||||
glm_normalize_to(q.imag.raw, dest.raw);
|
||||
glm_normalize_to(q.raw, dest.raw);
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
CGLM_INLINE vec3s glms_vec3(vec4s v4);
|
||||
CGLM_INLINE void glms_vec3_pack(vec3s dst[], vec3 src[], size_t len);
|
||||
CGLM_INLINE void glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len);
|
||||
CGLM_INLINE vec3s glms_vec3_zero();
|
||||
CGLM_INLINE vec3s glms_vec3_one();
|
||||
CGLM_INLINE vec3s glms_vec3_zero(void);
|
||||
CGLM_INLINE vec3s glms_vec3_one(void);
|
||||
CGLM_INLINE float glms_vec3_dot(vec3s a, vec3s b);
|
||||
CGLM_INLINE float glms_vec3_norm2(vec3s v);
|
||||
CGLM_INLINE float glms_vec3_norm(vec3s v);
|
||||
@@ -86,15 +86,15 @@
|
||||
#include "../vec3.h"
|
||||
#include "vec3-ext.h"
|
||||
|
||||
#define GLMS_VEC3_ONE_INIT {1.0f, 1.0f, 1.0f}
|
||||
#define GLMS_VEC3_ZERO_INIT {0.0f, 0.0f, 0.0f}
|
||||
#define GLMS_VEC3_ONE_INIT {GLM_VEC3_ONE_INIT}
|
||||
#define GLMS_VEC3_ZERO_INIT {GLM_VEC3_ZERO_INIT}
|
||||
|
||||
#define GLMS_VEC3_ONE ((vec3s)GLMS_VEC3_ONE_INIT)
|
||||
#define GLMS_VEC3_ZERO ((vec3s)GLMS_VEC3_ZERO_INIT)
|
||||
|
||||
#define GLMS_YUP ((vec3s){0.0f, 1.0f, 0.0f})
|
||||
#define GLMS_ZUP ((vec3s){0.0f, 0.0f, 1.0f})
|
||||
#define GLMS_XUP ((vec3s){1.0f, 0.0f, 0.0f})
|
||||
#define GLMS_YUP ((vec3s){{0.0f, 1.0f, 0.0f}})
|
||||
#define GLMS_ZUP ((vec3s){{0.0f, 0.0f, 1.0f}})
|
||||
#define GLMS_XUP ((vec3s){{1.0f, 0.0f, 0.0f}})
|
||||
|
||||
/*!
|
||||
* @brief init vec3 using vec4
|
||||
@@ -151,7 +151,7 @@ glms_vec3_unpack(vec3 dst[], vec3s src[], size_t len) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec3s
|
||||
glms_vec3_zero() {
|
||||
glms_vec3_zero(void) {
|
||||
vec3s r;
|
||||
glm_vec3_zero(r.raw);
|
||||
return r;
|
||||
@@ -164,7 +164,7 @@ glms_vec3_zero() {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec3s
|
||||
glms_vec3_one() {
|
||||
glms_vec3_one(void) {
|
||||
vec3s r;
|
||||
glm_vec3_one(r.raw);
|
||||
return r;
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
/*
|
||||
Macros:
|
||||
GLM_VEC4_ONE_INIT
|
||||
GLM_VEC4_BLACK_INIT
|
||||
GLM_VEC4_ZERO_INIT
|
||||
GLM_VEC4_ONE
|
||||
GLM_VEC4_BLACK
|
||||
GLM_VEC4_ZERO
|
||||
GLMS_VEC4_ONE_INIT
|
||||
GLMS_VEC4_BLACK_INIT
|
||||
GLMS_VEC4_ZERO_INIT
|
||||
GLMS_VEC4_ONE
|
||||
GLMS_VEC4_BLACK
|
||||
GLMS_VEC4_ZERO
|
||||
|
||||
Functions:
|
||||
CGLM_INLINE vec4s glms_vec4(vec3s v3, float last);
|
||||
@@ -72,9 +72,9 @@
|
||||
#include "../vec4.h"
|
||||
#include "vec4-ext.h"
|
||||
|
||||
#define GLMS_VEC4_ONE_INIT {1.0f, 1.0f, 1.0f, 1.0f}
|
||||
#define GLMS_VEC4_BLACK_INIT {0.0f, 0.0f, 0.0f, 1.0f}
|
||||
#define GLMS_VEC4_ZERO_INIT {0.0f, 0.0f, 0.0f, 0.0f}
|
||||
#define GLMS_VEC4_ONE_INIT {GLM_VEC4_ONE_INIT}
|
||||
#define GLMS_VEC4_BLACK_INIT {GLM_VEC4_BLACK_INIT}
|
||||
#define GLMS_VEC4_ZERO_INIT {GLM_VEC4_ZERO_INIT}
|
||||
|
||||
#define GLMS_VEC4_ONE ((vec4s)GLM_VEC4_ONE_INIT)
|
||||
#define GLMS_VEC4_BLACK ((vec4s)GLM_VEC4_BLACK_INIT)
|
||||
@@ -180,7 +180,7 @@ glms_vec4_unpack(vec4 dst[], vec4s src[], size_t len) {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec4s
|
||||
glms_vec4_zero() {
|
||||
glms_vec4_zero(void) {
|
||||
vec4s r;
|
||||
glm_vec4_zero(r.raw);
|
||||
return r;
|
||||
@@ -193,7 +193,7 @@ glms_vec4_zero() {
|
||||
*/
|
||||
CGLM_INLINE
|
||||
vec4s
|
||||
glms_vec4_one() {
|
||||
glms_vec4_one(void) {
|
||||
vec4s r;
|
||||
glm_vec4_one(r.raw);
|
||||
return r;
|
||||
|
||||
@@ -10,30 +10,71 @@
|
||||
|
||||
#include "types.h"
|
||||
|
||||
/*
|
||||
* Anonymous structs are available since C11, but we'd like to be compatible
|
||||
* with C99 and C89 too. So let's figure out if we should be using them or not.
|
||||
* It's simply a convenience feature, you can e.g. build the library with
|
||||
* anonymous structs and your application without them and they'll still be
|
||||
* compatible, cglm doesn't use the anonymous structs internally.
|
||||
*/
|
||||
#ifndef CGLM_USE_ANONYMOUS_STRUCT
|
||||
/* If the user doesn't explicitly specify if they want anonymous structs or
|
||||
* not, then we'll try to intuit an appropriate choice. */
|
||||
# if defined(CGLM_NO_ANONYMOUS_STRUCT)
|
||||
/* The user has defined CGLM_NO_ANONYMOUS_STRUCT. This used to be the
|
||||
* only #define governing the use of anonymous structs, so for backward
|
||||
* compatibility, we still honor that choice and disable them. */
|
||||
# define CGLM_USE_ANONYMOUS_STRUCT 0
|
||||
# elif __STDC_VERSION__ >= 20112L || defined(_MSVC_VER)
|
||||
/* We're compiling for C11 or this is the MSVC compiler. In either
|
||||
* case, anonymous structs are available, so use them. */
|
||||
# define CGLM_USE_ANONYMOUS_STRUCT 1
|
||||
# elif defined(_MSC_VER) && (_MSC_VER >= 1900) /* Visual Studio 2015 */
|
||||
/* We can support anonymous structs
|
||||
* since Visual Studio 2015 or 2017 (1910) maybe? */
|
||||
# define CGLM_USE_ANONYMOUS_STRUCT 1
|
||||
# else
|
||||
/* Otherwise, we're presumably building for C99 or C89 and can't rely
|
||||
* on anonymous structs being available. Turn them off. */
|
||||
# define CGLM_USE_ANONYMOUS_STRUCT 0
|
||||
# endif
|
||||
#endif
|
||||
|
||||
typedef union vec2s {
|
||||
vec2 raw;
|
||||
#if CGLM_USE_ANONYMOUS_STRUCT
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
};
|
||||
#endif
|
||||
} vec2s;
|
||||
|
||||
typedef union vec3s {
|
||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
||||
vec3 raw;
|
||||
#if CGLM_USE_ANONYMOUS_STRUCT
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
float z;
|
||||
};
|
||||
#endif
|
||||
vec3 raw;
|
||||
} vec3s;
|
||||
|
||||
typedef union ivec3s {
|
||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
||||
ivec3 raw;
|
||||
#if CGLM_USE_ANONYMOUS_STRUCT
|
||||
struct {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
};
|
||||
#endif
|
||||
ivec3 raw;
|
||||
} ivec3s;
|
||||
|
||||
typedef union CGLM_ALIGN_IF(16) vec4s {
|
||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
||||
vec4 raw;
|
||||
#if CGLM_USE_ANONYMOUS_STRUCT
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
@@ -41,11 +82,11 @@ typedef union CGLM_ALIGN_IF(16) vec4s {
|
||||
float w;
|
||||
};
|
||||
#endif
|
||||
vec4 raw;
|
||||
} vec4s;
|
||||
|
||||
typedef union CGLM_ALIGN_IF(16) versors {
|
||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
||||
vec4 raw;
|
||||
#if CGLM_USE_ANONYMOUS_STRUCT
|
||||
struct {
|
||||
float x;
|
||||
float y;
|
||||
@@ -58,23 +99,24 @@ typedef union CGLM_ALIGN_IF(16) versors {
|
||||
float real;
|
||||
};
|
||||
#endif
|
||||
vec4 raw;
|
||||
} versors;
|
||||
|
||||
typedef union mat3s {
|
||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
||||
mat3 raw;
|
||||
vec3s col[3];
|
||||
#if CGLM_USE_ANONYMOUS_STRUCT
|
||||
struct {
|
||||
float m00, m01, m02;
|
||||
float m10, m11, m12;
|
||||
float m20, m21, m22;
|
||||
};
|
||||
#endif
|
||||
vec3s col[3];
|
||||
mat3 raw;
|
||||
} mat3s;
|
||||
|
||||
typedef union CGLM_ALIGN_MAT mat4s {
|
||||
#ifndef CGLM_NO_ANONYMOUS_STRUCT
|
||||
mat4 raw;
|
||||
vec4s col[4];
|
||||
#if CGLM_USE_ANONYMOUS_STRUCT
|
||||
struct {
|
||||
float m00, m01, m02, m03;
|
||||
float m10, m11, m12, m13;
|
||||
@@ -82,8 +124,6 @@ typedef union CGLM_ALIGN_MAT mat4s {
|
||||
float m30, m31, m32, m33;
|
||||
};
|
||||
#endif
|
||||
vec4s col[4];
|
||||
mat4 raw;
|
||||
} mat4s;
|
||||
|
||||
#endif /* cglm_types_struct_h */
|
||||
|
||||
@@ -996,6 +996,27 @@ glm_vec3_smoothinterpc(vec3 from, vec3 to, float t, vec3 dest) {
|
||||
glm_vec3_smoothinterp(from, to, glm_clamp_zo(t), dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swizzle vector components
|
||||
*
|
||||
* you can use existin masks e.g. GLM_XXX, GLM_ZYX
|
||||
*
|
||||
* @param[in] v source
|
||||
* @param[in] mask mask
|
||||
* @param[out] dest destination
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec3_swizzle(vec3 v, int mask, vec3 dest) {
|
||||
vec3 t;
|
||||
|
||||
t[0] = v[(mask & (3 << 0))];
|
||||
t[1] = v[(mask & (3 << 2)) >> 2];
|
||||
t[2] = v[(mask & (3 << 4)) >> 4];
|
||||
|
||||
glm_vec3_copy(t, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief vec3 cross product
|
||||
*
|
||||
@@ -1054,25 +1075,4 @@ glm_normalize_to(vec3 v, vec3 dest) {
|
||||
glm_vec3_normalize_to(v, dest);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief swizzle vector components
|
||||
*
|
||||
* you can use existin masks e.g. GLM_XXX, GLM_ZYX
|
||||
*
|
||||
* @param[in] v source
|
||||
* @param[in] mask mask
|
||||
* @param[out] dest destination
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_vec3_swizzle(vec3 v, int mask, vec3 dest) {
|
||||
vec3 t;
|
||||
|
||||
t[0] = v[(mask & (3 << 0))];
|
||||
t[1] = v[(mask & (3 << 2)) >> 2];
|
||||
t[2] = v[(mask & (3 << 4)) >> 4];
|
||||
|
||||
glm_vec3_copy(t, dest);
|
||||
}
|
||||
|
||||
#endif /* cglm_vec3_h */
|
||||
|
||||
@@ -252,7 +252,7 @@ glm_vec4_abs(vec4 v, vec4 dest) {
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
glmm_store(dest, glmm_abs(glmm_load(v)));
|
||||
#elif defined(CGLM_NEON_FP)
|
||||
vst1q_f32(dest, vabsq_f32(vld1q_f32(a)));
|
||||
vst1q_f32(dest, vabsq_f32(vld1q_f32(v)));
|
||||
#else
|
||||
dest[0] = fabsf(v[0]);
|
||||
dest[1] = fabsf(v[1]);
|
||||
|
||||
@@ -10,6 +10,6 @@
|
||||
|
||||
#define CGLM_VERSION_MAJOR 0
|
||||
#define CGLM_VERSION_MINOR 6
|
||||
#define CGLM_VERSION_PATCH 0
|
||||
#define CGLM_VERSION_PATCH 2
|
||||
|
||||
#endif /* cglm_version_h */
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# Copyright (c), Recep Aslantas.
|
||||
#
|
||||
# MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
# Full license can be found in the LICENSE file
|
||||
#
|
||||
|
||||
cd $(dirname "$0")
|
||||
|
||||
mkdir -p "$(pwd)/.libs"
|
||||
|
||||
libmocka_folder=$(pwd)/test/lib/cmocka/build/src/
|
||||
|
||||
if [ "$(uname)" = "Darwin" ]; then
|
||||
libcmocka=libcmocka.0.dylib
|
||||
else
|
||||
libcmocka=libcmocka.so.0
|
||||
fi
|
||||
|
||||
libcmocka_path="$libmocka_folder$libcmocka"
|
||||
if [ -f "$libcmocka_path" ]; then
|
||||
ln -sf "$libcmocka_path" "$(pwd)/.libs/$libcmocka";
|
||||
fi
|
||||
@@ -20,6 +20,12 @@ glmc_mat3_identity(mat3 mat) {
|
||||
glm_mat3_identity(mat);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat3_zero(mat3 mat) {
|
||||
glm_mat3_zero(mat);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat3_identity_array(mat3 * __restrict mat, size_t count) {
|
||||
|
||||
@@ -32,6 +32,12 @@ glmc_mat4_identity_array(mat4 * __restrict mat, size_t count) {
|
||||
glm_mat4_identity_array(mat, count);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat4_zero(mat4 mat) {
|
||||
glm_mat4_zero(mat);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_mat4_pick3(mat4 mat, mat3 dest) {
|
||||
|
||||
@@ -59,7 +59,7 @@ glmc_quat_normalize_to(versor q, versor dest) {
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_quat_normalize(versor q) {
|
||||
glm_quat_norm(q);
|
||||
glm_quat_normalize(q);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
|
||||
@@ -239,13 +239,13 @@ glmc_vec3_distance2(vec3 a, vec3 b) {
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_maxv(vec3 a, vec3 b, vec3 dest) {
|
||||
glm_vec3_minv(a, b, dest);
|
||||
glm_vec3_maxv(a, b, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec3_minv(vec3 a, vec3 b, vec3 dest) {
|
||||
glm_vec3_maxv(a, b, dest);
|
||||
glm_vec3_minv(a, b, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
|
||||
@@ -203,13 +203,13 @@ glmc_vec4_distance2(vec4 a, vec4 b) {
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec4_maxv(vec4 a, vec4 b, vec4 dest) {
|
||||
glm_vec4_minv(a, b, dest);
|
||||
glm_vec4_maxv(a, b, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
void
|
||||
glmc_vec4_minv(vec4 a, vec4 b, vec4 dest) {
|
||||
glm_vec4_maxv(a, b, dest);
|
||||
glm_vec4_minv(a, b, dest);
|
||||
}
|
||||
|
||||
CGLM_EXPORT
|
||||
|
||||
119
test/include/common.h
Normal file
119
test/include/common.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#ifndef tests_common_h
|
||||
#define tests_common_h
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <cglm/cglm.h>
|
||||
#include <cglm/struct.h>
|
||||
#include <cglm/call.h>
|
||||
|
||||
typedef struct test_status_t {
|
||||
const char *msg;
|
||||
int status;
|
||||
} test_status_t;
|
||||
|
||||
typedef test_status_t (*fntest)(void);
|
||||
|
||||
typedef struct test_entry_t {
|
||||
char *name;
|
||||
fntest entry;
|
||||
int ret;
|
||||
int show_output;
|
||||
} test_entry_t;
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define BLACK "\033[30m" /* Black */
|
||||
#define RED "\033[31m" /* Red */
|
||||
#define GREEN "\033[32m" /* Green */
|
||||
#define YELLOW "\033[33m" /* Yellow */
|
||||
#define BLUE "\033[34m" /* Blue */
|
||||
#define MAGENTA "\033[35m" /* Magenta */
|
||||
#define CYAN "\033[36m" /* Cyan */
|
||||
#define WHITE "\033[37m" /* White */
|
||||
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
|
||||
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
|
||||
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
|
||||
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
|
||||
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
|
||||
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
|
||||
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
|
||||
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
|
||||
|
||||
#define TEST_DECLARE(FUN) test_status_t test_ ## FUN(void);
|
||||
#define TEST_ENTRY(FUN) { #FUN, test_ ## FUN, 0, 0 },
|
||||
#define TEST_LIST static test_entry_t tests[] =
|
||||
|
||||
/* __VA_ARGS__ workaround for MSVC: https://stackoverflow.com/a/5134656 */
|
||||
#define EXPAND(x) x
|
||||
|
||||
#define TEST_OK 1
|
||||
#define TEST_SUCCESS return (test_status_t){NULL, TEST_OK};
|
||||
|
||||
#define TEST_IMPL_ARG1(FUN) \
|
||||
test_status_t test_ ## FUN (void); \
|
||||
test_status_t test_ ## FUN()
|
||||
|
||||
#define TEST_IMPL_ARG2(PREFIX, FUN) TEST_IMPL_ARG1(PREFIX ## FUN)
|
||||
#define TEST_IMPL_ARG3(arg1, arg2, arg3, ...) arg3
|
||||
|
||||
#define TEST_IMPL_CHOOSER(...) \
|
||||
EXPAND(TEST_IMPL_ARG3(__VA_ARGS__, TEST_IMPL_ARG2, TEST_IMPL_ARG1))
|
||||
|
||||
#define TEST_IMPL(...) EXPAND(TEST_IMPL_CHOOSER(__VA_ARGS__)(__VA_ARGS__))
|
||||
|
||||
#define ASSERT_EXT(expr, msg) \
|
||||
if (!(expr)) { \
|
||||
fprintf(stderr, \
|
||||
RED " assert fail" RESET \
|
||||
" in " BOLDCYAN "%s " RESET \
|
||||
"on " BOLDMAGENTA "line %d" RESET \
|
||||
" : " BOLDWHITE " ASSERT(%s)\n" RESET, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#expr); \
|
||||
return (test_status_t){msg, 0}; \
|
||||
}
|
||||
|
||||
#define ASSERT_ARG1(expr) ASSERT_EXT(expr, NULL)
|
||||
#define ASSERT_ARG2(expr, msg) ASSERT_EXT(expr, msg)
|
||||
#define ASSERT_ARG3(arg1, arg2, arg3, ...) arg3
|
||||
|
||||
#define ASSERT_CHOOSER(...) ASSERT_ARG3(__VA_ARGS__, ASSERT_ARG2, ASSERT_ARG1)
|
||||
#define ASSERT(...) do { ASSERT_CHOOSER(__VA_ARGS__)(__VA_ARGS__) } while(0);
|
||||
#define ASSERTIFY(expr) do { \
|
||||
test_status_t ts; \
|
||||
ts = expr; \
|
||||
if (ts.status != TEST_OK) { \
|
||||
fprintf(stderr, \
|
||||
RED " assert fail" RESET \
|
||||
" in " BOLDCYAN "%s " RESET \
|
||||
"on " BOLDMAGENTA "line %d" RESET \
|
||||
" : " BOLDWHITE " ASSERTIFY(%s)\n" RESET, \
|
||||
__FILE__, \
|
||||
__LINE__, \
|
||||
#expr); \
|
||||
return (test_status_t){ts.msg, 0}; \
|
||||
} \
|
||||
} while(0);
|
||||
|
||||
#if defined(_WIN32)
|
||||
# define drand48() ((float)(rand() / (RAND_MAX + 1.0)))
|
||||
# define OK_TEXT "ok:"
|
||||
# define FAIL_TEXT "fail:"
|
||||
# define FINAL_TEXT "^_^"
|
||||
#else
|
||||
# define OK_TEXT "✔︎"
|
||||
# define FAIL_TEXT "𐄂"
|
||||
# define FINAL_TEXT "🎉"
|
||||
#endif
|
||||
|
||||
#endif /* common_h */
|
||||
Submodule test/lib/cmocka deleted from 5f61d2f188
98
test/runner.c
Normal file
98
test/runner.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "include/common.h"
|
||||
#include "tests.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
|
||||
int
|
||||
main(int argc, const char * argv[]) {
|
||||
test_entry_t *entry;
|
||||
test_status_t st;
|
||||
int32_t i, count, passed, failed, maxlen;
|
||||
double start, end, elapsed, total;
|
||||
|
||||
passed = failed = maxlen = 0;
|
||||
total = 0.0;
|
||||
count = sizeof(tests) / sizeof(tests[0]);
|
||||
|
||||
fprintf(stderr, CYAN "\nWelcome to cglm tests\n\n" RESET);
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
int32_t len;
|
||||
|
||||
entry = tests + i;
|
||||
len = (int32_t)strlen(entry->name);
|
||||
|
||||
maxlen = GLM_MAX(maxlen, len);
|
||||
}
|
||||
|
||||
maxlen += 5;
|
||||
|
||||
fprintf(stderr,
|
||||
BOLDWHITE " %-*s %-*s\n",
|
||||
maxlen, "Test Name", maxlen, "Elapsed Time");
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
entry = tests + i;
|
||||
start = clock();
|
||||
st = entry->entry();
|
||||
end = clock();
|
||||
elapsed = (end - start) / CLOCKS_PER_SEC;
|
||||
total += elapsed;
|
||||
|
||||
if (!st.status) {
|
||||
fprintf(stderr,
|
||||
BOLDRED " " FAIL_TEXT BOLDWHITE " %s " RESET, entry->name);
|
||||
if (st.msg) {
|
||||
fprintf(stderr,
|
||||
YELLOW "- %s" RESET,
|
||||
st.msg);
|
||||
}
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
failed++;
|
||||
} else {
|
||||
fprintf(stderr, GREEN " " OK_TEXT RESET " %-*s ", maxlen, entry->name);
|
||||
|
||||
if (elapsed > 0.01)
|
||||
fprintf(stderr, YELLOW "%.2fs", elapsed);
|
||||
else
|
||||
fprintf(stderr, "0");
|
||||
|
||||
fprintf(stderr, "\n" RESET);
|
||||
passed++;
|
||||
}
|
||||
}
|
||||
|
||||
if (failed == 0) {
|
||||
fprintf(stderr,
|
||||
BOLDGREEN "\n All tests are passed " FINAL_TEXT "\n" RESET);
|
||||
}
|
||||
|
||||
fprintf(stderr,
|
||||
CYAN "\ncglm test results (%0.2fs):\n" RESET
|
||||
"--------------------------\n"
|
||||
|
||||
MAGENTA "%d" RESET " tests are runned, "
|
||||
GREEN "%d" RESET " %s passed, "
|
||||
RED "%d" RESET " %s failed\n\n" RESET,
|
||||
total,
|
||||
count,
|
||||
passed,
|
||||
passed > 1 ? "are" : "is",
|
||||
failed,
|
||||
failed > 1 ? "are" : "is");
|
||||
|
||||
return failed;
|
||||
}
|
||||
@@ -7,8 +7,7 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
void
|
||||
test_affine(void **state) {
|
||||
TEST_IMPL(affine) {
|
||||
mat4 t1, t2, t3, t4, t5;
|
||||
|
||||
/* test translate is postmultiplied */
|
||||
@@ -18,7 +17,7 @@ test_affine(void **state) {
|
||||
glmc_mat4_mul(t1, t2, t3); /* R * T */
|
||||
|
||||
glm_translate(t1, (vec3){34, 57, 36});
|
||||
test_assert_mat4_eq(t1, t3);
|
||||
ASSERTIFY(test_assert_mat4_eq(t1, t3))
|
||||
|
||||
/* test rotate is postmultiplied */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
|
||||
@@ -27,7 +26,7 @@ test_affine(void **state) {
|
||||
glmc_mat4_mul(t2, t1, t3); /* T * R */
|
||||
|
||||
glm_rotate(t2, GLM_PI_4f, GLM_YUP);
|
||||
test_assert_mat4_eq(t2, t3);
|
||||
ASSERTIFY(test_assert_mat4_eq(t2, t3))
|
||||
|
||||
/* test scale is postmultiplied */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
|
||||
@@ -38,7 +37,7 @@ test_affine(void **state) {
|
||||
glmc_mat4_mul(t3, t4, t5); /* T * R * S */
|
||||
|
||||
glm_scale(t3, (vec3){3, 5, 6});
|
||||
test_assert_mat4_eq(t3, t5);
|
||||
ASSERTIFY(test_assert_mat4_eq(t3, t5))
|
||||
|
||||
/* test translate_x */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
|
||||
@@ -46,7 +45,7 @@ test_affine(void **state) {
|
||||
|
||||
glmc_mat4_mul(t1, t2, t3); /* R * T */
|
||||
glm_translate_x(t1, 34);
|
||||
test_assert_mat4_eq(t1, t3);
|
||||
ASSERTIFY(test_assert_mat4_eq(t1, t3))
|
||||
|
||||
/* test translate_y */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
|
||||
@@ -54,7 +53,7 @@ test_affine(void **state) {
|
||||
|
||||
glmc_mat4_mul(t1, t2, t3); /* R * T */
|
||||
glm_translate_y(t1, 57);
|
||||
test_assert_mat4_eq(t1, t3);
|
||||
ASSERTIFY(test_assert_mat4_eq(t1, t3))
|
||||
|
||||
/* test translate_z */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
|
||||
@@ -62,7 +61,7 @@ test_affine(void **state) {
|
||||
|
||||
glmc_mat4_mul(t1, t2, t3); /* R * T */
|
||||
glm_translate_z(t1, 36);
|
||||
test_assert_mat4_eq(t1, t3);
|
||||
ASSERTIFY(test_assert_mat4_eq(t1, t3))
|
||||
|
||||
/* test rotate_x */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, (vec3){1, 0, 0});
|
||||
@@ -71,7 +70,7 @@ test_affine(void **state) {
|
||||
glmc_mat4_mul(t2, t1, t3); /* T * R */
|
||||
|
||||
glm_rotate_x(t2, GLM_PI_4f, t2);
|
||||
test_assert_mat4_eq(t2, t3);
|
||||
ASSERTIFY(test_assert_mat4_eq(t2, t3))
|
||||
|
||||
/* test rotate_y */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 1, 0});
|
||||
@@ -80,7 +79,7 @@ test_affine(void **state) {
|
||||
glmc_mat4_mul(t2, t1, t3); /* T * R */
|
||||
|
||||
glm_rotate_y(t2, GLM_PI_4f, t2);
|
||||
test_assert_mat4_eq(t2, t3);
|
||||
ASSERTIFY(test_assert_mat4_eq(t2, t3))
|
||||
|
||||
/* test rotate_z */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1});
|
||||
@@ -89,7 +88,7 @@ test_affine(void **state) {
|
||||
glmc_mat4_mul(t2, t1, t3); /* T * R */
|
||||
|
||||
glm_rotate_z(t2, GLM_PI_4f, t2);
|
||||
test_assert_mat4_eq(t2, t3);
|
||||
ASSERTIFY(test_assert_mat4_eq(t2, t3))
|
||||
|
||||
/* test rotate */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, (vec3){0, 0, 1});
|
||||
@@ -98,7 +97,7 @@ test_affine(void **state) {
|
||||
glmc_mat4_mul(t2, t1, t3); /* T * R */
|
||||
glmc_rotate(t2, GLM_PI_4f, (vec3){0, 0, 1});
|
||||
|
||||
test_assert_mat4_eq(t3, t2);
|
||||
ASSERTIFY(test_assert_mat4_eq(t3, t2))
|
||||
|
||||
/* test scale_uni */
|
||||
glmc_rotate_make(t1, GLM_PI_4f, GLM_YUP);
|
||||
@@ -109,5 +108,7 @@ test_affine(void **state) {
|
||||
glmc_mat4_mul(t3, t4, t5); /* T * R * S */
|
||||
|
||||
glm_scale_uni(t3, 3);
|
||||
test_assert_mat4_eq(t3, t5);
|
||||
ASSERTIFY(test_assert_mat4_eq(t3, t5))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ test_hermite_plain(float s, float p0, float t0, float t1, float p1) {
|
||||
+ t1 * (sss - ss);
|
||||
}
|
||||
|
||||
void
|
||||
test_bezier(void **state) {
|
||||
TEST_IMPL(bezier) {
|
||||
float s, p0, p1, c0, c1, smc, Bs, Bs_plain;
|
||||
|
||||
s = test_rand();
|
||||
@@ -50,16 +49,18 @@ test_bezier(void **state) {
|
||||
Bs = glm_bezier(s, p0, c0, c1, p1);
|
||||
Bs_plain = test_bezier_plain(s, p0, c0, c1, p1);
|
||||
|
||||
assert_true(glm_eq(Bs, Bs_plain));
|
||||
test_assert_eqf(smc, Bs_plain);
|
||||
test_assert_eqf(Bs, smc);
|
||||
ASSERT(test_eq(Bs, Bs_plain));
|
||||
ASSERTIFY(test_assert_eqf(smc, Bs_plain))
|
||||
ASSERTIFY(test_assert_eqf(Bs, smc))
|
||||
|
||||
/* test cubic hermite */
|
||||
smc = glm_smc(s, GLM_HERMITE_MAT, (vec4){p0, p1, c0, c1});
|
||||
Bs = glm_hermite(s, p0, c0, c1, p1);
|
||||
Bs_plain = test_hermite_plain(s, p0, c0, c1, p1);
|
||||
|
||||
assert_true(glm_eq(Bs, Bs_plain));
|
||||
assert_true(glm_eq(smc, Bs_plain));
|
||||
assert_true(glm_eq(Bs, smc));
|
||||
ASSERT(test_eq(Bs, Bs_plain));
|
||||
ASSERT(test_eq(smc, Bs_plain));
|
||||
ASSERT(test_eq(Bs, smc));
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -7,25 +7,24 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
void
|
||||
test_camera_lookat(void **state) {
|
||||
mat4 view1, view2;
|
||||
TEST_IMPL(camera_lookat) {
|
||||
mat4 view1, view2;
|
||||
vec3 center,
|
||||
eye = {0.024f, 14.6f, 67.04f},
|
||||
dir = {0.0f, 0.0f, -1.0f},
|
||||
up = {0.0f, 1.0f, 0.0f}
|
||||
;
|
||||
eye = {0.024f, 14.6f, 67.04f},
|
||||
dir = {0.0f, 0.0f, -1.0f},
|
||||
up = {0.0f, 1.0f, 0.0f};
|
||||
|
||||
glm_vec3_add(eye, dir, center);
|
||||
glm_lookat(eye, center, up, view1);
|
||||
|
||||
glm_look(eye, dir, up, view2);
|
||||
|
||||
test_assert_mat4_eq(view1, view2);
|
||||
ASSERTIFY(test_assert_mat4_eq(view1, view2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_camera_decomp(void **state) {
|
||||
TEST_IMPL(camera_decomp) {
|
||||
mat4 proj, proj2;
|
||||
vec4 sizes;
|
||||
float aspect, fovy, nearVal, farVal;
|
||||
@@ -36,19 +35,21 @@ test_camera_decomp(void **state) {
|
||||
farVal = 100.0f;
|
||||
|
||||
glm_perspective(fovy, aspect, nearVal, farVal, proj);
|
||||
assert_true(fabsf(aspect - glm_persp_aspect(proj)) < FLT_EPSILON);
|
||||
assert_true(fabsf(fovy - glm_persp_fovy(proj)) < FLT_EPSILON);
|
||||
assert_true(fabsf(49.984f - glm_deg(glm_persp_fovy(proj))) < FLT_EPSILON);
|
||||
ASSERT(fabsf(aspect - glm_persp_aspect(proj)) < FLT_EPSILON)
|
||||
ASSERT(fabsf(fovy - glm_persp_fovy(proj)) < FLT_EPSILON)
|
||||
ASSERT(fabsf(49.984f - glm_deg(glm_persp_fovy(proj))) < FLT_EPSILON)
|
||||
|
||||
glm_persp_sizes(proj, fovy, sizes);
|
||||
|
||||
glm_frustum(-sizes[0] * 0.5,
|
||||
sizes[0] * 0.5,
|
||||
-sizes[1] * 0.5,
|
||||
sizes[1] * 0.5,
|
||||
glm_frustum(-sizes[0] * 0.5f,
|
||||
sizes[0] * 0.5f,
|
||||
-sizes[1] * 0.5f,
|
||||
sizes[1] * 0.5f,
|
||||
nearVal,
|
||||
farVal,
|
||||
proj2);
|
||||
|
||||
test_assert_mat4_eq(proj, proj2);
|
||||
ASSERTIFY(test_assert_mat4_eq(proj, proj2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -7,24 +7,25 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
void
|
||||
test_clamp(void **state) {
|
||||
vec3 v3 = {15.07, 0.4, 17.3};
|
||||
vec4 v4 = {5.07, 2.3, 1.3, 1.4};
|
||||
TEST_IMPL(clamp) {
|
||||
vec3 v3 = {15.07f, 0.4f, 17.3f};
|
||||
vec4 v4 = {5.07f, 2.3f, 1.3f, 1.4f};
|
||||
|
||||
assert_true(glm_clamp(1.6f, 0.0f, 1.0f) == 1.0f);
|
||||
assert_true(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f);
|
||||
assert_true(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f);
|
||||
ASSERT(glm_clamp(1.6f, 0.0f, 1.0f) == 1.0f)
|
||||
ASSERT(glm_clamp(-1.6f, 0.0f, 1.0f) == 0.0f)
|
||||
ASSERT(glm_clamp(0.6f, 0.0f, 1.0f) == 0.6f)
|
||||
|
||||
glm_vec3_clamp(v3, 0.0, 1.0);
|
||||
glm_vec4_clamp(v4, 1.5, 3.0);
|
||||
|
||||
assert_true(v3[0] == 1.0f);
|
||||
assert_true(v3[1] == 0.4f);
|
||||
assert_true(v3[2] == 1.0f);
|
||||
ASSERT(v3[0] == 1.0f)
|
||||
ASSERT(v3[1] == 0.4f)
|
||||
ASSERT(v3[2] == 1.0f)
|
||||
|
||||
assert_true(v4[0] == 3.0f);
|
||||
assert_true(v4[1] == 2.3f);
|
||||
assert_true(v4[2] == 1.5f);
|
||||
assert_true(v4[3] == 1.5f);
|
||||
ASSERT(v4[0] == 3.0f)
|
||||
ASSERT(v4[1] == 2.3f)
|
||||
ASSERT(v4[2] == 1.5f)
|
||||
ASSERT(v4[3] == 1.5f)
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -4,18 +4,12 @@
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
|
||||
#define m 4
|
||||
#define n 4
|
||||
#include <time.h>
|
||||
|
||||
void
|
||||
test_rand_mat4(mat4 dest) {
|
||||
glm_mat4_copy(GLM_MAT4_IDENTITY, dest);
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
/* random position */
|
||||
dest[3][0] = drand48();
|
||||
dest[3][1] = drand48();
|
||||
@@ -32,8 +26,6 @@ void
|
||||
test_rand_mat3(mat3 dest) {
|
||||
mat4 m4;
|
||||
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
/* random rotatation around random axis with random angle */
|
||||
glm_rotate_make(m4, drand48(), (vec3){drand48(), drand48(), drand48()});
|
||||
glm_mat4_pick3(m4, dest);
|
||||
@@ -41,8 +33,6 @@ test_rand_mat3(mat3 dest) {
|
||||
|
||||
void
|
||||
test_rand_vec3(vec3 dest) {
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
dest[0] = drand48();
|
||||
dest[1] = drand48();
|
||||
dest[2] = drand48();
|
||||
@@ -57,8 +47,6 @@ test_rand_vec3s() {
|
||||
|
||||
void
|
||||
test_rand_vec4(vec4 dest) {
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
dest[0] = drand48();
|
||||
dest[1] = drand48();
|
||||
dest[2] = drand48();
|
||||
@@ -74,97 +62,213 @@ test_rand_vec4s() {
|
||||
|
||||
float
|
||||
test_rand(void) {
|
||||
srand((unsigned int)time(NULL));
|
||||
return drand48();
|
||||
}
|
||||
|
||||
void
|
||||
test_rand_quat(versor q) {
|
||||
srand((unsigned int)time(NULL));
|
||||
|
||||
glm_quat(q, drand48(), drand48(), drand48(), drand48());
|
||||
glm_quat_normalize(q);
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_mat4_eq(mat4 m1, mat4 m2) {
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
for (k = 0; k < m; k++)
|
||||
assert_true(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009);
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_mat4_eqt(mat4 m1, mat4 m2) {
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++)
|
||||
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009)
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps) {
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
for (k = 0; k < m; k++)
|
||||
assert_true(fabsf(m1[i][j] - m2[i][j]) <= eps);
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++)
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= eps);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_mat3_eq(mat3 m1, mat3 m2) {
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
for (k = 0; k < 3; k++)
|
||||
assert_true(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009);
|
||||
ASSERT(fabsf(m1[i][j] - m2[i][j]) <= 0.0000009);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_mat3_eqt(mat3 m1, mat3 m2) {
|
||||
int i, j, k;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
for (k = 0; k < 3; k++)
|
||||
ASSERT(fabsf(m1[j][i] - m2[i][j]) <= 0.0000009);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3_eq_identity(mat3 m3) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
if (i == j) {
|
||||
ASSERT(test_eq(m3[i][j], 1.0f))
|
||||
} else {
|
||||
ASSERT(test_eq(m3[i][j], 0.0f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3_eq_zero(mat3 m3) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
ASSERT(test_eq(m3[i][j], 0.0f))
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat4_eq_identity(mat4 m4) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
if (i == j) {
|
||||
ASSERT(test_eq(m4[i][j], 1.0f))
|
||||
} else {
|
||||
ASSERT(test_eq(m4[i][j], 0.0f))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_mat4_eq_zero(mat4 m4) {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
ASSERT(test_eq(m4[i][j], 0.0f))
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_eqf(float a, float b) {
|
||||
assert_true(fabsf(a - b) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(a - b) <= 0.000009); /* rounding errors */
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_vec3_eq(vec3 v1, vec3 v2) {
|
||||
assert_true(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
assert_true(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
assert_true(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_vec3s_eq(vec3s v1, vec3s v2) {
|
||||
test_assert_vec3_eq(v1.raw, v2.raw);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_vec4_eq(vec4 v1, vec4 v2) {
|
||||
assert_true(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
assert_true(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
assert_true(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
assert_true(fabsf(v1[3] - v2[3]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_vec4s_eq(vec4s v1, vec4s v2) {
|
||||
test_assert_vec4_eq(v1.raw, v2.raw);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_quat_eq_abs(versor v1, versor v2) {
|
||||
assert_true(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */
|
||||
assert_true(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009);
|
||||
assert_true(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009);
|
||||
assert_true(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009);
|
||||
ASSERT(fabsf(fabsf(v1[0]) - fabsf(v2[0])) <= 0.0009); /* rounding errors */
|
||||
ASSERT(fabsf(fabsf(v1[1]) - fabsf(v2[1])) <= 0.0009);
|
||||
ASSERT(fabsf(fabsf(v1[2]) - fabsf(v2[2])) <= 0.0009);
|
||||
ASSERT(fabsf(fabsf(v1[3]) - fabsf(v2[3])) <= 0.0009);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_quat_eq(versor v1, versor v2) {
|
||||
assert_true(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
assert_true(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
assert_true(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
assert_true(fabsf(v1[3] - v2[3]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[0] - v2[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(v1[1] - v2[1]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[2] - v2[2]) <= 0.000009);
|
||||
ASSERT(fabsf(v1[3] - v2[3]) <= 0.000009);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
test_status_t
|
||||
test_assert_quat_eq_identity(versor q) {
|
||||
versor p = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
ASSERT(fabsf(q[0] - p[0]) <= 0.000009); /* rounding errors */
|
||||
ASSERT(fabsf(q[1] - p[1]) <= 0.000009);
|
||||
ASSERT(fabsf(q[2] - p[2]) <= 0.000009);
|
||||
ASSERT(fabsf(q[3] - p[3]) <= 0.000009);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -8,20 +8,7 @@
|
||||
#ifndef test_common_h
|
||||
#define test_common_h
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <setjmp.h>
|
||||
#include <cmocka.h>
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <cglm/cglm.h>
|
||||
#include <cglm/struct.h>
|
||||
#include <cglm/call.h>
|
||||
#include "../include/common.h"
|
||||
|
||||
void
|
||||
test_rand_mat4(mat4 dest);
|
||||
@@ -29,34 +16,55 @@ test_rand_mat4(mat4 dest);
|
||||
void
|
||||
test_rand_mat3(mat3 dest);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_eqf(float a, float b);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_mat4_eq(mat4 m1, mat4 m2);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_mat4_eqt(mat4 m1, mat4 m2);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat4_eq2(mat4 m1, mat4 m2, float eps);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_mat4_eq_identity(mat4 m4);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat4_eq_zero(mat4 m4);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3_eq(mat3 m1, mat3 m2);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_mat3_eqt(mat3 m1, mat3 m2);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3_eq_identity(mat3 m3);
|
||||
|
||||
test_status_t
|
||||
test_assert_mat3_eq_zero(mat3 m3);
|
||||
|
||||
test_status_t
|
||||
test_assert_vec3_eq(vec3 v1, vec3 v2);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_vec3s_eq(vec3s v1, vec3s v2);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_vec4_eq(vec4 v1, vec4 v2);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_vec4s_eq(vec4s v1, vec4s v2);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_quat_eq(versor v1, versor v2);
|
||||
|
||||
void
|
||||
test_status_t
|
||||
test_assert_quat_eq_identity(versor q) ;
|
||||
|
||||
test_status_t
|
||||
test_assert_quat_eq_abs(versor v1, versor v2);
|
||||
|
||||
void
|
||||
@@ -77,4 +85,16 @@ test_rand(void);
|
||||
void
|
||||
test_rand_quat(versor q);
|
||||
|
||||
CGLM_INLINE
|
||||
bool
|
||||
test_eq(float a, float b) {
|
||||
return fabsf(a - b) <= 1e-6;
|
||||
}
|
||||
|
||||
CGLM_INLINE
|
||||
bool
|
||||
test_eq_th(float a, float b, float th) {
|
||||
return fabsf(a - b) <= th;
|
||||
}
|
||||
|
||||
#endif /* test_common_h */
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
void
|
||||
test_euler(void **state) {
|
||||
mat4 rot1, rot2;
|
||||
vec3 inAngles, outAngles;
|
||||
TEST_IMPL(euler) {
|
||||
mat4 rot1, rot2;
|
||||
vec3 inAngles, outAngles;
|
||||
|
||||
inAngles[0] = glm_rad(-45.0f); /* X angle */
|
||||
inAngles[1] = glm_rad(88.0f); /* Y angle */
|
||||
@@ -22,11 +21,11 @@ test_euler(void **state) {
|
||||
glmc_euler_angles(rot1, outAngles);
|
||||
|
||||
/* angles must be equal in that range */
|
||||
test_assert_vec3_eq(inAngles, outAngles);
|
||||
ASSERTIFY(test_assert_vec3_eq(inAngles, outAngles))
|
||||
|
||||
/* matrices must be equal */
|
||||
glmc_euler_xyz(outAngles, rot2);
|
||||
test_assert_mat4_eq(rot1, rot2);
|
||||
ASSERTIFY(test_assert_mat4_eq(rot1, rot2))
|
||||
|
||||
/* change range */
|
||||
inAngles[0] = glm_rad(-145.0f); /* X angle */
|
||||
@@ -40,5 +39,7 @@ test_euler(void **state) {
|
||||
|
||||
/* matrices must be equal */
|
||||
glmc_euler_xyz(outAngles, rot2);
|
||||
test_assert_mat4_eq(rot1, rot2);
|
||||
ASSERTIFY(test_assert_mat4_eq(rot1, rot2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
#include "test_tests.h"
|
||||
|
||||
int
|
||||
main(int argc, const char * argv[]) {
|
||||
const struct CMUnitTest tests[] = {
|
||||
/* mat4 */
|
||||
cmocka_unit_test(test_mat4),
|
||||
|
||||
/* mat3 */
|
||||
cmocka_unit_test(test_mat3),
|
||||
|
||||
/* camera */
|
||||
cmocka_unit_test(test_camera_lookat),
|
||||
cmocka_unit_test(test_camera_decomp),
|
||||
|
||||
/* project */
|
||||
cmocka_unit_test(test_project),
|
||||
|
||||
/* vector */
|
||||
cmocka_unit_test(test_clamp),
|
||||
|
||||
/* euler */
|
||||
cmocka_unit_test(test_euler),
|
||||
|
||||
/* quaternion */
|
||||
cmocka_unit_test(test_quat),
|
||||
|
||||
/* vec4 */
|
||||
cmocka_unit_test(test_vec4),
|
||||
|
||||
/* vec3 */
|
||||
cmocka_unit_test(test_vec3),
|
||||
|
||||
/* affine */
|
||||
cmocka_unit_test(test_affine),
|
||||
|
||||
/* bezier */
|
||||
cmocka_unit_test(test_bezier)
|
||||
};
|
||||
|
||||
return cmocka_run_group_tests(tests, NULL, NULL);
|
||||
}
|
||||
@@ -5,54 +5,22 @@
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
/* test inline mat3 */
|
||||
|
||||
#define m 3
|
||||
#define n 3
|
||||
#define GLM_PREFIX glm_
|
||||
#define GLM(X) (glm_ ## X)
|
||||
|
||||
void
|
||||
test_mat3(void **state) {
|
||||
mat3 m1 = GLM_MAT3_IDENTITY_INIT;
|
||||
mat3 m2 = GLM_MAT3_IDENTITY_INIT;
|
||||
mat3 m3;
|
||||
mat3 m4 = GLM_MAT3_ZERO_INIT;
|
||||
mat3 m5;
|
||||
int i, j, k;
|
||||
#include "test_mat3.h"
|
||||
|
||||
/* test identity matrix multiplication */
|
||||
glmc_mat3_mul(m1, m2, m3);
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
if (i == j)
|
||||
assert_true(glm_eq(m3[i][j], 1.0f));
|
||||
else
|
||||
assert_true(glm_eq(m3[i][j], 0.0f));
|
||||
}
|
||||
}
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
/* test random matrices */
|
||||
/* random matrices */
|
||||
test_rand_mat3(m1);
|
||||
test_rand_mat3(m2);
|
||||
/* test pre-compiled mat3 */
|
||||
|
||||
glmc_mat3_mul(m1, m2, m3);
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
for (k = 0; k < m; k++)
|
||||
/* column-major */
|
||||
m4[i][j] += m1[k][j] * m2[i][k];
|
||||
}
|
||||
}
|
||||
#define GLM_PREFIX glmc_
|
||||
#define GLM(X) (glmc_ ## X)
|
||||
|
||||
test_assert_mat3_eq(m3, m4);
|
||||
#include "test_mat3.h"
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
test_rand_mat3(m3);
|
||||
test_rand_mat3(m4);
|
||||
|
||||
/* test inverse precise */
|
||||
glmc_mat3_inv(m3, m4);
|
||||
glmc_mat3_inv(m4, m5);
|
||||
test_assert_mat3_eq(m3, m5);
|
||||
}
|
||||
}
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
309
test/src/test_mat3.h
Normal file
309
test/src/test_mat3.h
Normal file
@@ -0,0 +1,309 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define A_MATRIX {{1,2,3},{5,6,7},{9,10,11}}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_copy) {
|
||||
mat3 m1 = A_MATRIX;
|
||||
mat3 m2 = GLM_MAT3_IDENTITY_INIT;
|
||||
|
||||
GLM(mat3_copy)(m1, m2);
|
||||
|
||||
test_assert_mat3_eq(m1, m2);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_identity) {
|
||||
mat3 m1 = GLM_MAT3_IDENTITY_INIT;
|
||||
mat3 m2 = GLM_MAT3_IDENTITY_INIT;
|
||||
mat3 m3;
|
||||
|
||||
GLM(mat3_identity)(m3);
|
||||
|
||||
ASSERTIFY(test_assert_mat3_eq_identity(m1))
|
||||
ASSERTIFY(test_assert_mat3_eq_identity(m2))
|
||||
ASSERTIFY(test_assert_mat3_eq_identity(m3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_identity_array) {
|
||||
int i, count;
|
||||
mat3 matrices[4] = {
|
||||
A_MATRIX,
|
||||
A_MATRIX,
|
||||
A_MATRIX,
|
||||
A_MATRIX
|
||||
};
|
||||
|
||||
count = 4;
|
||||
|
||||
GLM(mat3_identity_array)(matrices, count);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
ASSERTIFY(test_assert_mat3_eq_identity(matrices[i]))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_zero) {
|
||||
mat3 m1 = GLM_MAT3_ZERO_INIT;
|
||||
mat3 m2 = GLM_MAT3_ZERO_INIT;
|
||||
mat3 m3;
|
||||
|
||||
GLM(mat3_zero)(m3);
|
||||
|
||||
ASSERTIFY(test_assert_mat3_eq_zero(m1))
|
||||
ASSERTIFY(test_assert_mat3_eq_zero(m2))
|
||||
ASSERTIFY(test_assert_mat3_eq_zero(m3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_mul) {
|
||||
mat3 m1 = GLM_MAT3_IDENTITY_INIT;
|
||||
mat3 m2 = GLM_MAT3_IDENTITY_INIT;
|
||||
mat3 m3;
|
||||
mat3 m4 = GLM_MAT3_ZERO_INIT;
|
||||
int i, j, k;
|
||||
|
||||
/* test random matrices */
|
||||
/* random matrices */
|
||||
test_rand_mat3(m1);
|
||||
test_rand_mat3(m2);
|
||||
|
||||
GLM(mat3_mul)(m1, m2, m3);
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
for (k = 0; k < 3; k++)
|
||||
/* column-major */
|
||||
m4[i][j] += m1[k][j] * m2[i][k];
|
||||
}
|
||||
}
|
||||
|
||||
ASSERTIFY(test_assert_mat3_eq(m3, m4))
|
||||
|
||||
/* test pre compiled */
|
||||
GLM(mat3_mul)(m1, m2, m3);
|
||||
ASSERTIFY(test_assert_mat3_eq(m3, m4))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_mulv) {
|
||||
vec4 res;
|
||||
mat3 mat = A_MATRIX;
|
||||
vec4 v = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
int i;
|
||||
|
||||
GLM(mat3_mulv)(mat, v, res);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
ASSERT(test_eq(res[i],
|
||||
v[0] * mat[0][i]
|
||||
+ v[1] * mat[1][i]
|
||||
+ v[2] * mat[2][i]))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_trace) {
|
||||
mat3 mat = A_MATRIX;
|
||||
float trace;
|
||||
|
||||
trace = GLM(mat3_trace)(mat);
|
||||
|
||||
ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_quat) {
|
||||
mat3 m1, m3;
|
||||
mat4 m2;
|
||||
versor q1, q2, q3;
|
||||
vec3 axis1;
|
||||
vec3 axis2 = {1.9f, 2.3f, 4.5f};
|
||||
|
||||
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
|
||||
GLM(quat_mat3)(q1, m1);
|
||||
GLM(mat3_quat)(m1, q2);
|
||||
|
||||
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
|
||||
GLM(mat3_quat)(m1, q3);
|
||||
|
||||
GLM(quat_axis)(q3, axis1);
|
||||
|
||||
GLM(vec3_normalize)(axis1);
|
||||
GLM(vec3_normalize)(axis2);
|
||||
|
||||
GLM(mat4_pick3)(m2, m3);
|
||||
|
||||
ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f))
|
||||
ASSERTIFY(test_assert_vec3_eq(axis1, axis2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q2))
|
||||
ASSERTIFY(test_assert_mat3_eq(m1, m3))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_transpose_to) {
|
||||
mat3 mat = A_MATRIX;
|
||||
mat3 m1;
|
||||
|
||||
GLM(mat3_transpose_to)(mat, m1);
|
||||
|
||||
ASSERTIFY(test_assert_mat3_eqt(mat, m1))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_transpose) {
|
||||
mat3 mat = A_MATRIX;
|
||||
mat3 m1;
|
||||
|
||||
GLM(mat3_copy)(mat, m1);
|
||||
GLM(mat3_transpose)(m1);
|
||||
|
||||
ASSERTIFY(test_assert_mat3_eqt(mat, m1))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_scale) {
|
||||
mat3 m1 = A_MATRIX;
|
||||
mat3 m2 = A_MATRIX;
|
||||
int i, j, k, scale;
|
||||
|
||||
scale = rand() % 100;
|
||||
|
||||
GLM(mat3_scale)(m1, (float)scale);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
for (k = 0; k < 3; k++)
|
||||
ASSERT(test_eq(m1[i][j], m2[i][j] * scale))
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_det) {
|
||||
mat3 mat;
|
||||
float a, b, c,
|
||||
d, e, f,
|
||||
g, h, i;
|
||||
float det1, det2;
|
||||
|
||||
test_rand_mat3(mat);
|
||||
|
||||
a = mat[0][0]; b = mat[0][1]; c = mat[0][2];
|
||||
d = mat[1][0]; e = mat[1][1]; f = mat[1][2];
|
||||
g = mat[2][0]; h = mat[2][1]; i = mat[2][2];
|
||||
|
||||
det1 = a * (e * i - h * f) - d * (b * i - c * h) + g * (b * f - c * e);
|
||||
det2 = GLM(mat3_det)(mat);
|
||||
|
||||
ASSERT(test_eq(det1, det2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_inv) {
|
||||
mat3 m1 = GLM_MAT3_IDENTITY_INIT;
|
||||
mat3 m2 = GLM_MAT3_IDENTITY_INIT;
|
||||
mat3 m3;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
test_rand_mat3(m1);
|
||||
test_rand_mat3(m2);
|
||||
|
||||
/* test inverse precise */
|
||||
GLM(mat3_inv)(m1, m2);
|
||||
GLM(mat3_inv)(m2, m3);
|
||||
ASSERTIFY(test_assert_mat3_eq(m1, m3))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_swap_col) {
|
||||
mat3 m1 = A_MATRIX;
|
||||
mat3 m2 = A_MATRIX;
|
||||
|
||||
GLM(mat3_swap_col)(m1, 0, 1);
|
||||
|
||||
ASSERTIFY(test_assert_vec3_eq(m1[0], m2[1]))
|
||||
ASSERTIFY(test_assert_vec3_eq(m1[1], m2[0]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_swap_row) {
|
||||
mat3 m1 = A_MATRIX;
|
||||
mat3 m2 = A_MATRIX;
|
||||
|
||||
GLM(mat3_swap_row)(m1, 0, 1);
|
||||
|
||||
ASSERT(test_eq(m1[0][0], m2[0][1]))
|
||||
ASSERT(test_eq(m1[0][1], m2[0][0]))
|
||||
ASSERT(test_eq(m1[0][2], m2[0][2]))
|
||||
|
||||
ASSERT(test_eq(m1[1][0], m2[1][1]))
|
||||
ASSERT(test_eq(m1[1][1], m2[1][0]))
|
||||
ASSERT(test_eq(m1[1][2], m2[1][2]))
|
||||
|
||||
ASSERT(test_eq(m1[2][0], m2[2][1]))
|
||||
ASSERT(test_eq(m1[2][1], m2[2][0]))
|
||||
ASSERT(test_eq(m1[2][2], m2[2][2]))
|
||||
|
||||
GLM(mat3_swap_row)(m1, 1, 2);
|
||||
|
||||
ASSERT(test_eq(m1[0][0], m2[0][1]))
|
||||
ASSERT(test_eq(m1[0][1], m2[0][2]))
|
||||
ASSERT(test_eq(m1[0][2], m2[0][0]))
|
||||
|
||||
ASSERT(test_eq(m1[1][0], m2[1][1]))
|
||||
ASSERT(test_eq(m1[1][1], m2[1][2]))
|
||||
ASSERT(test_eq(m1[1][2], m2[1][0]))
|
||||
|
||||
ASSERT(test_eq(m1[2][0], m2[2][1]))
|
||||
ASSERT(test_eq(m1[2][1], m2[2][2]))
|
||||
ASSERT(test_eq(m1[2][2], m2[2][0]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat3_rmc) {
|
||||
mat3 mat = A_MATRIX;
|
||||
vec3 v = {11.0f, 12.0f, 13.0f};
|
||||
vec3 v1;
|
||||
float r1, r2;
|
||||
int i;
|
||||
|
||||
r1 = GLM(mat3_rmc)(v, mat, v);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
v1[i] = v[0] * mat[i][0]
|
||||
+ v[1] * mat[i][1]
|
||||
+ v[2] * mat[i][2];
|
||||
}
|
||||
|
||||
r2 = v[0] * v1[0] + v[1] * v1[1] + v[2] * v1[2];
|
||||
|
||||
ASSERT(test_eq(r1, r2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
@@ -5,90 +5,22 @@
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
/* test inline mat4 */
|
||||
|
||||
#define m 4
|
||||
#define n 4
|
||||
#define GLM_PREFIX glm_
|
||||
#define GLM(X) (glm_ ## X)
|
||||
|
||||
void
|
||||
test_mat4(void **state) {
|
||||
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat4 m3;
|
||||
mat4 m4 = GLM_MAT4_ZERO_INIT;
|
||||
mat4 m5;
|
||||
int i, j, k;
|
||||
#include "test_mat4.h"
|
||||
|
||||
/* test identity matrix multiplication */
|
||||
glm_mat4_mul(m1, m2, m3);
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
if (i == j)
|
||||
assert_true(glm_eq(m3[i][j], 1.0f));
|
||||
else
|
||||
assert_true(glm_eq(m3[i][j], 0.0f));
|
||||
}
|
||||
}
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
/* test random matrices */
|
||||
/* random matrices */
|
||||
test_rand_mat4(m1);
|
||||
test_rand_mat4(m2);
|
||||
/* test pre-compiled mat4 */
|
||||
|
||||
glm_mat4_mul(m1, m2, m3);
|
||||
for (i = 0; i < m; i++) {
|
||||
for (j = 0; j < n; j++) {
|
||||
for (k = 0; k < m; k++)
|
||||
/* column-major */
|
||||
m4[i][j] += m1[k][j] * m2[i][k];
|
||||
}
|
||||
}
|
||||
#define GLM_PREFIX glmc_
|
||||
#define GLM(X) (glmc_ ## X)
|
||||
|
||||
test_assert_mat4_eq(m3, m4);
|
||||
#include "test_mat4.h"
|
||||
|
||||
/* test pre compiled */
|
||||
glmc_mat4_mul(m1, m2, m3);
|
||||
test_assert_mat4_eq(m3, m4);
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
test_rand_mat4(m3);
|
||||
test_rand_mat4(m4);
|
||||
|
||||
/* test inverse precise */
|
||||
glm_mat4_inv_precise(m3, m4);
|
||||
glm_mat4_inv_precise(m4, m5);
|
||||
test_assert_mat4_eq(m3, m5);
|
||||
|
||||
test_rand_mat4(m3);
|
||||
test_rand_mat4(m4);
|
||||
|
||||
glmc_mat4_inv_precise(m3, m4);
|
||||
glmc_mat4_inv_precise(m4, m5);
|
||||
test_assert_mat4_eq(m3, m5);
|
||||
|
||||
/* test inverse rcp */
|
||||
test_rand_mat4(m3);
|
||||
test_rand_mat4(m4);
|
||||
|
||||
glm_mat4_inv_fast(m3, m4);
|
||||
glm_mat4_inv_fast(m4, m5);
|
||||
test_assert_mat4_eq2(m3, m5, 0.0009f);
|
||||
|
||||
test_rand_mat4(m3);
|
||||
test_rand_mat4(m4);
|
||||
|
||||
glmc_mat4_inv(m3, m4);
|
||||
glmc_mat4_inv(m4, m5);
|
||||
test_assert_mat4_eq2(m3, m5, 0.0009f);
|
||||
}
|
||||
|
||||
/* print */
|
||||
glm_mat4_print(m3, stderr);
|
||||
glm_mat4_print(m4, stderr);
|
||||
|
||||
/* test determinant */
|
||||
assert_int_equal(glm_mat4_det(m1), glmc_mat4_det(m1));
|
||||
#if defined( __SSE2__ )
|
||||
assert_int_equal(glmc_mat4_det(m1), glm_mat4_det_sse2(m1));
|
||||
#endif
|
||||
}
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
485
test/src/test_mat4.h
Normal file
485
test/src/test_mat4.h
Normal file
@@ -0,0 +1,485 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#define A_MATRIX {{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}}
|
||||
#define A_MATRIX3 {{1,2,3},{5,6,7},{9,10,11}}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_ucopy) {
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
||||
|
||||
GLM(mat4_ucopy)(m1, m2);
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_copy) {
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
||||
|
||||
GLM(mat4_copy)(m1, m2);
|
||||
|
||||
test_assert_mat4_eq(m1, m2);
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_identity) {
|
||||
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat4 m3;
|
||||
|
||||
GLM(mat4_identity)(m3);
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eq_identity(m1))
|
||||
ASSERTIFY(test_assert_mat4_eq_identity(m2))
|
||||
ASSERTIFY(test_assert_mat4_eq_identity(m3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_identity_array) {
|
||||
int i, count;
|
||||
mat4 matrices[4] = {
|
||||
A_MATRIX,
|
||||
A_MATRIX,
|
||||
A_MATRIX,
|
||||
A_MATRIX
|
||||
};
|
||||
|
||||
count = 4;
|
||||
|
||||
GLM(mat4_identity_array)(matrices, count);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
ASSERTIFY(test_assert_mat4_eq_identity(matrices[i]))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_zero) {
|
||||
mat4 m1 = GLM_MAT4_ZERO_INIT;
|
||||
mat4 m2 = GLM_MAT4_ZERO_INIT;
|
||||
mat4 m3;
|
||||
|
||||
GLM(mat4_zero)(m3);
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eq_zero(m1))
|
||||
ASSERTIFY(test_assert_mat4_eq_zero(m2))
|
||||
ASSERTIFY(test_assert_mat4_eq_zero(m3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_pick3) {
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat3 m2 = GLM_MAT3_ZERO_INIT;
|
||||
mat3 m3 = A_MATRIX3;
|
||||
|
||||
GLM(mat4_pick3)(m1, m2);
|
||||
|
||||
ASSERTIFY(test_assert_mat3_eq(m2, m3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_pick3t) {
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat3 m2 = GLM_MAT3_ZERO_INIT;
|
||||
mat3 m3 = A_MATRIX3;
|
||||
|
||||
GLM(mat4_pick3t)(m1, m2);
|
||||
|
||||
ASSERTIFY(test_assert_mat3_eqt(m2, m3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_ins3) {
|
||||
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat3 m2 = A_MATRIX3;
|
||||
int i, j;
|
||||
|
||||
GLM(mat4_ins3)(m2, m1);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 3; j++) {
|
||||
ASSERT(m1[i][j] == m2[i][j])
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT(test_eq(m1[3][0], 0.0f))
|
||||
ASSERT(test_eq(m1[3][1], 0.0f))
|
||||
ASSERT(test_eq(m1[3][2], 0.0f))
|
||||
ASSERT(test_eq(m1[3][3], 1.0f))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_mul) {
|
||||
mat4 m1 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat4 m2 = GLM_MAT4_IDENTITY_INIT;
|
||||
mat4 m3;
|
||||
mat4 m4 = GLM_MAT4_ZERO_INIT;
|
||||
int i, j, k;
|
||||
|
||||
/* test random matrices */
|
||||
/* random matrices */
|
||||
test_rand_mat4(m1);
|
||||
test_rand_mat4(m2);
|
||||
|
||||
GLM(mat4_mul)(m1, m2, m3);
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++)
|
||||
/* column-major */
|
||||
m4[i][j] += m1[k][j] * m2[i][k];
|
||||
}
|
||||
}
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eq(m3, m4))
|
||||
|
||||
/* test pre compiled */
|
||||
GLM(mat4_mul)(m1, m2, m3);
|
||||
ASSERTIFY(test_assert_mat4_eq(m3, m4))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_mulN) {
|
||||
mat4 res1, res2;
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat4 m2 = A_MATRIX;
|
||||
mat4 m3 = A_MATRIX;
|
||||
|
||||
mat4 *matrices[] = {
|
||||
&m1, &m2, &m3
|
||||
};
|
||||
|
||||
GLM(mat4_mulN)(matrices, sizeof(matrices) / sizeof(matrices[0]), res1);
|
||||
|
||||
GLM(mat4_mul)(*matrices[0], *matrices[1], res2);
|
||||
GLM(mat4_mul)(res2, *matrices[2], res2);
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eq(res1, res1))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_mulv) {
|
||||
vec4 res;
|
||||
mat4 mat = A_MATRIX;
|
||||
vec4 v = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
int i;
|
||||
|
||||
GLM(mat4_mulv)(mat, v, res);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
ASSERT(test_eq(res[i],
|
||||
v[0] * mat[0][i]
|
||||
+ v[1] * mat[1][i]
|
||||
+ v[2] * mat[2][i]
|
||||
+ v[3] * mat[3][i]))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_mulv3) {
|
||||
vec4 res;
|
||||
mat4 mat = A_MATRIX;
|
||||
vec3 v = {1.0f, 2.0f, 3.0f};
|
||||
float last;
|
||||
int i;
|
||||
|
||||
last = 1.0f;
|
||||
|
||||
GLM(mat4_mulv3)(mat, v, last, res);
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
ASSERT(test_eq(res[i],
|
||||
v[0] * mat[0][i]
|
||||
+ v[1] * mat[1][i]
|
||||
+ v[2] * mat[2][i]
|
||||
+ last * mat[3][i]))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_trace) {
|
||||
mat4 mat = A_MATRIX;
|
||||
float trace;
|
||||
|
||||
trace = GLM(mat4_trace)(mat);
|
||||
|
||||
ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2] + mat[3][3]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_trace3) {
|
||||
mat4 mat = A_MATRIX;
|
||||
float trace;
|
||||
|
||||
trace = GLM(mat4_trace3)(mat);
|
||||
|
||||
ASSERT(test_eq(trace, mat[0][0] + mat[1][1] + mat[2][2]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_quat) {
|
||||
mat4 m1, m2;
|
||||
versor q1, q2, q3;
|
||||
vec3 axis1;
|
||||
vec3 axis2 = {1.9f, 2.3f, 4.5f};
|
||||
|
||||
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
|
||||
GLM(quat_mat4)(q1, m1);
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
|
||||
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
|
||||
GLM(mat4_quat)(m1, q3);
|
||||
|
||||
GLM(quat_axis)(q3, axis1);
|
||||
|
||||
GLM(vec3_normalize)(axis1);
|
||||
GLM(vec3_normalize)(axis2);
|
||||
|
||||
ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f))
|
||||
ASSERTIFY(test_assert_vec3_eq(axis1, axis2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q2))
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q3))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_transpose_to) {
|
||||
mat4 mat = A_MATRIX;
|
||||
mat4 m1;
|
||||
|
||||
GLM(mat4_transpose_to)(mat, m1);
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eqt(mat, m1))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_transpose) {
|
||||
mat4 mat = A_MATRIX;
|
||||
mat4 m1;
|
||||
|
||||
GLM(mat4_copy)(mat, m1);
|
||||
GLM(mat4_transpose)(m1);
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eqt(mat, m1))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_scale_p) {
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat4 m2 = A_MATRIX;
|
||||
int i, j, k, scale;
|
||||
|
||||
scale = rand() % 100;
|
||||
|
||||
GLM(mat4_scale_p)(m1, (float)scale);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++)
|
||||
ASSERT(test_eq(m1[i][j], m2[i][j] * scale))
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_scale) {
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat4 m2 = A_MATRIX;
|
||||
int i, j, k, scale;
|
||||
|
||||
scale = rand() % 100;
|
||||
|
||||
GLM(mat4_scale)(m1, (float)scale);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
for (j = 0; j < 4; j++) {
|
||||
for (k = 0; k < 4; k++)
|
||||
ASSERT(test_eq(m1[i][j], m2[i][j] * scale))
|
||||
}
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_det) {
|
||||
mat4 mat = GLM_MAT4_IDENTITY_INIT;
|
||||
float t[6];
|
||||
float a, b, c, d,
|
||||
e, f, g, h,
|
||||
i, j, k, l,
|
||||
m, n, o, p;
|
||||
float det1, det2;
|
||||
|
||||
test_rand_mat4(mat);
|
||||
|
||||
a = mat[0][0]; b = mat[0][1]; c = mat[0][2]; d = mat[0][3];
|
||||
e = mat[1][0]; f = mat[1][1]; g = mat[1][2]; h = mat[1][3];
|
||||
i = mat[2][0]; j = mat[2][1]; k = mat[2][2]; l = mat[2][3];
|
||||
m = mat[3][0]; n = mat[3][1]; o = mat[3][2]; p = mat[3][3];
|
||||
|
||||
t[0] = k * p - o * l;
|
||||
t[1] = j * p - n * l;
|
||||
t[2] = j * o - n * k;
|
||||
t[3] = i * p - m * l;
|
||||
t[4] = i * o - m * k;
|
||||
t[5] = i * n - m * j;
|
||||
|
||||
det1 = a * (f * t[0] - g * t[1] + h * t[2])
|
||||
- b * (e * t[0] - g * t[3] + h * t[4])
|
||||
+ c * (e * t[1] - f * t[3] + h * t[5])
|
||||
- d * (e * t[2] - f * t[4] + g * t[5]);
|
||||
|
||||
det2 = GLM(mat4_det(mat));
|
||||
|
||||
ASSERT(test_eq(det1, det2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_inv) {
|
||||
mat4 m1, m2, m3;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
test_rand_mat4(m1);
|
||||
test_rand_mat4(m2);
|
||||
|
||||
/* test inverse precise */
|
||||
GLM(mat4_inv)(m1, m2);
|
||||
GLM(mat4_inv)(m2, m3);
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m3))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_inv_precise) {
|
||||
mat4 m1, m2, m3;
|
||||
mat4 m4, m5, m6;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
test_rand_mat4(m1);
|
||||
test_rand_mat4(m2);
|
||||
|
||||
glm_mat4_inv_precise(m1, m2);
|
||||
glm_mat4_inv_precise(m2, m3);
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m3))
|
||||
|
||||
test_rand_mat4(m4);
|
||||
test_rand_mat4(m5);
|
||||
|
||||
glmc_mat4_inv_precise(m4, m5);
|
||||
glmc_mat4_inv_precise(m5, m6);
|
||||
ASSERTIFY(test_assert_mat4_eq(m4, m6))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_inv_fast) {
|
||||
mat4 m1, m2, m3;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 100000; i++) {
|
||||
test_rand_mat4(m1);
|
||||
test_rand_mat4(m2);
|
||||
|
||||
/* test inverse precise */
|
||||
GLM(mat4_inv_fast)(m1, m2);
|
||||
GLM(mat4_inv_fast)(m2, m3);
|
||||
ASSERTIFY(test_assert_mat4_eq2(m1, m3, 0.0009f))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_swap_col) {
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat4 m2 = A_MATRIX;
|
||||
|
||||
GLM(mat4_swap_col)(m1, 0, 1);
|
||||
GLM(mat4_swap_col)(m1, 2, 3);
|
||||
|
||||
ASSERTIFY(test_assert_vec4_eq(m1[0], m2[1]))
|
||||
ASSERTIFY(test_assert_vec4_eq(m1[1], m2[0]))
|
||||
ASSERTIFY(test_assert_vec4_eq(m1[2], m2[3]))
|
||||
ASSERTIFY(test_assert_vec4_eq(m1[3], m2[2]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_swap_row) {
|
||||
mat4 m1 = A_MATRIX;
|
||||
mat4 m2 = A_MATRIX;
|
||||
|
||||
GLM(mat4_swap_row)(m1, 0, 1);
|
||||
GLM(mat4_swap_row)(m1, 2, 3);
|
||||
|
||||
ASSERT(test_eq(m1[0][0], m2[0][1]))
|
||||
ASSERT(test_eq(m1[0][1], m2[0][0]))
|
||||
ASSERT(test_eq(m1[0][2], m2[0][3]))
|
||||
ASSERT(test_eq(m1[0][3], m2[0][2]))
|
||||
ASSERT(test_eq(m1[1][0], m2[1][1]))
|
||||
ASSERT(test_eq(m1[1][1], m2[1][0]))
|
||||
ASSERT(test_eq(m1[1][2], m2[1][3]))
|
||||
ASSERT(test_eq(m1[1][3], m2[1][2]))
|
||||
ASSERT(test_eq(m1[2][0], m2[2][1]))
|
||||
ASSERT(test_eq(m1[2][1], m2[2][0]))
|
||||
ASSERT(test_eq(m1[2][2], m2[2][3]))
|
||||
ASSERT(test_eq(m1[2][3], m2[2][2]))
|
||||
ASSERT(test_eq(m1[3][0], m2[3][1]))
|
||||
ASSERT(test_eq(m1[3][1], m2[3][0]))
|
||||
ASSERT(test_eq(m1[3][2], m2[3][3]))
|
||||
ASSERT(test_eq(m1[3][3], m2[3][2]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, mat4_rmc) {
|
||||
mat4 mat = A_MATRIX;
|
||||
vec4 v = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
vec4 v1;
|
||||
float r1, r2;
|
||||
int i;
|
||||
|
||||
r1 = GLM(mat4_rmc)(v, mat, v);
|
||||
|
||||
for (i = 0; i < 4; i++) {
|
||||
v1[i] = v[0] * mat[i][0]
|
||||
+ v[1] * mat[i][1]
|
||||
+ v[2] * mat[i][2]
|
||||
+ v[3] * mat[i][3];
|
||||
}
|
||||
|
||||
r2 = v[0] * v1[0] + v[1] * v1[1] + v[2] * v1[2] + v[3] * v1[3];
|
||||
|
||||
ASSERT(test_eq(r1, r2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
@@ -5,27 +5,22 @@
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
/* test inline project */
|
||||
|
||||
void
|
||||
test_project(void **state) {
|
||||
mat4 model, view, proj, mvp;
|
||||
vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f};
|
||||
vec3 pos = {13.0f, 45.0f, 0.74f};
|
||||
vec3 projected, unprojected;
|
||||
#define GLM_PREFIX glm_
|
||||
#define GLM(X) (glm_ ## X)
|
||||
|
||||
glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f});
|
||||
glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view);
|
||||
#include "test_project.h"
|
||||
|
||||
glm_perspective_default(0.5f, proj);
|
||||
glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp);
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
glmc_project(pos, mvp, viewport, projected);
|
||||
glmc_unproject(projected, mvp, viewport, unprojected);
|
||||
/* test pre-compiled project */
|
||||
|
||||
/* unprojected of projected vector must be same as original one */
|
||||
/* we used 0.01 because of projection floating point errors */
|
||||
assert_true(fabsf(pos[0] - unprojected[0]) < 0.01);
|
||||
assert_true(fabsf(pos[1] - unprojected[1]) < 0.01);
|
||||
assert_true(fabsf(pos[2] - unprojected[2]) < 0.01);
|
||||
}
|
||||
#define GLM_PREFIX glmc_
|
||||
#define GLM(X) (glmc_ ## X)
|
||||
|
||||
#include "test_project.h"
|
||||
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
92
test/src/test_project.h
Normal file
92
test/src/test_project.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, unprojecti) {
|
||||
mat4 model, view, proj, mvp;
|
||||
vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f};
|
||||
vec3 pos = {13.0f, 45.0f, 0.74f};
|
||||
vec3 projected, unprojected;
|
||||
|
||||
glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f});
|
||||
glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view);
|
||||
|
||||
glm_perspective_default(0.5f, proj);
|
||||
glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp);
|
||||
|
||||
GLM(project)(pos, mvp, viewport, projected);
|
||||
|
||||
glm_mat4_inv(mvp, mvp);
|
||||
GLM(unprojecti)(projected, mvp, viewport, unprojected);
|
||||
|
||||
/* unprojected of projected vector must be same as original one */
|
||||
/* we used 0.01 because of projection floating point errors */
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01)
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, unproject) {
|
||||
mat4 model, view, proj, mvp;
|
||||
vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f};
|
||||
vec3 pos = {13.0f, 45.0f, 0.74f};
|
||||
vec3 projected, unprojected;
|
||||
|
||||
glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f});
|
||||
glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view);
|
||||
|
||||
glm_perspective_default(0.5f, proj);
|
||||
glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp);
|
||||
|
||||
GLM(project)(pos, mvp, viewport, projected);
|
||||
GLM(unproject)(projected, mvp, viewport, unprojected);
|
||||
|
||||
/* unprojected of projected vector must be same as original one */
|
||||
/* we used 0.01 because of projection floating point errors */
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01)
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, project) {
|
||||
mat4 model, view, proj, mvp;
|
||||
vec4 viewport = {0.0f, 0.0f, 800.0f, 600.0f};
|
||||
vec3 pos = {13.0f, 45.0f, 0.74f};
|
||||
vec3 projected, unprojected;
|
||||
|
||||
glm_translate_make(model, (vec3){0.0f, 0.0f, -10.0f});
|
||||
glm_lookat((vec3){0.0f, 0.0f, 0.0f}, pos, GLM_YUP, view);
|
||||
|
||||
glm_perspective_default(0.5f, proj);
|
||||
glm_mat4_mulN((mat4 *[]){&proj, &view, &model}, 3, mvp);
|
||||
|
||||
GLM(project)(pos, mvp, viewport, projected);
|
||||
GLM(unproject)(projected, mvp, viewport, unprojected);
|
||||
|
||||
/* unprojected of projected vector must be same as original one */
|
||||
/* we used 0.01 because of projection floating point errors */
|
||||
ASSERT(fabsf(pos[0] - unprojected[0]) < 0.01)
|
||||
ASSERT(fabsf(pos[1] - unprojected[1]) < 0.01)
|
||||
ASSERT(fabsf(pos[2] - unprojected[2]) < 0.01)
|
||||
|
||||
/* test with no projection */
|
||||
glm_mat4_identity(mvp);
|
||||
|
||||
GLM(project)(pos, mvp, viewport, projected);
|
||||
GLM(unproject)(projected, mvp, viewport, unprojected);
|
||||
|
||||
ASSERT(test_eq(pos[0], unprojected[0]))
|
||||
ASSERT(test_eq(pos[1], unprojected[1]))
|
||||
ASSERT(test_eq(pos[2], unprojected[2]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
@@ -7,6 +7,26 @@
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
/* test inline quat */
|
||||
|
||||
#define GLM_PREFIX glm_
|
||||
#define GLM(X) (glm_ ## X)
|
||||
|
||||
#include "test_quat.h"
|
||||
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
/* test pre-compiled quat */
|
||||
|
||||
#define GLM_PREFIX glmc_
|
||||
#define GLM(X) (glmc_ ## X)
|
||||
|
||||
#include "test_quat.h"
|
||||
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
CGLM_INLINE
|
||||
void
|
||||
test_quat_mul_raw(versor p, versor q, versor dest) {
|
||||
@@ -16,8 +36,7 @@ test_quat_mul_raw(versor p, versor q, versor dest) {
|
||||
dest[3] = p[3] * q[3] - p[0] * q[0] - p[1] * q[1] - p[2] * q[2];
|
||||
}
|
||||
|
||||
void
|
||||
test_quat(void **state) {
|
||||
TEST_IMPL(quat) {
|
||||
mat4 inRot, outRot, view1, view2, rot1, rot2;
|
||||
versor inQuat, outQuat, q3, q4, q5;
|
||||
vec3 eye, axis, imag, v1, v2;
|
||||
@@ -25,9 +44,10 @@ test_quat(void **state) {
|
||||
|
||||
/* 0. test identiy quat */
|
||||
glm_quat_identity(q4);
|
||||
assert_true(glm_eq(glm_quat_real(q4), cosf(glm_rad(0.0f) * 0.5f)));
|
||||
ASSERT(test_eq(glm_quat_real(q4), cosf(glm_rad(0.0f) * 0.5f)))
|
||||
|
||||
glm_quat_mat4(q4, rot1);
|
||||
test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009);
|
||||
ASSERTIFY(test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009f))
|
||||
|
||||
/* 1. test quat to mat and mat to quat */
|
||||
for (i = 0; i < 1000; i++) {
|
||||
@@ -38,16 +58,17 @@ test_quat(void **state) {
|
||||
glmc_quat_mat4(outQuat, outRot);
|
||||
|
||||
/* 2. test first quat and generated one equality */
|
||||
test_assert_quat_eq_abs(inQuat, outQuat);
|
||||
ASSERTIFY(test_assert_quat_eq_abs(inQuat, outQuat));
|
||||
|
||||
/* 3. test first rot and second rotation */
|
||||
test_assert_mat4_eq2(inRot, outRot, 0.000009); /* almost equal */
|
||||
/* almost equal */
|
||||
ASSERTIFY(test_assert_mat4_eq2(inRot, outRot, 0.000009f));
|
||||
|
||||
/* 4. test SSE mul and raw mul */
|
||||
#if defined( __SSE__ ) || defined( __SSE2__ )
|
||||
test_quat_mul_raw(inQuat, outQuat, q3);
|
||||
glm_quat_mul_sse2(inQuat, outQuat, q4);
|
||||
test_assert_quat_eq(q3, q4);
|
||||
ASSERTIFY(test_assert_quat_eq(q3, q4));
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -61,7 +82,7 @@ test_quat(void **state) {
|
||||
/* create view matrix with quaternion */
|
||||
glm_quat_look(eye, q3, view2);
|
||||
|
||||
test_assert_mat4_eq2(view1, view2, 0.000009);
|
||||
ASSERTIFY(test_assert_mat4_eq2(view1, view2, 0.000009f));
|
||||
|
||||
/* 6. test quaternion rotation matrix result */
|
||||
test_rand_quat(q3);
|
||||
@@ -71,7 +92,7 @@ test_quat(void **state) {
|
||||
glm_quat_axis(q3, axis);
|
||||
glm_rotate_make(rot2, glm_quat_angle(q3), axis);
|
||||
|
||||
test_assert_mat4_eq2(rot1, rot2, 0.000009);
|
||||
ASSERTIFY(test_assert_mat4_eq2(rot1, rot2, 0.000009f));
|
||||
|
||||
/* 7. test quaternion multiplication (hamilton product),
|
||||
final rotation = first rotation + second = quat1 * quat2
|
||||
@@ -91,7 +112,7 @@ test_quat(void **state) {
|
||||
glm_quat_mat4(q5, rot2);
|
||||
|
||||
/* result must be same (almost) */
|
||||
test_assert_mat4_eq2(rot1, rot2, 0.000009);
|
||||
ASSERTIFY(test_assert_mat4_eq2(rot1, rot2, 0.000009f))
|
||||
|
||||
/* 8. test quaternion for look rotation */
|
||||
|
||||
@@ -101,26 +122,26 @@ test_quat(void **state) {
|
||||
|
||||
/* result must be identity */
|
||||
glm_quat_identity(q4);
|
||||
test_assert_quat_eq(q3, q4);
|
||||
ASSERTIFY(test_assert_quat_eq(q3, q4))
|
||||
|
||||
/* look at from 0, 0, 1 to zero, direction = 0, 0, -1 */
|
||||
glm_quat_forp(GLM_ZUP, GLM_VEC3_ZERO, (vec3){0, 0, -1}, GLM_YUP, q3);
|
||||
|
||||
/* result must be identity */
|
||||
glm_quat_identity(q4);
|
||||
test_assert_quat_eq(q3, q4);
|
||||
ASSERTIFY(test_assert_quat_eq(q3, q4))
|
||||
|
||||
/* 8.2 perpendicular */
|
||||
glm_quat_for(GLM_XUP, (vec3){0, 0, -1}, GLM_YUP, q3);
|
||||
|
||||
/* result must be -90 */
|
||||
glm_quatv(q4, glm_rad(-90.0f), GLM_YUP);
|
||||
test_assert_quat_eq(q3, q4);
|
||||
ASSERTIFY(test_assert_quat_eq(q3, q4))
|
||||
|
||||
/* 9. test imag, real */
|
||||
|
||||
/* 9.1 real */
|
||||
assert_true(glm_eq(glm_quat_real(q4), cosf(glm_rad(-90.0f) * 0.5f)));
|
||||
ASSERT(test_eq(glm_quat_real(q4), cosf(glm_rad(-90.0f) * 0.5f)))
|
||||
|
||||
/* 9.1 imag */
|
||||
glm_quat_imag(q4, imag);
|
||||
@@ -130,7 +151,7 @@ test_quat(void **state) {
|
||||
axis[1] = sinf(glm_rad(-90.0f) * 0.5f) * 1.0f;
|
||||
axis[2] = 0.0f;
|
||||
|
||||
assert_true(glm_vec3_eqv_eps(imag, axis));
|
||||
ASSERT(glm_vec3_eqv_eps(imag, axis));
|
||||
|
||||
/* 9.2 axis */
|
||||
glm_quat_axis(q4, axis);
|
||||
@@ -138,7 +159,7 @@ test_quat(void **state) {
|
||||
imag[1] = -1.0f;
|
||||
imag[2] = 0.0f;
|
||||
|
||||
test_assert_vec3_eq(imag, axis);
|
||||
ASSERTIFY(test_assert_vec3_eq(imag, axis));
|
||||
|
||||
/* 10. test rotate vector using quat */
|
||||
/* (0,0,-1) around (1,0,0) must give (0,1,0) */
|
||||
@@ -152,11 +173,11 @@ test_quat(void **state) {
|
||||
glm_quat_rotatev(q3, v2, v2);
|
||||
|
||||
/* result must be : (0,1,0) */
|
||||
assert_true(fabsf(v1[0]) <= 0.00009f
|
||||
&& fabsf(v1[1] - 1.0f) <= 0.00009f
|
||||
&& fabsf(v1[2]) <= 0.00009f);
|
||||
ASSERT(fabsf(v1[0]) <= 0.00009f
|
||||
&& fabsf(v1[1] - 1.0f) <= 0.00009f
|
||||
&& fabsf(v1[2]) <= 0.00009f)
|
||||
|
||||
test_assert_vec3_eq(v1, v2);
|
||||
ASSERTIFY(test_assert_vec3_eq(v1, v2))
|
||||
|
||||
/* 11. test rotate transform */
|
||||
glm_translate_make(rot1, (vec3){-10.0, 45.0f, 8.0f});
|
||||
@@ -167,7 +188,7 @@ test_quat(void **state) {
|
||||
glm_quat_rotate(rot2, q3, rot2);
|
||||
|
||||
/* result must be same (almost) */
|
||||
test_assert_mat4_eq2(rot1, rot2, 0.000009);
|
||||
ASSERTIFY(test_assert_mat4_eq2(rot1, rot2, 0.000009f))
|
||||
|
||||
glm_rotate_make(rot1, glm_rad(-90), GLM_ZUP);
|
||||
glm_translate(rot1, (vec3){-10.0, 45.0f, 8.0f});
|
||||
@@ -178,7 +199,7 @@ test_quat(void **state) {
|
||||
glm_translate(rot2, (vec3){-10.0, 45.0f, 8.0f});
|
||||
|
||||
/* result must be same (almost) */
|
||||
test_assert_mat4_eq2(rot1, rot2, 0.000009);
|
||||
ASSERTIFY(test_assert_mat4_eq2(rot1, rot2, 0.000009f))
|
||||
|
||||
/* reverse */
|
||||
glm_rotate_make(rot1, glm_rad(-90), GLM_ZUP);
|
||||
@@ -186,7 +207,7 @@ test_quat(void **state) {
|
||||
glm_quat_rotate(rot1, q3, rot1);
|
||||
|
||||
/* result must be identity */
|
||||
test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009);
|
||||
ASSERTIFY(test_assert_mat4_eq2(rot1, GLM_MAT4_IDENTITY, 0.000009f))
|
||||
|
||||
test_rand_quat(q3);
|
||||
|
||||
@@ -195,7 +216,9 @@ test_quat(void **state) {
|
||||
glm_quat_mul(q3, q4, q5);
|
||||
|
||||
glm_quat_identity(q3);
|
||||
test_assert_quat_eq(q3, q5);
|
||||
ASSERTIFY(test_assert_quat_eq(q3, q5))
|
||||
|
||||
/* TODO: add tests for slerp, lerp */
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
762
test/src/test_quat.h
Normal file
762
test/src/test_quat.h
Normal file
@@ -0,0 +1,762 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
#ifndef CGLM_TEST_QUAT_ONCE
|
||||
#define CGLM_TEST_QUAT_ONCE
|
||||
|
||||
/* Macros */
|
||||
|
||||
TEST_IMPL(MACRO_GLM_QUAT_IDENTITY_INIT) {
|
||||
versor v = GLM_QUAT_IDENTITY_INIT;
|
||||
|
||||
ASSERT(test_eq(v[0], 0.0f))
|
||||
ASSERT(test_eq(v[1], 0.0f))
|
||||
ASSERT(test_eq(v[2], 0.0f))
|
||||
ASSERT(test_eq(v[3], 1.0f))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(MACRO_GLM_QUAT_IDENTITY) {
|
||||
ASSERT(test_eq(GLM_QUAT_IDENTITY[0], 0.0f))
|
||||
ASSERT(test_eq(GLM_QUAT_IDENTITY[1], 0.0f))
|
||||
ASSERT(test_eq(GLM_QUAT_IDENTITY[2], 0.0f))
|
||||
ASSERT(test_eq(GLM_QUAT_IDENTITY[3], 1.0f))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
#endif /* CGLM_TEST_QUAT_ONCE */
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_identity) {
|
||||
versor a = GLM_QUAT_IDENTITY_INIT;
|
||||
versor b = GLM_QUAT_IDENTITY_INIT;
|
||||
versor c;
|
||||
mat4 r;
|
||||
|
||||
GLM(quat_identity)(c);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq_identity(a))
|
||||
ASSERTIFY(test_assert_quat_eq_identity(b))
|
||||
ASSERTIFY(test_assert_quat_eq_identity(c))
|
||||
|
||||
glm_quat_identity(c);
|
||||
ASSERT(test_eq(glm_quat_real(c), cosf(glm_rad(0.0f) * 0.5f)))
|
||||
|
||||
glm_quat_mat4(c, r);
|
||||
ASSERTIFY(test_assert_mat4_eq2(r, GLM_MAT4_IDENTITY, 0.000009f))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_identity_array) {
|
||||
int i, count;
|
||||
versor quats[4] = {
|
||||
{1.0f, 2.0f, 3.0f, 4.0f},
|
||||
{1.0f, 2.0f, 3.0f, 4.0f},
|
||||
{1.0f, 2.0f, 3.0f, 4.0f},
|
||||
{1.0f, 2.0f, 3.0f, 4.0f},
|
||||
};
|
||||
|
||||
count = 4;
|
||||
|
||||
GLM(quat_identity_array)(quats, count);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
ASSERTIFY(test_assert_quat_eq_identity(quats[i]))
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_init) {
|
||||
versor q1 = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
versor q2 = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
versor q3 = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
|
||||
GLM(quat_init)(q1, 10.0f, 11.0f, 12.0f, 13.0f);
|
||||
GLM(quat_init)(q2, 100.0f, 110.0f, 120.0f, 130.0f);
|
||||
GLM(quat_init)(q3, 1000.0f, 1100.0f, 1200.0f, 1300.0f);
|
||||
|
||||
ASSERT(q1[0] == 10.0f)
|
||||
ASSERT(q1[1] == 11.0f)
|
||||
ASSERT(q1[2] == 12.0f)
|
||||
ASSERT(q1[3] == 13.0f)
|
||||
|
||||
ASSERT(q2[0] == 100.0f)
|
||||
ASSERT(q2[1] == 110.0f)
|
||||
ASSERT(q2[2] == 120.0f)
|
||||
ASSERT(q2[3] == 130.0f)
|
||||
|
||||
ASSERT(q3[0] == 1000.0f)
|
||||
ASSERT(q3[1] == 1100.0f)
|
||||
ASSERT(q3[2] == 1200.0f)
|
||||
ASSERT(q3[3] == 1300.0f)
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quatv) {
|
||||
versor q1 = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
vec3 v1, v2;
|
||||
float a1;
|
||||
|
||||
test_rand_vec3(v1);
|
||||
GLM(quatv)(q1, glm_rad(60.0f), v1);
|
||||
|
||||
glm_quat_axis(q1, v2);
|
||||
a1 = glm_quat_angle(q1);
|
||||
|
||||
ASSERT(test_eq(a1, glm_rad(60.0f)))
|
||||
|
||||
glm_vec3_normalize(v1);
|
||||
ASSERTIFY(test_assert_vec3_eq(v1, v2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat) {
|
||||
versor q1 = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
vec3 v1, v2;
|
||||
float a1;
|
||||
|
||||
test_rand_vec3(v1);
|
||||
GLM(quat)(q1, glm_rad(60.0f), v1[0], v1[1], v1[2]);
|
||||
|
||||
glm_quat_axis(q1, v2);
|
||||
a1 = glm_quat_angle(q1);
|
||||
|
||||
ASSERT(test_eq(a1, glm_rad(60.0f)))
|
||||
|
||||
glm_vec3_normalize(v1);
|
||||
ASSERTIFY(test_assert_vec3_eq(v1, v2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_copy) {
|
||||
versor v1 = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
versor v2 = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
|
||||
GLM(quat_copy)(v1, v2);
|
||||
|
||||
ASSERTIFY(test_assert_vec4_eq(v1, v2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_norm) {
|
||||
versor a = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
float n1, n2;
|
||||
|
||||
n1 = GLM(quat_norm)(a);
|
||||
n2 = sqrtf(a[0] * a[0] + a[1] * a[1] + a[2] * a[2] + a[3] * a[3]);
|
||||
|
||||
ASSERT(test_eq(n1, n2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_normalize_to) {
|
||||
versor v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2;
|
||||
float s = 1.0f;
|
||||
float norm;
|
||||
|
||||
GLM(quat_normalize_to)(v1, v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]);
|
||||
if (norm <= 0.0f) {
|
||||
ASSERTIFY(test_assert_quat_eq_identity(v1))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
norm = s / norm;
|
||||
|
||||
ASSERT(test_eq(v1[0] * norm, v2[0]))
|
||||
ASSERT(test_eq(v1[1] * norm, v2[1]))
|
||||
ASSERT(test_eq(v1[2] * norm, v2[2]))
|
||||
ASSERT(test_eq(v1[3] * norm, v2[3]))
|
||||
|
||||
glm_vec4_zero(v1);
|
||||
GLM(quat_normalize_to)(v1, v2);
|
||||
ASSERTIFY(test_assert_quat_eq_identity(v2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_normalize) {
|
||||
versor v1 = {2.0f, -3.0f, 4.0f, 5.0f}, v2 = {2.0f, -3.0f, 4.0f, 5.0f};
|
||||
float s = 1.0f;
|
||||
float norm;
|
||||
|
||||
GLM(quat_normalize)(v2);
|
||||
|
||||
norm = sqrtf(v1[0] * v1[0] + v1[1] * v1[1] + v1[2] * v1[2] + v1[3] * v1[3]);
|
||||
if (norm <= 0.0f) {
|
||||
ASSERTIFY(test_assert_quat_eq_identity(v1))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
norm = s / norm;
|
||||
|
||||
ASSERT(test_eq(v1[0] * norm, v2[0]))
|
||||
ASSERT(test_eq(v1[1] * norm, v2[1]))
|
||||
ASSERT(test_eq(v1[2] * norm, v2[2]))
|
||||
ASSERT(test_eq(v1[3] * norm, v2[3]))
|
||||
|
||||
glm_vec4_zero(v1);
|
||||
GLM(quat_normalize)(v1);
|
||||
ASSERTIFY(test_assert_quat_eq_identity(v1))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_dot) {
|
||||
versor a = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
versor b = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
float dot1, dot2;
|
||||
|
||||
dot1 = GLM(quat_dot)(a, b);
|
||||
dot2 = a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
||||
|
||||
ASSERT(test_eq(dot1, dot2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_conjugate) {
|
||||
versor a = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
versor b = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
versor d, e;
|
||||
|
||||
GLM(quat_conjugate)(a, d);
|
||||
GLM(quat_conjugate)(b, e);
|
||||
|
||||
ASSERT(test_eq(d[0], -a[0]))
|
||||
ASSERT(test_eq(d[1], -a[1]))
|
||||
ASSERT(test_eq(d[2], -a[2]))
|
||||
ASSERT(test_eq(d[3], a[3]))
|
||||
|
||||
ASSERT(test_eq(e[0], -b[0]))
|
||||
ASSERT(test_eq(e[1], -b[1]))
|
||||
ASSERT(test_eq(e[2], -b[2]))
|
||||
ASSERT(test_eq(e[3], b[3]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_inv) {
|
||||
versor a = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
versor b = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
versor d, e;
|
||||
float n1, n2;
|
||||
|
||||
n1 = 1.0f / glm_vec4_norm2(a);
|
||||
n2 = 1.0f / glm_vec4_norm2(b);
|
||||
|
||||
GLM(quat_inv)(a, d);
|
||||
GLM(quat_inv)(b, e);
|
||||
|
||||
ASSERT(test_eq(d[0], -a[0] * n1))
|
||||
ASSERT(test_eq(d[1], -a[1] * n1))
|
||||
ASSERT(test_eq(d[2], -a[2] * n1))
|
||||
ASSERT(test_eq(d[3], a[3] * n1))
|
||||
|
||||
ASSERT(test_eq(e[0], -b[0] * n2))
|
||||
ASSERT(test_eq(e[1], -b[1] * n2))
|
||||
ASSERT(test_eq(e[2], -b[2] * n2))
|
||||
ASSERT(test_eq(e[3], b[3] * n2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_add) {
|
||||
versor a = {-10.0f, 9.0f, -8.0f, 56.0f};
|
||||
versor b = {12.0f, 19.0f, -18.0f, 1.0f};
|
||||
versor c, d;
|
||||
|
||||
c[0] = a[0] + b[0];
|
||||
c[1] = a[1] + b[1];
|
||||
c[2] = a[2] + b[2];
|
||||
c[3] = a[3] + b[3];
|
||||
|
||||
GLM(quat_add)(a, b, d);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(c, d))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_sub) {
|
||||
vec4 a = {-10.0f, 9.0f, -8.0f, 56.0f};
|
||||
vec4 b = {12.0f, 19.0f, -18.0f, 1.0f};
|
||||
vec4 c, d;
|
||||
|
||||
c[0] = a[0] - b[0];
|
||||
c[1] = a[1] - b[1];
|
||||
c[2] = a[2] - b[2];
|
||||
c[3] = a[3] - b[3];
|
||||
|
||||
GLM(quat_sub)(a, b, d);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(c, d))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_real) {
|
||||
versor a = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
versor b = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
|
||||
ASSERT(test_eq(GLM(quat_real)(a), 78.0f))
|
||||
ASSERT(test_eq(GLM(quat_real)(b), 4.0f))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_imag) {
|
||||
versor a = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
versor b = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
vec3 d, e;
|
||||
|
||||
GLM(quat_imag)(a, d);
|
||||
GLM(quat_imag)(b, e);
|
||||
|
||||
ASSERT(test_eq(d[0], a[0]))
|
||||
ASSERT(test_eq(d[1], a[1]))
|
||||
ASSERT(test_eq(d[2], a[2]))
|
||||
|
||||
ASSERT(test_eq(e[0], b[0]))
|
||||
ASSERT(test_eq(e[1], b[1]))
|
||||
ASSERT(test_eq(e[2], b[2]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_imagn) {
|
||||
versor a = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
versor b = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
vec3 d, e;
|
||||
|
||||
GLM(quat_imagn)(a, d);
|
||||
GLM(quat_imagn)(b, e);
|
||||
|
||||
glm_vec3_normalize(a);
|
||||
glm_vec3_normalize(b);
|
||||
glm_vec3_normalize(d);
|
||||
glm_vec3_normalize(e);
|
||||
|
||||
ASSERT(test_eq(d[0], a[0]))
|
||||
ASSERT(test_eq(d[1], a[1]))
|
||||
ASSERT(test_eq(d[2], a[2]))
|
||||
|
||||
ASSERT(test_eq(e[0], b[0]))
|
||||
ASSERT(test_eq(e[1], b[1]))
|
||||
ASSERT(test_eq(e[2], b[2]))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_imaglen) {
|
||||
versor a = {10.0f, 9.0f, 8.0f, 78.0f};
|
||||
versor b = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
|
||||
ASSERT(test_eq(GLM(quat_imaglen)(a), glm_vec3_norm(a)));
|
||||
ASSERT(test_eq(GLM(quat_imaglen)(b), glm_vec3_norm(b)));
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_angle) {
|
||||
versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}, q2, q3;
|
||||
vec3 v1;
|
||||
float a1, a2, a3;
|
||||
|
||||
test_rand_vec3(v1);
|
||||
GLM(quatv)(q1, glm_rad(60.140f), v1);
|
||||
GLM(quatv)(q2, glm_rad(160.04f), v1);
|
||||
GLM(quatv)(q3, glm_rad(20.350f), v1);
|
||||
|
||||
a1 = GLM(quat_angle)(q1);
|
||||
a2 = GLM(quat_angle)(q2);
|
||||
a3 = GLM(quat_angle)(q3);
|
||||
|
||||
ASSERT(test_eq(a1, glm_rad(60.140f)))
|
||||
ASSERT(test_eq(a2, glm_rad(160.04f)))
|
||||
ASSERT(test_eq(a3, glm_rad(20.350f)))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_axis) {
|
||||
versor q1 = {1.0f, 2.0f, 3.0f, 4.0f}, q2, q3;
|
||||
vec3 v1, v2;
|
||||
|
||||
test_rand_vec3(v1);
|
||||
GLM(quatv)(q1, glm_rad(60.0f), v1);
|
||||
|
||||
glm_quat_axis(q1, v2);
|
||||
glm_vec3_normalize(v1);
|
||||
ASSERTIFY(test_assert_vec3_eq(v1, v2))
|
||||
|
||||
test_rand_vec3(v1);
|
||||
GLM(quatv)(q2, glm_rad(60.0f), v1);
|
||||
|
||||
glm_quat_axis(q2, v2);
|
||||
glm_vec3_normalize(v1);
|
||||
ASSERTIFY(test_assert_vec3_eq(v1, v2))
|
||||
|
||||
test_rand_vec3(v1);
|
||||
GLM(quatv)(q3, glm_rad(60.0f), v1);
|
||||
|
||||
glm_quat_axis(q3, v2);
|
||||
glm_vec3_normalize(v1);
|
||||
ASSERTIFY(test_assert_vec3_eq(v1, v2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_mul) {
|
||||
versor q1 = {2.0f, 3.0f, 4.0f, 5.0f};
|
||||
versor q2 = {6.0f, 7.0f, 8.0f, 9.0f};
|
||||
versor q3;
|
||||
versor q4;
|
||||
vec3 v1 = {1.5f, 2.5f, 3.5f};
|
||||
|
||||
GLM(quat_mul)(q1, q2, q3);
|
||||
|
||||
ASSERT(test_eq(q3[0], q1[3] * q2[0] + q1[0] * q2[3] + q1[1] * q2[2] - q1[2] * q2[1]))
|
||||
ASSERT(test_eq(q3[1], q1[3] * q2[1] - q1[0] * q2[2] + q1[1] * q2[3] + q1[2] * q2[0]))
|
||||
ASSERT(test_eq(q3[2], q1[3] * q2[2] + q1[0] * q2[1] - q1[1] * q2[0] + q1[2] * q2[3]))
|
||||
ASSERT(test_eq(q3[3], q1[3] * q2[3] - q1[0] * q2[0] - q1[1] * q2[1] - q1[2] * q2[2]))
|
||||
|
||||
glm_quatv(q1, glm_rad(30.0f), v1);
|
||||
glm_quatv(q2, glm_rad(20.0f), v1);
|
||||
glm_quatv(q3, glm_rad(50.0f), v1);
|
||||
|
||||
GLM(quat_mul)(q1, q2, q4);
|
||||
|
||||
ASSERTIFY(test_assert_quat_eq(q3, q4))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_mat4) {
|
||||
mat4 m1, m2;
|
||||
versor q1, q2, q3;
|
||||
vec3 axis1;
|
||||
vec3 axis2 = {1.9f, 2.3f, 4.5f};
|
||||
int i;
|
||||
|
||||
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
|
||||
GLM(quat_mat4)(q1, m1);
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
|
||||
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
|
||||
GLM(mat4_quat)(m1, q3);
|
||||
|
||||
GLM(quat_axis)(q3, axis1);
|
||||
|
||||
GLM(vec3_normalize)(axis1);
|
||||
GLM(vec3_normalize)(axis2);
|
||||
|
||||
ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f))
|
||||
ASSERTIFY(test_assert_vec3_eq(axis1, axis2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q2))
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q3))
|
||||
|
||||
/* 1. test quat to mat and mat to quat */
|
||||
for (i = 0; i < 1000; i++) {
|
||||
test_rand_quat(q1);
|
||||
|
||||
GLM(quat_mat4)(q1, m1);
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
GLM(quat_mat4)(q2, m2);
|
||||
|
||||
/* 2. test first quat and generated one equality */
|
||||
ASSERTIFY(test_assert_quat_eq_abs(q1, q2));
|
||||
|
||||
/* 3. test first rot and second rotation */
|
||||
/* almost equal */
|
||||
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f));
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_mat4t) {
|
||||
mat4 m1, m2;
|
||||
versor q1, q2, q3;
|
||||
vec3 axis1;
|
||||
vec3 axis2 = {1.9f, 2.3f, 4.5f};
|
||||
int i;
|
||||
|
||||
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
|
||||
|
||||
GLM(quat_mat4t)(q1, m1);
|
||||
glm_mat4_transpose(m1);
|
||||
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
|
||||
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
|
||||
GLM(mat4_quat)(m1, q3);
|
||||
|
||||
GLM(quat_axis)(q3, axis1);
|
||||
|
||||
GLM(vec3_normalize)(axis1);
|
||||
GLM(vec3_normalize)(axis2);
|
||||
|
||||
ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f))
|
||||
ASSERTIFY(test_assert_vec3_eq(axis1, axis2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q2))
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q3))
|
||||
|
||||
/* 1. test quat to mat and mat to quat */
|
||||
for (i = 0; i < 1000; i++) {
|
||||
test_rand_quat(q1);
|
||||
|
||||
GLM(quat_mat4t)(q1, m1);
|
||||
glm_mat4_transpose(m1);
|
||||
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
|
||||
GLM(quat_mat4t)(q2, m2);
|
||||
glm_mat4_transpose(m2);
|
||||
|
||||
/* 2. test first quat and generated one equality */
|
||||
ASSERTIFY(test_assert_quat_eq_abs(q1, q2));
|
||||
|
||||
/* 3. test first rot and second rotation */
|
||||
/* almost equal */
|
||||
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f));
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_mat3) {
|
||||
mat4 m1, m2;
|
||||
mat3 m3;
|
||||
versor q1, q2, q3;
|
||||
vec3 axis1;
|
||||
vec3 axis2 = {1.9f, 2.3f, 4.5f};
|
||||
int i;
|
||||
|
||||
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
|
||||
GLM(quat_mat3)(q1, m3);
|
||||
glm_mat4_identity(m1);
|
||||
glm_mat4_ins3(m3, m1);
|
||||
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
|
||||
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
|
||||
GLM(mat4_quat)(m1, q3);
|
||||
|
||||
GLM(quat_axis)(q3, axis1);
|
||||
|
||||
GLM(vec3_normalize)(axis1);
|
||||
GLM(vec3_normalize)(axis2);
|
||||
|
||||
ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f))
|
||||
ASSERTIFY(test_assert_vec3_eq(axis1, axis2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q2))
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q3))
|
||||
|
||||
/* 1. test quat to mat and mat to quat */
|
||||
for (i = 0; i < 1000; i++) {
|
||||
test_rand_quat(q1);
|
||||
|
||||
GLM(quat_mat3)(q1, m3);
|
||||
glm_mat4_identity(m1);
|
||||
glm_mat4_ins3(m3, m1);
|
||||
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
|
||||
GLM(quat_mat3)(q2, m3);
|
||||
glm_mat4_identity(m2);
|
||||
glm_mat4_ins3(m3, m2);
|
||||
|
||||
/* 2. test first quat and generated one equality */
|
||||
ASSERTIFY(test_assert_quat_eq_abs(q1, q2));
|
||||
|
||||
/* 3. test first rot and second rotation */
|
||||
/* almost equal */
|
||||
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f));
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_mat3t) {
|
||||
mat4 m1, m2;
|
||||
mat3 m3;
|
||||
versor q1, q2, q3;
|
||||
vec3 axis1;
|
||||
vec3 axis2 = {1.9f, 2.3f, 4.5f};
|
||||
int i;
|
||||
|
||||
GLM(quat)(q1, GLM_PI_4f, 1.9f, 2.3f, 4.5f);
|
||||
|
||||
GLM(quat_mat3t)(q1, m3);
|
||||
glm_mat3_transpose(m3);
|
||||
glm_mat4_identity(m1);
|
||||
glm_mat4_ins3(m3, m1);
|
||||
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
|
||||
GLM(rotate_make)(m2, GLM_PI_4f, axis2);
|
||||
GLM(mat4_quat)(m1, q3);
|
||||
|
||||
GLM(quat_axis)(q3, axis1);
|
||||
|
||||
GLM(vec3_normalize)(axis1);
|
||||
GLM(vec3_normalize)(axis2);
|
||||
|
||||
ASSERT(test_eq(glm_quat_angle(q3), GLM_PI_4f))
|
||||
ASSERTIFY(test_assert_vec3_eq(axis1, axis2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q2))
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m2))
|
||||
ASSERTIFY(test_assert_vec4_eq(q1, q3))
|
||||
|
||||
/* 1. test quat to mat and mat to quat */
|
||||
for (i = 0; i < 1000; i++) {
|
||||
test_rand_quat(q1);
|
||||
|
||||
GLM(quat_mat3t)(q1, m3);
|
||||
glm_mat3_transpose(m3);
|
||||
glm_mat4_identity(m1);
|
||||
glm_mat4_ins3(m3, m1);
|
||||
|
||||
GLM(mat4_quat)(m1, q2);
|
||||
|
||||
GLM(quat_mat3t)(q2, m3);
|
||||
glm_mat3_transpose(m3);
|
||||
glm_mat4_identity(m2);
|
||||
glm_mat4_ins3(m3, m2);
|
||||
|
||||
/* 2. test first quat and generated one equality */
|
||||
ASSERTIFY(test_assert_quat_eq_abs(q1, q2));
|
||||
|
||||
/* 3. test first rot and second rotation */
|
||||
/* almost equal */
|
||||
ASSERTIFY(test_assert_mat4_eq2(m1, m2, 0.000009f));
|
||||
}
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_lerp) {
|
||||
versor v1 = {-100.0f, -200.0f, -10.0f, -10.0f};
|
||||
versor v2 = {100.0f, 200.0f, 10.0f, 10.0f};
|
||||
versor v3;
|
||||
|
||||
GLM(quat_lerp)(v1, v2, 0.5f, v3);
|
||||
ASSERT(test_eq(v3[0], 0.0f))
|
||||
ASSERT(test_eq(v3[1], 0.0f))
|
||||
ASSERT(test_eq(v3[2], 0.0f))
|
||||
ASSERT(test_eq(v3[3], 0.0f))
|
||||
|
||||
GLM(quat_lerp)(v1, v2, 0.75f, v3);
|
||||
ASSERT(test_eq(v3[0], 50.0f))
|
||||
ASSERT(test_eq(v3[1], 100.0f))
|
||||
ASSERT(test_eq(v3[2], 5.0f))
|
||||
ASSERT(test_eq(v3[3], 5.0f))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_lerpc) {
|
||||
versor v1 = {-100.0f, -200.0f, -10.0f, -10.0f};
|
||||
versor v2 = {100.0f, 200.0f, 10.0f, 10.0f};
|
||||
versor v3;
|
||||
|
||||
GLM(quat_lerpc)(v1, v2, 0.5f, v3);
|
||||
ASSERT(test_eq(v3[0], 0.0f))
|
||||
ASSERT(test_eq(v3[1], 0.0f))
|
||||
ASSERT(test_eq(v3[2], 0.0f))
|
||||
ASSERT(test_eq(v3[3], 0.0f))
|
||||
|
||||
GLM(quat_lerpc)(v1, v2, 0.75f, v3);
|
||||
ASSERT(test_eq(v3[0], 50.0f))
|
||||
ASSERT(test_eq(v3[1], 100.0f))
|
||||
ASSERT(test_eq(v3[2], 5.0f))
|
||||
ASSERT(test_eq(v3[3], 5.0f))
|
||||
|
||||
GLM(quat_lerpc)(v1, v2, -1.75f, v3);
|
||||
ASSERT(test_eq(v3[0], -100.0f))
|
||||
ASSERT(test_eq(v3[1], -200.0f))
|
||||
ASSERT(test_eq(v3[2], -10.0f))
|
||||
ASSERT(test_eq(v3[3], -10.0f))
|
||||
|
||||
GLM(quat_lerpc)(v1, v2, 1.75f, v3);
|
||||
ASSERT(test_eq(v3[0], 100.0f))
|
||||
ASSERT(test_eq(v3[1], 200.0f))
|
||||
ASSERT(test_eq(v3[2], 10.0f))
|
||||
ASSERT(test_eq(v3[3], 10.0f))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_slerp) {
|
||||
versor q1, q2, q3, q4;
|
||||
vec3 v1 = {10.0f, 0.0f, 0.0f}, v2;
|
||||
|
||||
glm_quatv(q1, glm_rad(30.0f), v1);
|
||||
glm_quatv(q2, glm_rad(90.0f), v1);
|
||||
|
||||
q1[0] = 10.0f;
|
||||
GLM(quat_slerp)(q1, q2, 1.0f, q3);
|
||||
ASSERTIFY(test_assert_quat_eq(q1, q3));
|
||||
|
||||
glm_quatv(q1, glm_rad(30.001f), v1);
|
||||
glm_quatv(q2, glm_rad(30.002f), v1);
|
||||
GLM(quat_slerp)(q1, q2, 0.7f, q3);
|
||||
glm_quat_lerp(q1, q2, 0.7f, q4);
|
||||
ASSERTIFY(test_assert_quat_eq(q3, q4));
|
||||
|
||||
glm_quatv(q1, glm_rad(30.0f), v1);
|
||||
glm_quatv(q2, glm_rad(90.0f), v1);
|
||||
GLM(quat_slerp)(q1, q2, 0.5f, q3);
|
||||
|
||||
glm_quat_axis(q3, v2);
|
||||
glm_vec3_normalize(v1);
|
||||
glm_vec3_normalize(v2);
|
||||
|
||||
ASSERT(glm_quat_angle(q3) > glm_rad(30.0f));
|
||||
ASSERT(glm_quat_angle(q3) < glm_rad(90.0f));
|
||||
ASSERTIFY(test_assert_vec3_eq(v1, v2))
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(GLM_PREFIX, quat_look) {
|
||||
versor q1;
|
||||
vec3 v1 = {0.0f, 1.0f, 0.0f};
|
||||
mat4 m1, m2;
|
||||
|
||||
glm_quat(q1, glm_rad(90.0f), 0.0f, 1.0f, 0.0f);
|
||||
GLM(quat_look)(v1, q1, m1);
|
||||
|
||||
glm_look(v1, (vec3){-1.0f, 0.0f, 0.0f}, GLM_YUP, m2);
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m2));
|
||||
|
||||
glm_quat(q1, glm_rad(180.0f), 1.0f, 0.0f, 0.0f);
|
||||
GLM(quat_look)(v1, q1, m1);
|
||||
|
||||
glm_look(v1, (vec3){0.0f, 0.0f, 1.0f}, (vec3){0.0f, -1.0f, 0.0f}, m2);
|
||||
|
||||
ASSERTIFY(test_assert_mat4_eq(m1, m2));
|
||||
|
||||
TEST_SUCCESS
|
||||
}
|
||||
78
test/src/test_struct.c
Normal file
78
test/src/test_struct.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
*
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
|
||||
TEST_IMPL(mat3s_identity_init) {
|
||||
mat3s mat3_identity = GLMS_MAT3_IDENTITY_INIT;
|
||||
mat3 mat3_identity_a = GLM_MAT3_IDENTITY_INIT;
|
||||
test_assert_mat3_eq(mat3_identity.raw, mat3_identity_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(mat3s_zero_init) {
|
||||
mat3s mat3_zero = GLMS_MAT3_ZERO_INIT;
|
||||
mat3 mat3_zero_a = GLM_MAT3_ZERO_INIT;
|
||||
test_assert_mat3_eq(mat3_zero.raw, mat3_zero_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(mat4s_identity_init) {
|
||||
mat4s mat4_identity = GLMS_MAT4_IDENTITY_INIT;
|
||||
mat4 mat4_identity_a = GLM_MAT4_IDENTITY_INIT;
|
||||
test_assert_mat4_eq(mat4_identity.raw, mat4_identity_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(mat4s_zero_init) {
|
||||
mat4s mat4_zero = GLMS_MAT4_ZERO_INIT;
|
||||
mat4 mat4_zero_a = GLM_MAT4_ZERO_INIT;
|
||||
test_assert_mat4_eq(mat4_zero.raw, mat4_zero_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(quats_zero_init) {
|
||||
versors quat_zero = GLMS_QUAT_IDENTITY_INIT;
|
||||
versor quat_zero_a = GLM_QUAT_IDENTITY_INIT;
|
||||
test_assert_quat_eq(quat_zero.raw, quat_zero_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(vec3s_one_init) {
|
||||
vec3s vec3_one = GLMS_VEC3_ONE_INIT;
|
||||
vec3 vec3_one_a = GLM_VEC3_ONE_INIT;
|
||||
test_assert_vec3_eq(vec3_one.raw, vec3_one_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(vec3s_zero_init) {
|
||||
vec3s vec3_zero = GLMS_VEC3_ZERO_INIT;
|
||||
vec3 vec3_zero_a = GLM_VEC3_ZERO_INIT;
|
||||
test_assert_vec3_eq(vec3_zero.raw, vec3_zero_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(vec4s_black_init) {
|
||||
vec4s vec4_black = GLMS_VEC4_BLACK_INIT;
|
||||
vec4 vec4_black_a = GLM_VEC4_BLACK_INIT;
|
||||
test_assert_vec4_eq(vec4_black.raw, vec4_black_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(vec4s_one_init) {
|
||||
vec4s vec4_one = GLMS_VEC4_ONE_INIT;
|
||||
vec4 vec4_one_a = GLM_VEC4_ONE_INIT;
|
||||
test_assert_vec4_eq(vec4_one.raw, vec4_one_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
|
||||
TEST_IMPL(vec4s_zero_init) {
|
||||
vec4s vec4_zero = GLMS_VEC4_ZERO_INIT;
|
||||
vec4 vec4_zero_a = GLM_VEC4_ZERO_INIT;
|
||||
test_assert_vec4_eq(vec4_zero.raw, vec4_zero_a);
|
||||
TEST_SUCCESS
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (c), Recep Aslantas.
|
||||
* MIT License (MIT), http://opensource.org/licenses/MIT
|
||||
*/
|
||||
|
||||
#ifndef test_tests_h
|
||||
#define test_tests_h
|
||||
|
||||
/* mat4 */
|
||||
void test_mat4(void **state);
|
||||
|
||||
/* mat3 */
|
||||
void test_mat3(void **state);
|
||||
|
||||
/* camera */
|
||||
void
|
||||
test_camera_lookat(void **state);
|
||||
|
||||
void
|
||||
test_camera_decomp(void **state);
|
||||
|
||||
void
|
||||
test_project(void **state);
|
||||
|
||||
void
|
||||
test_clamp(void **state);
|
||||
|
||||
void
|
||||
test_euler(void **state);
|
||||
|
||||
void
|
||||
test_quat(void **state);
|
||||
|
||||
void
|
||||
test_vec4(void **state);
|
||||
|
||||
void
|
||||
test_vec3(void **state);
|
||||
|
||||
void
|
||||
test_affine(void **state);
|
||||
|
||||
void
|
||||
test_bezier(void **state);
|
||||
|
||||
#endif /* test_tests_h */
|
||||
@@ -5,109 +5,22 @@
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
/* test inline mat3 */
|
||||
|
||||
void
|
||||
test_vec3(void **state) {
|
||||
mat3 rot1m3;
|
||||
mat4 rot1;
|
||||
vec3 v, v1, v2;
|
||||
vec3s vs1, vs2, vs3, vs4;
|
||||
#define GLM_PREFIX glm_
|
||||
#define GLM(X) (glm_ ## X)
|
||||
|
||||
/* test zero */
|
||||
glm_vec3_zero(v);
|
||||
test_assert_vec3_eq(GLM_VEC3_ZERO, v);
|
||||
#include "test_vec3.h"
|
||||
|
||||
/* test one */
|
||||
glm_vec3_one(v);
|
||||
test_assert_vec3_eq(GLM_VEC3_ONE, v);
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
/* adds, subs, div, divs, mul */
|
||||
glm_vec3_add(v, GLM_VEC3_ONE, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 2));
|
||||
/* test pre-compiled mat3 */
|
||||
|
||||
glm_vec3_adds(v, 10, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 12));
|
||||
#define GLM_PREFIX glmc_
|
||||
#define GLM(X) (glmc_ ## X)
|
||||
|
||||
glm_vec3_sub(v, GLM_VEC3_ONE, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 11));
|
||||
#include "test_vec3.h"
|
||||
|
||||
glm_vec3_subs(v, 1, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 10));
|
||||
|
||||
glm_vec3_broadcast(2, v1);
|
||||
glm_vec3_div(v, v1, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 5));
|
||||
|
||||
glm_vec3_divs(v, 0.5, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 10));
|
||||
|
||||
glm_vec3_mul(v, v1, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 20));
|
||||
|
||||
glm_vec3_scale(v, 0.5, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 10));
|
||||
|
||||
glm_vec3_normalize_to(v, v1);
|
||||
glm_vec3_scale(v1, 0.8, v1);
|
||||
glm_vec3_scale_as(v, 0.8, v);
|
||||
test_assert_vec3_eq(v1, v);
|
||||
|
||||
/* addadd, subadd, muladd */
|
||||
glm_vec3_one(v);
|
||||
|
||||
glm_vec3_addadd(GLM_VEC3_ONE, GLM_VEC3_ONE, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 3));
|
||||
|
||||
glm_vec3_subadd(GLM_VEC3_ONE, GLM_VEC3_ZERO, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 4));
|
||||
|
||||
glm_vec3_broadcast(2, v1);
|
||||
glm_vec3_broadcast(3, v2);
|
||||
glm_vec3_muladd(v1, v2, v);
|
||||
assert_true(glmc_vec3_eq_eps(v, 10));
|
||||
|
||||
/* rotate */
|
||||
glm_vec3_copy(GLM_YUP, v);
|
||||
glm_rotate_make(rot1, glm_rad(90), GLM_XUP);
|
||||
glm_vec3_rotate_m4(rot1, v, v1);
|
||||
glm_mat4_pick3(rot1, rot1m3);
|
||||
glm_vec3_rotate_m3(rot1m3, v, v2);
|
||||
|
||||
test_assert_vec3_eq(v1, v2);
|
||||
test_assert_vec3_eq(v1, GLM_ZUP);
|
||||
|
||||
/* structs */
|
||||
vs1 = test_rand_vec3s();
|
||||
vs2 = test_rand_vec3s();
|
||||
|
||||
vs3 = glms_vec3_add(vs1, vs2);
|
||||
vs4 = glms_vec3_maxv(vs1, vs3);
|
||||
test_assert_vec3s_eq(vs3, vs4);
|
||||
|
||||
/* swizzle */
|
||||
|
||||
/* ZYX */
|
||||
v1[0] = 1;
|
||||
v1[1] = 2;
|
||||
v1[2] = 3;
|
||||
glm_vec3_swizzle(v1, GLM_ZYX, v1);
|
||||
test_assert_vec3_eq(v1, (vec3){3, 2, 1});
|
||||
|
||||
glm_vec3_swizzle(v1, GLM_XXX, v1);
|
||||
test_assert_vec3_eq(v1, (vec3){3, 3, 3});
|
||||
|
||||
v1[0] = 1;
|
||||
v1[1] = 2;
|
||||
v1[2] = 3;
|
||||
|
||||
glm_vec3_swizzle(v1, GLM_YYY, v1);
|
||||
test_assert_vec3_eq(v1, (vec3){2, 2, 2});
|
||||
|
||||
v1[0] = 1;
|
||||
v1[1] = 2;
|
||||
v1[2] = 3;
|
||||
|
||||
glm_vec3_swizzle(v1, GLM_ZZZ, v1);
|
||||
test_assert_vec3_eq(v1, (vec3){3, 3, 3});
|
||||
}
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
1718
test/src/test_vec3.h
Normal file
1718
test/src/test_vec3.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -5,227 +5,22 @@
|
||||
* Full license can be found in the LICENSE file
|
||||
*/
|
||||
|
||||
#include "test_common.h"
|
||||
/* test inline mat3 */
|
||||
|
||||
CGLM_INLINE
|
||||
float
|
||||
test_vec4_dot(vec4 a, vec4 b) {
|
||||
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
||||
}
|
||||
#define GLM_PREFIX glm_
|
||||
#define GLM(X) (glm_ ## X)
|
||||
|
||||
CGLM_INLINE
|
||||
void
|
||||
test_vec4_normalize_to(vec4 vec, vec4 dest) {
|
||||
float norm;
|
||||
#include "test_vec4.h"
|
||||
|
||||
norm = glm_vec4_norm(vec);
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
if (norm == 0.0f) {
|
||||
dest[0] = dest[1] = dest[2] = dest[3] = 0.0f;
|
||||
return;
|
||||
}
|
||||
/* test pre-compiled mat3 */
|
||||
|
||||
glm_vec4_scale(vec, 1.0f / norm, dest);
|
||||
}
|
||||
#define GLM_PREFIX glmc_
|
||||
#define GLM(X) (glmc_ ## X)
|
||||
|
||||
float
|
||||
test_vec4_norm2(vec4 vec) {
|
||||
return test_vec4_dot(vec, vec);
|
||||
}
|
||||
#include "test_vec4.h"
|
||||
|
||||
float
|
||||
test_vec4_norm(vec4 vec) {
|
||||
return sqrtf(test_vec4_dot(vec, vec));
|
||||
}
|
||||
|
||||
void
|
||||
test_vec4_maxv(vec4 v1, vec4 v2, vec4 dest) {
|
||||
dest[0] = glm_max(v1[0], v2[0]);
|
||||
dest[1] = glm_max(v1[1], v2[1]);
|
||||
dest[2] = glm_max(v1[2], v2[2]);
|
||||
dest[3] = glm_max(v1[3], v2[3]);
|
||||
}
|
||||
|
||||
void
|
||||
test_vec4_minv(vec4 v1, vec4 v2, vec4 dest) {
|
||||
dest[0] = glm_min(v1[0], v2[0]);
|
||||
dest[1] = glm_min(v1[1], v2[1]);
|
||||
dest[2] = glm_min(v1[2], v2[2]);
|
||||
dest[3] = glm_min(v1[3], v2[3]);
|
||||
}
|
||||
|
||||
void
|
||||
test_vec4_clamp(vec4 v, float minVal, float maxVal) {
|
||||
v[0] = glm_clamp(v[0], minVal, maxVal);
|
||||
v[1] = glm_clamp(v[1], minVal, maxVal);
|
||||
v[2] = glm_clamp(v[2], minVal, maxVal);
|
||||
v[3] = glm_clamp(v[3], minVal, maxVal);
|
||||
}
|
||||
|
||||
void
|
||||
test_vec4(void **state) {
|
||||
vec4 v, v1, v2, v3, v4;
|
||||
vec4s vs1, vs2, vs3, vs4;
|
||||
int i;
|
||||
float d1, d2;
|
||||
|
||||
for (i = 0; i < 1000; i++) {
|
||||
/* 1. test SSE/SIMD dot product */
|
||||
test_rand_vec4(v);
|
||||
d1 = glm_vec4_dot(v, v);
|
||||
d2 = test_vec4_dot(v, v);
|
||||
|
||||
assert_true(fabsf(d1 - d2) <= 0.000009);
|
||||
|
||||
/* 2. test SIMD normalize */
|
||||
test_vec4_normalize_to(v, v1);
|
||||
glm_vec4_normalize_to(v, v2);
|
||||
glm_vec4_normalize(v);
|
||||
|
||||
/* all must be same */
|
||||
test_assert_vec4_eq(v1, v2);
|
||||
test_assert_vec4_eq(v, v2);
|
||||
|
||||
/* 3. test SIMD norm */
|
||||
test_rand_vec4(v);
|
||||
test_assert_eqf(test_vec4_norm(v), glm_vec4_norm(v));
|
||||
|
||||
/* 3. test SIMD norm2 */
|
||||
test_rand_vec4(v);
|
||||
test_assert_eqf(test_vec4_norm2(v), glm_vec4_norm2(v));
|
||||
|
||||
/* 4. test SSE/SIMD distance */
|
||||
test_rand_vec4(v1);
|
||||
test_rand_vec4(v2);
|
||||
d1 = glm_vec4_distance(v1, v2);
|
||||
d2 = sqrtf(powf(v1[0]-v2[0], 2.0f) + pow(v1[1]-v2[1], 2.0f) + pow(v1[2]-v2[2], 2.0f) + pow(v1[3]-v2[3], 2.0f));
|
||||
assert_true(fabsf(d1 - d2) <= 0.000009);
|
||||
}
|
||||
|
||||
/* test zero */
|
||||
glm_vec4_zero(v);
|
||||
test_assert_vec4_eq(GLM_VEC4_ZERO, v);
|
||||
|
||||
/* test one */
|
||||
glm_vec4_one(v);
|
||||
test_assert_vec4_eq(GLM_VEC4_ONE, v);
|
||||
|
||||
/* adds, subs, div, divs, mul */
|
||||
glm_vec4_add(v, GLM_VEC4_ONE, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 2));
|
||||
|
||||
glm_vec4_adds(v, 10, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 12));
|
||||
|
||||
glm_vec4_sub(v, GLM_VEC4_ONE, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 11));
|
||||
|
||||
glm_vec4_subs(v, 1, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 10));
|
||||
|
||||
glm_vec4_broadcast(2, v1);
|
||||
glm_vec4_div(v, v1, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 5));
|
||||
|
||||
glm_vec4_divs(v, 0.5, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 10));
|
||||
|
||||
glm_vec4_mul(v, v1, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 20));
|
||||
|
||||
glm_vec4_scale(v, 0.5, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 10));
|
||||
|
||||
glm_vec4_normalize_to(v, v1);
|
||||
glm_vec4_scale(v1, 0.8, v1);
|
||||
glm_vec4_scale_as(v, 0.8, v);
|
||||
test_assert_vec4_eq(v1, v);
|
||||
|
||||
/* addadd, subadd, muladd */
|
||||
glm_vec4_one(v);
|
||||
|
||||
glm_vec4_addadd(GLM_VEC4_ONE, GLM_VEC4_ONE, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 3));
|
||||
|
||||
glm_vec4_subadd(GLM_VEC4_ONE, GLM_VEC4_ZERO, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 4));
|
||||
|
||||
glm_vec4_broadcast(2, v1);
|
||||
glm_vec4_broadcast(3, v2);
|
||||
glm_vec4_muladd(v1, v2, v);
|
||||
assert_true(glmc_vec4_eq_eps(v, 10));
|
||||
|
||||
/* min, max */
|
||||
test_rand_vec4(v1);
|
||||
test_rand_vec4(v2);
|
||||
|
||||
glm_vec4_maxv(v1, v2, v3);
|
||||
test_vec4_maxv(v1, v2, v4);
|
||||
test_assert_vec4_eq(v3, v4);
|
||||
|
||||
glm_vec4_minv(v1, v2, v3);
|
||||
test_vec4_minv(v1, v2, v4);
|
||||
test_assert_vec4_eq(v3, v4);
|
||||
|
||||
glm_vec4_print(v3, stderr);
|
||||
glm_vec4_print(v4, stderr);
|
||||
|
||||
/* clamp */
|
||||
glm_vec4_clamp(v3, 0.1, 0.8);
|
||||
test_vec4_clamp(v4, 0.1, 0.8);
|
||||
test_assert_vec4_eq(v3, v4);
|
||||
|
||||
glm_vec4_print(v3, stderr);
|
||||
glm_vec4_print(v4, stderr);
|
||||
|
||||
assert_true(v3[0] >= 0.0999 && v3[0] <= 0.80001); /* rounding erros */
|
||||
assert_true(v3[1] >= 0.0999 && v3[1] <= 0.80001);
|
||||
assert_true(v3[2] >= 0.0999 && v3[2] <= 0.80001);
|
||||
assert_true(v3[3] >= 0.0999 && v3[3] <= 0.80001);
|
||||
|
||||
/* swizzle */
|
||||
|
||||
/* ZYX */
|
||||
v1[0] = 1;
|
||||
v1[1] = 2;
|
||||
v1[2] = 3;
|
||||
v1[3] = 4;
|
||||
|
||||
glm_vec4_swizzle(v1, GLM_WZYX, v1);
|
||||
test_assert_vec4_eq(v1, (vec4){4, 3, 2, 1});
|
||||
|
||||
glm_vec4_swizzle(v1, GLM_XXXX, v1);
|
||||
test_assert_vec4_eq(v1, (vec4){4, 4, 4, 4});
|
||||
|
||||
v1[0] = 1;
|
||||
v1[1] = 2;
|
||||
v1[2] = 3;
|
||||
v1[3] = 4;
|
||||
|
||||
glm_vec4_swizzle(v1, GLM_YYYY, v1);
|
||||
test_assert_vec4_eq(v1, (vec4){2, 2, 2, 2});
|
||||
|
||||
v1[0] = 1;
|
||||
v1[1] = 2;
|
||||
v1[2] = 3;
|
||||
v1[3] = 4;
|
||||
|
||||
glm_vec4_swizzle(v1, GLM_ZZZZ, v1);
|
||||
test_assert_vec4_eq(v1, (vec4){3, 3, 3, 3});
|
||||
|
||||
v1[0] = 1;
|
||||
v1[1] = 2;
|
||||
v1[2] = 3;
|
||||
v1[3] = 4;
|
||||
|
||||
glm_vec4_swizzle(v1, GLM_WWWW, v1);
|
||||
test_assert_vec4_eq(v1, (vec4){4, 4, 4, 4});
|
||||
|
||||
/* structs */
|
||||
vs1 = test_rand_vec4s();
|
||||
vs2 = test_rand_vec4s();
|
||||
|
||||
vs3 = glms_vec4_add(vs1, vs2);
|
||||
vs4 = glms_vec4_maxv(vs1, vs3);
|
||||
test_assert_vec4s_eq(vs3, vs4);
|
||||
}
|
||||
#undef GLM
|
||||
#undef GLM_PREFIX
|
||||
|
||||
1420
test/src/test_vec4.h
Normal file
1420
test/src/test_vec4.h
Normal file
File diff suppressed because it is too large
Load Diff
1026
test/tests.h
Normal file
1026
test/tests.h
Normal file
File diff suppressed because it is too large
Load Diff
5
win/.gitignore
vendored
5
win/.gitignore
vendored
@@ -1,4 +1,9 @@
|
||||
!cglm.sln
|
||||
|
||||
!cglm.vcxproj
|
||||
!cglm.vcxproj.filters
|
||||
|
||||
!cglm-test.vcxproj
|
||||
!cglm-test.vcxproj.filters
|
||||
|
||||
!packages.config
|
||||
|
||||
196
win/cglm-test.vcxproj
Normal file
196
win/cglm-test.vcxproj
Normal file
@@ -0,0 +1,196 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test\runner.c" />
|
||||
<ClCompile Include="..\test\src\test_affine.c" />
|
||||
<ClCompile Include="..\test\src\test_bezier.c" />
|
||||
<ClCompile Include="..\test\src\test_cam.c" />
|
||||
<ClCompile Include="..\test\src\test_clamp.c" />
|
||||
<ClCompile Include="..\test\src\test_common.c" />
|
||||
<ClCompile Include="..\test\src\test_euler.c" />
|
||||
<ClCompile Include="..\test\src\test_mat3.c" />
|
||||
<ClCompile Include="..\test\src\test_mat4.c" />
|
||||
<ClCompile Include="..\test\src\test_project.c" />
|
||||
<ClCompile Include="..\test\src\test_quat.c" />
|
||||
<ClCompile Include="..\test\src\test_struct.c" />
|
||||
<ClCompile Include="..\test\src\test_vec3.c" />
|
||||
<ClCompile Include="..\test\src\test_vec4.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\test\include\common.h" />
|
||||
<ClInclude Include="..\test\src\test_common.h" />
|
||||
<ClInclude Include="..\test\src\test_mat3.h" />
|
||||
<ClInclude Include="..\test\src\test_mat4.h" />
|
||||
<ClInclude Include="..\test\src\test_project.h" />
|
||||
<ClInclude Include="..\test\src\test_quat.h" />
|
||||
<ClInclude Include="..\test\src\test_vec3.h" />
|
||||
<ClInclude Include="..\test\src\test_vec4.h" />
|
||||
<ClInclude Include="..\test\tests.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="cglm.vcxproj">
|
||||
<Project>{ca8bcaf9-cd25-4133-8f62-3d1449b5d2fc}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>16.0</VCProjectVersion>
|
||||
<ProjectGuid>{200E0DF1-7532-44E6-8273-84FB92C5557E}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>cglmtest</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v142</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>../include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
86
win/cglm-test.vcxproj.filters
Normal file
86
win/cglm-test.vcxproj.filters
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="src">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="include">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test\runner.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_affine.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_bezier.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_cam.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_clamp.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_common.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_euler.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_mat3.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_mat4.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_project.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_quat.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_vec3.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_vec4.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test\src\test_struct.c">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\test\tests.h">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\test\src\test_common.h">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\test\include\common.h">
|
||||
<Filter>include</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\test\src\test_mat3.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\test\src\test_mat4.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\test\src\test_project.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\test\src\test_quat.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\test\src\test_vec3.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\test\src\test_vec4.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
17
win/cglm.sln
17
win/cglm.sln
@@ -1,10 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26403.7
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29123.88
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cglm", "cglm.vcxproj", "{CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}"
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cglm-test", "cglm-test.vcxproj", "{200E0DF1-7532-44E6-8273-84FB92C5557E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
@@ -21,8 +23,19 @@ Global
|
||||
{CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Release|x64.Build.0 = Release|x64
|
||||
{CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Release|x86.ActiveCfg = Release|Win32
|
||||
{CA8BCAF9-CD25-4133-8F62-3D1449B5D2FC}.Release|x86.Build.0 = Release|Win32
|
||||
{200E0DF1-7532-44E6-8273-84FB92C5557E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{200E0DF1-7532-44E6-8273-84FB92C5557E}.Debug|x64.Build.0 = Debug|x64
|
||||
{200E0DF1-7532-44E6-8273-84FB92C5557E}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{200E0DF1-7532-44E6-8273-84FB92C5557E}.Debug|x86.Build.0 = Debug|Win32
|
||||
{200E0DF1-7532-44E6-8273-84FB92C5557E}.Release|x64.ActiveCfg = Release|x64
|
||||
{200E0DF1-7532-44E6-8273-84FB92C5557E}.Release|x64.Build.0 = Release|x64
|
||||
{200E0DF1-7532-44E6-8273-84FB92C5557E}.Release|x86.ActiveCfg = Release|Win32
|
||||
{200E0DF1-7532-44E6-8273-84FB92C5557E}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {2AEF23C9-433B-428B-BEBC-068BF3AC9A65}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -5,10 +5,6 @@
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="src">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
|
||||
Reference in New Issue
Block a user