mirror of
https://github.com/HandmadeMath/HandmadeMath.git
synced 2025-12-28 15:44:33 +00:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
422bc588e9 | ||
|
|
beb837a3c6 | ||
|
|
50ab55b3bc | ||
|
|
22d743ce3d | ||
|
|
d4918a514e | ||
|
|
37aa3fa6a0 | ||
|
|
7e493a5481 | ||
|
|
f106a0f5f3 | ||
|
|
c24e4ff873 | ||
|
|
ba5405ac0f | ||
|
|
d69a859d73 | ||
|
|
8c18186b3b | ||
|
|
5f816bf9b3 | ||
|
|
c5bc802042 | ||
|
|
43afc87fa7 | ||
|
|
5bbac2167e | ||
|
|
655c662528 | ||
|
|
1f0c6ba493 | ||
|
|
1d82b4f0bc | ||
|
|
2fa0b36715 | ||
|
|
ad169e649c | ||
|
|
1900cc9275 | ||
|
|
ddb9971e71 | ||
|
|
341a376a17 | ||
|
|
c825fe48cf | ||
|
|
15bef820db | ||
|
|
fe32f081f2 | ||
|
|
785f19d4a7 | ||
|
|
a9b08b9147 | ||
|
|
f376f2a2a7 | ||
|
|
78e6feea82 | ||
|
|
21aa828a08 | ||
|
|
93e56be543 | ||
|
|
45c91702a9 |
34
.github/workflows/ci.yml
vendored
Normal file
34
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
pull_request:
|
||||
branches: [ "master" ]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: TheMrMilchmann/setup-msvc-dev@v2
|
||||
with:
|
||||
arch: x64
|
||||
if: matrix.os == 'windows-latest'
|
||||
- name: Test (Windows, MSVC)
|
||||
run: ./run_test_msvc.bat
|
||||
working-directory: ./test
|
||||
if: matrix.os == 'windows-latest'
|
||||
- name: Test (Windows, clang)
|
||||
run: ./run_test_clang.bat
|
||||
working-directory: ./test
|
||||
if: matrix.os == 'windows-latest'
|
||||
- name: Test (${{ matrix.os }})
|
||||
run: make all
|
||||
working-directory: ./test
|
||||
if: matrix.os != 'windows-latest'
|
||||
0
.gitmodules
vendored
0
.gitmodules
vendored
12
.travis.yml
12
.travis.yml
@@ -1,12 +0,0 @@
|
||||
language: cpp
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
install:
|
||||
- cd test
|
||||
- make
|
||||
script:
|
||||
- build/hmm_test_c
|
||||
- build/hmm_test_c_no_sse
|
||||
- build/hmm_test_cpp
|
||||
- build/hmm_test_cpp_no_sse
|
||||
@@ -1,43 +0,0 @@
|
||||
# Understanding the structure of Handmade Math
|
||||
|
||||
Most of the functions in Handmade Math are very short, and are the kind of functions you want to have inlined. Because of this, most functions in Handmade Math are defined with `HINLINE`, which is defined as `static inline`.
|
||||
|
||||
The exceptions are functions like `HMM_Rotate`, which are long enough that it doesn't make sense to inline them. These functions are defined with an `HEXTERN` prototype, and implemented in the `#ifdef HANDMADE_MATH_IMPLEMENTATION` block.
|
||||
|
||||
# Quick style guide
|
||||
|
||||
* Put braces on a new line
|
||||
* Float literals should have digits both before and after the decimal.
|
||||
```cpp
|
||||
// Good
|
||||
0.0f;
|
||||
0.5f;
|
||||
1.0f;
|
||||
3.14159f;
|
||||
|
||||
// Bad
|
||||
1.f
|
||||
.0f
|
||||
```
|
||||
* Put parentheses around the returned value:
|
||||
```cpp
|
||||
HINLINE float
|
||||
HMM_MyFunction()
|
||||
{
|
||||
return (1.0f);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
## Other style notes
|
||||
|
||||
* If a new function is defined with different names for different datatypes, also add C++ overloaded versions of the functions. For example, if you have `HMM_LengthVec2(hmm_vec2)` and `HMM_LengthVec3(hmm_vec3)`, also provide `HMM_Length(hmm_vec2)` and `HMM_Length(hmm_vec3)`.
|
||||
|
||||
It is fine for the overloaded versions to call the C versions.
|
||||
* Only use operator overloading for analogous operators in C. That means `+` for vector addition is fine, but no using `^` for cross product or `|` for dot product.
|
||||
* Try to define functions in the same order as the prototypes.
|
||||
* Don't forget that Handmade Math uses column-major order for matrices!
|
||||
|
||||
# Versioning
|
||||
|
||||
We use [semantic versioning](http://semver.org/) because it's reasonable.
|
||||
4895
HandmadeMath.h
4895
HandmadeMath.h
File diff suppressed because it is too large
Load Diff
56
README.md
56
README.md
@@ -1,44 +1,26 @@
|
||||
# Handmade Math
|
||||
|
||||
[](https://travis-ci.org/StrangeZak/Handmade-Math)
|
||||
A single-file, cross-platform, public domain graphics math library for both C and C++. Supports vectors, matrices, quaternions, and all the utilities you'd expect.
|
||||
|
||||
A single-file, cross-platform, public domain game math library for C/C++.
|
||||
To get started, go download [the latest release](https://github.com/HandmadeMath/HandmadeMath/releases).
|
||||
|
||||
To get started, go download [the latest release](https://github.com/HandmadeMath/Handmade-Math/releases).
|
||||
> If you are upgrading to Handmade Math 2.0, save yourself some time and use our [automatic update tool](./update).
|
||||
|
||||
-----
|
||||
Here's what sets Handmade Math apart:
|
||||
|
||||
Version | Changes |
|
||||
----------------|----------------|
|
||||
**1.8.0** | Added fast vector normalization routines that use fast inverse square roots.
|
||||
**1.7.1** | Changed operator[] to take a const ref int instead of an int.
|
||||
**1.7.0** | Renamed the 'Rows' member of hmm_mat4 to 'Columns'. Since our matrices are column-major, this should have been named 'Columns' from the start. 'Rows' is still present, but has been deprecated.
|
||||
**1.6.0** | Added array subscript operators for vector and matrix types in C++. This is provided as a convenience, but be aware that it may incur an extra function call in unoptimized builds.
|
||||
**1.5.1** | Fixed a bug with uninitialized elements in HMM_LookAt.
|
||||
**1.5.0** | Changed internal structure for better performance and inlining. As a result, `HANDMADE_MATH_NO_INLINE` has been removed and no longer has any effect.
|
||||
**1.4.0** | Fixed bug when using C mode. SSE'd all vec4 operations. Removed zeroing for better performance.
|
||||
**1.3.0** | Removed need to `#define HANDMADE_MATH_CPP_MODE`. C++ definitions are now included automatically in C++ environments.
|
||||
**1.2.0** | Added equality functions for `HMM_Vec2`, `HMM_Vec3`, and `HMM_Vec4`, and SSE'd `HMM_MultiplyMat4` and `HMM_Transpose`.
|
||||
**1.1.5** | Added `Width` and `Height` to `HMM_Vec2`, and made it so you can supply your own `SqrtF`.
|
||||
**1.1.4** | Fixed SSE being included on platforms that don't support it, and fixed divide-by-zero errors when normalizing zero vectors.
|
||||
**1.1.3** | Fixed compile error in C mode
|
||||
**1.1.2** | Fixed invalid HMMDEF's in the function definitions
|
||||
**1.1.1** | Resolved compiler warnings on gcc and g++
|
||||
**1.1** | Quaternions! |
|
||||
**1.0** | Lots of testing |
|
||||
**0.7** | Added HMM_Vec2, and HMM_Vec4 versions of HMM_LengthSquared, HMM_Length, and HMM_Normalize. |
|
||||
**0.6** | Made HMM_Power faster, Fixed possible efficiency problem with HMM_Normalize, RENAMED HMM_LengthSquareRoot to HMM_LengthSquared, RENAMED HMM_RSqrtF to HMM_RSquareRootF, RENAMED HMM_SqrtF to HMM_SquareRootF, REMOVED Inner function (user should use Dot now), REMOVED HMM_FastInverseSquareRoot function declaration |
|
||||
**0.5.2** | Fixed SSE code in HMM_SqrtF and HMM_RSqrtF |
|
||||
**0.5.1** | Fixed HMM_Translate producing row-major matrices, ensured column-major order for matrices throughout |
|
||||
**0.5** | Added scalar operations on vectors and matrices, added += and -= for hmm_mat4, reconciled headers and implementations, tidied up in general |
|
||||
**0.4** | Added SSE Optimized HMM_SqrtF, HMM_RSqrtF, Removed use of C Runtime |
|
||||
**0.3** | Added +=,-=, *=, /= for hmm_vec2, hmm_vec3, hmm_vec4 |
|
||||
**0.2b** | Disabled warning C4201 on MSVC, Added 64bit percision on HMM_PI |
|
||||
**0.2a** | Prefixed Macros |
|
||||
**0.2** | Updated Documentation, Fixed C Compliance, Prefixed all functions, and added better operator overloading |
|
||||
**0.1** | Initial Version |
|
||||
- **A simple single-header library.** Just `#include "HandmadeMath.h"`.
|
||||
- **Supports both C and C++.** While libraries like GLM only support C++, Handmade Math supports both C and C++, with convenient overloads wherever possible. For example, C++ codebases get operator overloading, and C11 codebases get `_Generic` versions of common operations.
|
||||
- **Supports all graphics APIs.** Handmade Math has left- and right-handed versions of each operation, as well as support for zero-to-one and negative-one-to-one NDC conventions.
|
||||
- **Swizzling, sort of.** Handmade Math's vector types use unions to provide several ways of accessing the same underlying data. For example, the components of an `HMM_Vec3` can be accessed as `XYZ`, `RGB`, or `UVW` - or subsets can be accessed like `.XY` and `.YZ`.
|
||||
- **Your choice of angle unit.** While Handmade Math uses radians by default, you can configure it to use degrees or [turns](https://www.computerenhance.com/p/turns-are-better-than-radians) instead.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
Simply `#include "HandmadeMath.h"`. All functions are `static inline`, so there is no need for an "implementation" file as with some other single-header libraries.
|
||||
|
||||
A few config options are available. See the header comment in [the source](./HandmadeMath.h) for details.
|
||||
|
||||
-----
|
||||
|
||||
## FAQ
|
||||
|
||||
@@ -48,4 +30,8 @@ This library is in the public domain. You can do whatever you want with it.
|
||||
|
||||
**Where can I contact you to ask questions?**
|
||||
|
||||
Feel free to make Github issues for any questions, concerns, or problems you encounter.
|
||||
Feel free to make GitHub issues for any questions, concerns, or problems you encounter.
|
||||
|
||||
**What if I don't want the `HMM_` prefix?**
|
||||
|
||||
Do a find and replace in the library source.
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#define HANDMADE_MATH_IMPLEMENTATION
|
||||
#define HANDMADE_MATH_NO_INLINE
|
||||
#ifndef WITHOUT_COVERAGE
|
||||
#include "HandmadeTest.h"
|
||||
#endif
|
||||
|
||||
#include "../HandmadeMath.h"
|
||||
|
||||
@@ -4,19 +4,46 @@
|
||||
This is Handmade Math's test framework. It is fully compatible with both C
|
||||
and C++, although it requires some compiler-specific features.
|
||||
|
||||
To use Handmade Test, you must #define HANDMADE_TEST_IMPLEMENTATION in
|
||||
exactly one C or C++ file that includes the header, like this:
|
||||
|
||||
#define HANDMADE_TEST_IMPLEMENTATION
|
||||
#include "HandmadeTest.h"
|
||||
|
||||
The basic way of creating a test is using the TEST macro, which registers a
|
||||
single test to be run:
|
||||
|
||||
TEST(MyCategory, MyTestName) {
|
||||
TEST(MyCategory, MyTestName) {
|
||||
// test code, including asserts/expects
|
||||
}
|
||||
}
|
||||
|
||||
The main function of your test code should then call hmt_run_all_tests and
|
||||
return the result:
|
||||
Handmade Test also provides macros you can use to check the coverage of
|
||||
important parts of your code. Define a coverage case by using the COVERAGE
|
||||
macro outside the function you wish to test, providing both a name and the
|
||||
number of asserts you expect to see covered over the course of your test.
|
||||
Then use the ASSERT_COVERED macro in every part of the function you wish to
|
||||
check coverage on. For example:
|
||||
|
||||
int main() {
|
||||
return hmt_run_all_tests();
|
||||
}
|
||||
COVERAGE(MyCoverageCase, 3)
|
||||
void MyFunction(int a, int b) {
|
||||
if (a > b) {
|
||||
ASSERT_COVERED(MyCoverageCase);
|
||||
return 10;
|
||||
} else if (a < b) {
|
||||
ASSERT_COVERED(MyCoverageCase);
|
||||
return -10;
|
||||
}
|
||||
|
||||
ASSERT_COVERED(MyCoverageCase);
|
||||
return 0;
|
||||
}
|
||||
|
||||
The main function of your test code should then call hmt_run_all_tests (and
|
||||
optionally hmt_check_all_coverage) and return the result:
|
||||
|
||||
int main() {
|
||||
return hmt_run_all_tests() || hmt_check_all_coverage();
|
||||
}
|
||||
|
||||
=============================================================================
|
||||
|
||||
@@ -40,7 +67,7 @@
|
||||
#define HMT_RED "\033[31m"
|
||||
#define HMT_GREEN "\033[32m"
|
||||
|
||||
#define HMT_INITIAL_ARRAY_SIZE 1024
|
||||
#define HMT_ARRAY_SIZE 1024
|
||||
|
||||
typedef struct hmt_testresult_struct {
|
||||
int count_cases;
|
||||
@@ -57,20 +84,188 @@ typedef struct hmt_test_struct {
|
||||
typedef struct hmt_category_struct {
|
||||
const char* name;
|
||||
int num_tests;
|
||||
int tests_capacity;
|
||||
hmt_test* tests;
|
||||
} hmt_category;
|
||||
|
||||
int hmt_num_categories = 0;
|
||||
int hmt_category_capacity = HMT_INITIAL_ARRAY_SIZE;
|
||||
hmt_category* categories = 0;
|
||||
typedef struct hmt_covercase_struct {
|
||||
const char* name;
|
||||
int expected_asserts;
|
||||
int actual_asserts;
|
||||
int* asserted_lines;
|
||||
} hmt_covercase;
|
||||
|
||||
hmt_category _hmt_new_category(const char* name);
|
||||
hmt_test _hmt_new_test(const char* name, hmt_test_func func);
|
||||
hmt_covercase _hmt_new_covercase(const char* name, int expected);
|
||||
void _hmt_register_test(const char* category, const char* name, hmt_test_func func);
|
||||
void _hmt_register_covercase(const char* name, const char* expected_asserts);
|
||||
void _hmt_count_cover(const char* name, int line);
|
||||
|
||||
#define _HMT_TEST_FUNCNAME(category, name) _hmt_test_ ## category ## _ ## name
|
||||
#define _HMT_TEST_FUNCNAME_INIT(category, name) _hmt_test_ ## category ## _ ## name ## _init
|
||||
#define _HMT_COVERCASE_FUNCNAME_INIT(name) _hmt_covercase_ ## name ## _init
|
||||
|
||||
#define HMT_TEST(category, name) \
|
||||
void _HMT_TEST_FUNCNAME(category, name)(hmt_testresult* _result); \
|
||||
INITIALIZER(_HMT_TEST_FUNCNAME_INIT(category, name)) { \
|
||||
_hmt_register_test(#category, #name, _HMT_TEST_FUNCNAME(category, name)); \
|
||||
} \
|
||||
void _HMT_TEST_FUNCNAME(category, name)(hmt_testresult* _result)
|
||||
|
||||
#define _HMT_CASE_START() \
|
||||
_result->count_cases++;
|
||||
|
||||
#define _HMT_CASE_FAIL() \
|
||||
_result->count_failures++; \
|
||||
printf("\n - " HMT_RED "[FAIL] (line %d) " HMT_RESET, __LINE__);
|
||||
|
||||
#define HMT_COVERAGE(name, num_asserts) \
|
||||
INITIALIZER(_HMT_COVERCASE_FUNCNAME_INIT(name)) { \
|
||||
_hmt_register_covercase(#name, #num_asserts); \
|
||||
} \
|
||||
|
||||
#define HMT_ASSERT_COVERED(name) \
|
||||
{ \
|
||||
_hmt_count_cover(#name, __LINE__); \
|
||||
} \
|
||||
|
||||
/*
|
||||
* Asserts and expects
|
||||
*/
|
||||
#define HMT_EXPECT_TRUE(_actual) { \
|
||||
_HMT_CASE_START(); \
|
||||
if (!(_actual)) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected true but got something false"); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define HMT_EXPECT_FALSE(_actual) { \
|
||||
_HMT_CASE_START(); \
|
||||
if (_actual) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected false but got something true"); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define HMT_EXPECT_FLOAT_EQ_MSG(_actual, _expected, _msg) { \
|
||||
_HMT_CASE_START(); \
|
||||
float actual = (_actual); \
|
||||
float diff = actual - (_expected); \
|
||||
if (diff < -FLT_EPSILON || FLT_EPSILON < diff) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
if ((_msg)[0] == 0) { \
|
||||
printf("Expected %f, got %f", (_expected), actual); \
|
||||
} else { \
|
||||
printf("%s: Expected %f, got %f", (_msg), (_expected), actual); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#define HMT_EXPECT_FLOAT_EQ(_actual, _expected) HMT_EXPECT_FLOAT_EQ_MSG(_actual, _expected, "");
|
||||
|
||||
#define HMT_EXPECT_NEAR_MSG(_actual, _expected, _epsilon, _msg) { \
|
||||
_HMT_CASE_START(); \
|
||||
float actual = (_actual); \
|
||||
float diff = actual - (_expected); \
|
||||
if (diff < -(_epsilon) || (_epsilon) < diff) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
if ((_msg)[0] == 0) { \
|
||||
printf("Expected %f, got %f", (_expected), actual); \
|
||||
} else { \
|
||||
printf("%s: Expected %f, got %f", (_msg), (_expected), actual); \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
#define HMT_EXPECT_NEAR(_actual, _expected, _epsilon) HMT_EXPECT_NEAR_MSG(_actual, _expected, _epsilon, "");
|
||||
|
||||
#define HMT_EXPECT_LT(_actual, _expected) { \
|
||||
_HMT_CASE_START(); \
|
||||
if ((_actual) >= (_expected)) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected %f to be less than %f", (_actual), (_expected)); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#define HMT_EXPECT_GT(_actual, _expected) { \
|
||||
_HMT_CASE_START(); \
|
||||
if ((_actual) <= (_expected)) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected %f to be greater than %f", (_actual), (_expected)); \
|
||||
} \
|
||||
} \
|
||||
|
||||
#ifndef HMT_SAFE_MACROS
|
||||
// Friendly defines
|
||||
#define TEST(category, name) HMT_TEST(category, name)
|
||||
#define COVERAGE(name, expected_asserts) HMT_COVERAGE(name, expected_asserts)
|
||||
#define ASSERT_COVERED(name) HMT_ASSERT_COVERED(name)
|
||||
#define EXPECT_TRUE(_actual) HMT_EXPECT_TRUE(_actual)
|
||||
#define EXPECT_FALSE(_actual) HMT_EXPECT_FALSE(_actual)
|
||||
#define EXPECT_FLOAT_EQ(_actual, _expected) HMT_EXPECT_FLOAT_EQ(_actual, _expected)
|
||||
#define EXPECT_V4_EQ(_actual, _expected) \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.X, _expected.X, "incorrect X"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Y, _expected.Y, "incorrect Y"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Z, _expected.Z, "incorrect Z"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.W, _expected.W, "incorrect W");
|
||||
#define EXPECT_M4_EQ(_actual, _expected) \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[0][0], _expected.Elements[0][0], "incorrect [0][0]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[0][1], _expected.Elements[0][1], "incorrect [0][1]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[0][2], _expected.Elements[0][2], "incorrect [0][2]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[0][3], _expected.Elements[0][3], "incorrect [0][3]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[1][0], _expected.Elements[1][0], "incorrect [1][0]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[1][1], _expected.Elements[1][1], "incorrect [1][1]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[1][2], _expected.Elements[1][2], "incorrect [1][2]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[1][3], _expected.Elements[1][3], "incorrect [1][3]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[2][0], _expected.Elements[2][0], "incorrect [2][0]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[2][1], _expected.Elements[2][1], "incorrect [2][1]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[2][2], _expected.Elements[2][2], "incorrect [2][2]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[2][3], _expected.Elements[2][3], "incorrect [2][3]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[3][0], _expected.Elements[3][0], "incorrect [3][0]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[3][1], _expected.Elements[3][1], "incorrect [3][1]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[3][2], _expected.Elements[3][2], "incorrect [3][2]"); \
|
||||
HMT_EXPECT_FLOAT_EQ_MSG(_actual.Elements[3][3], _expected.Elements[3][3], "incorrect [3][3]");
|
||||
#define EXPECT_NEAR(_actual, _expected, _epsilon) HMT_EXPECT_NEAR(_actual, _expected, _epsilon)
|
||||
#define EXPECT_M4_NEAR(_actual, _expected, _epsilon) \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[0][0], _expected.Elements[0][0], _epsilon, "incorrect [0][0]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[0][1], _expected.Elements[0][1], _epsilon, "incorrect [0][1]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[0][2], _expected.Elements[0][2], _epsilon, "incorrect [0][2]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[0][3], _expected.Elements[0][3], _epsilon, "incorrect [0][3]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[1][0], _expected.Elements[1][0], _epsilon, "incorrect [1][0]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[1][1], _expected.Elements[1][1], _epsilon, "incorrect [1][1]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[1][2], _expected.Elements[1][2], _epsilon, "incorrect [1][2]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[1][3], _expected.Elements[1][3], _epsilon, "incorrect [1][3]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[2][0], _expected.Elements[2][0], _epsilon, "incorrect [2][0]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[2][1], _expected.Elements[2][1], _epsilon, "incorrect [2][1]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[2][2], _expected.Elements[2][2], _epsilon, "incorrect [2][2]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[2][3], _expected.Elements[2][3], _epsilon, "incorrect [2][3]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[3][0], _expected.Elements[3][0], _epsilon, "incorrect [3][0]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[3][1], _expected.Elements[3][1], _epsilon, "incorrect [3][1]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[3][2], _expected.Elements[3][2], _epsilon, "incorrect [3][2]"); \
|
||||
HMT_EXPECT_NEAR_MSG(_actual.Elements[3][3], _expected.Elements[3][3], _epsilon, "incorrect [3][3]");
|
||||
#define EXPECT_LT(_actual, _expected) HMT_EXPECT_LT(_actual, _expected)
|
||||
#define EXPECT_GT(_actual, _expected) HMT_EXPECT_GT(_actual, _expected)
|
||||
#endif // HMT_SAFE_MACROS
|
||||
|
||||
#endif // HANDMADETEST_H
|
||||
|
||||
#ifdef HANDMADE_TEST_IMPLEMENTATION
|
||||
|
||||
#ifndef HANDMADE_TEST_IMPLEMENTATION_GUARD
|
||||
#define HANDMADE_TEST_IMPLEMENTATION_GUARD
|
||||
|
||||
int _hmt_num_categories = 0;
|
||||
hmt_category* _hmt_categories = 0;
|
||||
|
||||
int _hmt_num_covercases = 0;
|
||||
hmt_covercase* _hmt_covercases = 0;
|
||||
|
||||
int _hmt_num_covererrors = 0;
|
||||
|
||||
hmt_category _hmt_new_category(const char* name) {
|
||||
hmt_category cat = {
|
||||
.name = name,
|
||||
.num_tests = 0,
|
||||
.tests_capacity = HMT_INITIAL_ARRAY_SIZE,
|
||||
.tests = (hmt_test*) malloc(HMT_INITIAL_ARRAY_SIZE * sizeof(hmt_test))
|
||||
name, // name
|
||||
0, // num_tests
|
||||
(hmt_test*) malloc(HMT_ARRAY_SIZE * sizeof(hmt_test)), // tests
|
||||
};
|
||||
|
||||
return cat;
|
||||
@@ -78,60 +273,106 @@ hmt_category _hmt_new_category(const char* name) {
|
||||
|
||||
hmt_test _hmt_new_test(const char* name, hmt_test_func func) {
|
||||
hmt_test test = {
|
||||
.name = name,
|
||||
.func = func
|
||||
name, // name
|
||||
func, // func
|
||||
};
|
||||
|
||||
return test;
|
||||
}
|
||||
|
||||
int hmt_register_test(const char* category, const char* name, hmt_test_func func) {
|
||||
hmt_covercase _hmt_new_covercase(const char* name, int expected) {
|
||||
hmt_covercase covercase = {
|
||||
name, // name
|
||||
expected, // expected_asserts
|
||||
0, // actual_asserts
|
||||
(int*) malloc(HMT_ARRAY_SIZE * sizeof(int)), // asserted_lines
|
||||
};
|
||||
|
||||
return covercase;
|
||||
}
|
||||
|
||||
void _hmt_register_test(const char* category, const char* name, hmt_test_func func) {
|
||||
// initialize categories array if not initialized
|
||||
if (!categories) {
|
||||
categories = (hmt_category*) malloc(hmt_category_capacity * sizeof(hmt_category));
|
||||
if (!_hmt_categories) {
|
||||
_hmt_categories = (hmt_category*) malloc(HMT_ARRAY_SIZE * sizeof(hmt_category));
|
||||
}
|
||||
|
||||
// Find the matching category, if possible
|
||||
int cat_index;
|
||||
for (cat_index = 0; cat_index < hmt_num_categories; cat_index++) {
|
||||
if (strcmp(categories[cat_index].name, category) == 0) {
|
||||
for (cat_index = 0; cat_index < _hmt_num_categories; cat_index++) {
|
||||
if (strcmp(_hmt_categories[cat_index].name, category) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Expand the array of categories if necessary
|
||||
if (cat_index >= hmt_category_capacity) {
|
||||
// TODO: If/when we ever split HandmadeTest off into its own package,
|
||||
// we should start with a smaller initial capacity and dynamically expand.
|
||||
}
|
||||
|
||||
// Add a new category if necessary
|
||||
if (cat_index >= hmt_num_categories) {
|
||||
categories[cat_index] = _hmt_new_category(category);
|
||||
hmt_num_categories++;
|
||||
if (cat_index >= _hmt_num_categories) {
|
||||
_hmt_categories[cat_index] = _hmt_new_category(category);
|
||||
_hmt_num_categories++;
|
||||
}
|
||||
|
||||
hmt_category* cat = &categories[cat_index];
|
||||
hmt_category* cat = &_hmt_categories[cat_index];
|
||||
|
||||
// Add the test to the category
|
||||
if (cat->num_tests >= cat->tests_capacity) {
|
||||
// TODO: If/when we ever split HandmadeTest off into its own package,
|
||||
// we should start with a smaller initial capacity and dynamically expand.
|
||||
}
|
||||
cat->tests[cat->num_tests] = _hmt_new_test(name, func);
|
||||
cat->num_tests++;
|
||||
}
|
||||
|
||||
void _hmt_register_covercase(const char* name, const char* expected_asserts) {
|
||||
// initialize cases array if not initialized
|
||||
if (!_hmt_covercases) {
|
||||
_hmt_covercases = (hmt_covercase*) malloc(HMT_ARRAY_SIZE * sizeof(hmt_covercase));
|
||||
}
|
||||
|
||||
// check for existing case with that name, because the macro can run multiple
|
||||
// times in different translation units
|
||||
for (int i = 0; i < _hmt_num_covercases; i++) {
|
||||
if (strcmp(_hmt_covercases[i].name, name) == 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_hmt_covercases[_hmt_num_covercases] = _hmt_new_covercase(name, atoi(expected_asserts));
|
||||
_hmt_num_covercases++;
|
||||
}
|
||||
|
||||
hmt_covercase* _hmt_find_covercase(const char* name) {
|
||||
for (int i = 0; i < _hmt_num_covercases; i++) {
|
||||
if (strcmp(_hmt_covercases[i].name, name) == 0) {
|
||||
return &_hmt_covercases[i];
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void _hmt_count_cover(const char* name, int line) {
|
||||
hmt_covercase* covercase = _hmt_find_covercase(name);
|
||||
if (covercase == 0) {
|
||||
printf(HMT_RED "ERROR (line %d): Could not find coverage case with name \"%s\".\n" HMT_RESET, line, name);
|
||||
_hmt_num_covererrors++;
|
||||
return;
|
||||
}
|
||||
|
||||
// see if this line has already been covered
|
||||
for (int i = 0; i < covercase->actual_asserts; i++) {
|
||||
if (covercase->asserted_lines[i] == line) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
covercase->asserted_lines[covercase->actual_asserts] = line;
|
||||
covercase->actual_asserts++;
|
||||
}
|
||||
|
||||
int hmt_run_all_tests() {
|
||||
int count_alltests = 0;
|
||||
int count_allfailedtests = 0; // failed test cases
|
||||
int count_allfailures = 0; // failed asserts
|
||||
|
||||
for (int i = 0; i < hmt_num_categories; i++) {
|
||||
hmt_category cat = categories[i];
|
||||
int count_catfailedtests = 0;
|
||||
for (int i = 0; i < _hmt_num_categories; i++) {
|
||||
hmt_category cat = _hmt_categories[i];
|
||||
int count_catfailedtests = 0;
|
||||
int count_catfailures = 0;
|
||||
|
||||
printf("\n%s:\n", cat.name);
|
||||
@@ -142,8 +383,8 @@ int hmt_run_all_tests() {
|
||||
printf(" %s:", test.name);
|
||||
|
||||
hmt_testresult result = {
|
||||
.count_cases = 0,
|
||||
.count_failures = 0
|
||||
0, // count_cases
|
||||
0, // count_failures
|
||||
};
|
||||
test.func(&result);
|
||||
|
||||
@@ -177,87 +418,38 @@ int hmt_run_all_tests() {
|
||||
return (count_allfailedtests > 0);
|
||||
}
|
||||
|
||||
#define _HMT_TEST_FUNCNAME(category, name) category ## _ ## name
|
||||
#define _HMT_TEST_FUNCNAME_INIT(category, name) category ## _ ## name ## _init
|
||||
int hmt_check_all_coverage() {
|
||||
printf("Coverage:\n");
|
||||
|
||||
#define HMT_TEST(category, name) \
|
||||
void _HMT_TEST_FUNCNAME(category, name)(hmt_testresult* _result); \
|
||||
INITIALIZER(_HMT_TEST_FUNCNAME_INIT(category, name)) { \
|
||||
hmt_register_test(#category, #name, _HMT_TEST_FUNCNAME(category, name)); \
|
||||
} \
|
||||
void _HMT_TEST_FUNCNAME(category, name)(hmt_testresult* _result)
|
||||
int count_failures = 0;
|
||||
|
||||
#define _HMT_CASE_START() \
|
||||
_result->count_cases++;
|
||||
for (int i = 0; i < _hmt_num_covercases; i++) {
|
||||
hmt_covercase covercase = _hmt_covercases[i];
|
||||
|
||||
#define _HMT_CASE_FAIL() \
|
||||
_result->count_failures++; \
|
||||
printf("\n - " HMT_RED "[FAIL] (%d) " HMT_RESET, __LINE__);
|
||||
if (covercase.expected_asserts != covercase.actual_asserts) {
|
||||
count_failures++;
|
||||
printf("%s: " HMT_RED "FAIL (expected %d asserts, got %d)\n" HMT_RESET, covercase.name, covercase.expected_asserts, covercase.actual_asserts);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Asserts and expects
|
||||
*/
|
||||
#define HMT_EXPECT_TRUE(_actual) do { \
|
||||
_HMT_CASE_START(); \
|
||||
if (!(_actual)) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected true but got something false"); \
|
||||
} \
|
||||
} while (0)
|
||||
if (count_failures > 0) {
|
||||
printf("\n");
|
||||
printf(HMT_RED);
|
||||
} else {
|
||||
printf(HMT_GREEN);
|
||||
}
|
||||
printf("%d coverage cases tested, %d failures\n", _hmt_num_covercases, count_failures);
|
||||
printf(HMT_RESET);
|
||||
|
||||
#define HMT_EXPECT_FALSE(_actual) do { \
|
||||
_HMT_CASE_START(); \
|
||||
if (_actual) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected false but got something true"); \
|
||||
} \
|
||||
} while (0)
|
||||
printf("\n");
|
||||
|
||||
#define HMT_EXPECT_FLOAT_EQ(_actual, _expected) do { \
|
||||
_HMT_CASE_START(); \
|
||||
float actual = (_actual); \
|
||||
float diff = actual - (_expected); \
|
||||
if (diff < -FLT_EPSILON || FLT_EPSILON < diff) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected %f, got %f", (_expected), actual); \
|
||||
} \
|
||||
} while (0)
|
||||
if (_hmt_num_covererrors > 0) {
|
||||
printf(HMT_RED "There were %d other coverage errors; scroll up to see them.\n", _hmt_num_covererrors);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define HMT_EXPECT_NEAR(_actual, _expected, _epsilon) do { \
|
||||
_HMT_CASE_START(); \
|
||||
float actual = (_actual); \
|
||||
float diff = actual - (_expected); \
|
||||
if (diff < -(_epsilon) || (_epsilon) < diff) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected %f, got %f", (_expected), actual); \
|
||||
} \
|
||||
} while (0)
|
||||
return (count_failures > 0);
|
||||
}
|
||||
|
||||
#define HMT_EXPECT_LT(_actual, _expected) do { \
|
||||
_HMT_CASE_START(); \
|
||||
if ((_actual) >= (_expected)) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected %f to be less than %f", (_actual), (_expected)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define HMT_EXPECT_GT(_actual, _expected) do { \
|
||||
_HMT_CASE_START(); \
|
||||
if ((_actual) <= (_expected)) { \
|
||||
_HMT_CASE_FAIL(); \
|
||||
printf("Expected %f to be greater than %f", (_actual), (_expected)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#ifndef HMT_SAFE_MACROS
|
||||
// Friendly defines
|
||||
#define TEST(category, name) HMT_TEST(category, name)
|
||||
#define EXPECT_TRUE(_actual) HMT_EXPECT_TRUE(_actual)
|
||||
#define EXPECT_FALSE(_actual) HMT_EXPECT_FALSE(_actual)
|
||||
#define EXPECT_FLOAT_EQ(_actual, _expected) HMT_EXPECT_FLOAT_EQ(_actual, _expected)
|
||||
#define EXPECT_NEAR(_actual, _expected, _epsilon) HMT_EXPECT_NEAR(_actual, _expected, _epsilon)
|
||||
#define EXPECT_LT(_actual, _expected) HMT_EXPECT_LT(_actual, _expected)
|
||||
#define EXPECT_GT(_actual, _expected) HMT_EXPECT_GT(_actual, _expected)
|
||||
#endif // HMT_SAFE_MACROS
|
||||
|
||||
#endif // HANDMADETEST_H
|
||||
#endif // HANDMADE_TEST_IMPLEMENTATION_GUARD
|
||||
#endif // HANDMADE_TEST_IMPLEMENTATION
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
BUILD_DIR=build
|
||||
BUILD_DIR=./build
|
||||
|
||||
CXXFLAGS+=-g -Wall -Wextra -pthread -Wno-missing-braces -Wno-missing-field-initializers
|
||||
CXXFLAGS+=-g -Wall -Wextra -pthread -Wno-missing-braces -Wno-missing-field-initializers -Wfloat-equal
|
||||
|
||||
all: c c_no_sse cpp cpp_no_sse
|
||||
all: c c_no_sse cpp cpp_no_sse build_c_without_coverage build_cpp_without_coverage
|
||||
|
||||
build_all: build_c build_c_no_sse build_cpp build_cpp_no_sse
|
||||
|
||||
clean:
|
||||
rm -rf $(BUILD_DIR)
|
||||
|
||||
c: HandmadeMath.c test_impl
|
||||
c: build_c
|
||||
$(BUILD_DIR)/hmm_test_c
|
||||
|
||||
build_c: HandmadeMath.c test_impl
|
||||
@echo "\nCompiling in C mode"
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cd $(BUILD_DIR)\
|
||||
@@ -16,7 +21,10 @@ c: HandmadeMath.c test_impl
|
||||
-lm \
|
||||
&& $(CC) -ohmm_test_c HandmadeMath.o hmm_test.o -lm
|
||||
|
||||
c_no_sse: HandmadeMath.c test_impl
|
||||
c_no_sse: build_c_no_sse
|
||||
$(BUILD_DIR)/hmm_test_c_no_sse
|
||||
|
||||
build_c_no_sse: HandmadeMath.c test_impl
|
||||
@echo "\nCompiling in C mode (no SSE)"
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cd $(BUILD_DIR) \
|
||||
@@ -26,7 +34,10 @@ c_no_sse: HandmadeMath.c test_impl
|
||||
-lm \
|
||||
&& $(CC) -ohmm_test_c_no_sse HandmadeMath.o hmm_test.o -lm
|
||||
|
||||
cpp: HandmadeMath.cpp test_impl
|
||||
cpp: build_cpp
|
||||
$(BUILD_DIR)/hmm_test_cpp
|
||||
|
||||
build_cpp: HandmadeMath.cpp test_impl
|
||||
@echo "\nCompiling in C++ mode"
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cd $(BUILD_DIR) \
|
||||
@@ -34,7 +45,10 @@ cpp: HandmadeMath.cpp test_impl
|
||||
-DHANDMADE_MATH_CPP_MODE \
|
||||
../HandmadeMath.cpp ../hmm_test.cpp
|
||||
|
||||
cpp_no_sse: HandmadeMath.cpp test_impl
|
||||
cpp_no_sse: build_cpp_no_sse
|
||||
$(BUILD_DIR)/hmm_test_cpp_no_sse
|
||||
|
||||
build_cpp_no_sse: HandmadeMath.cpp test_impl
|
||||
@echo "\nCompiling in C++ mode (no SSE)"
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cd $(BUILD_DIR) \
|
||||
@@ -43,3 +57,22 @@ cpp_no_sse: HandmadeMath.cpp test_impl
|
||||
../HandmadeMath.cpp ../hmm_test.cpp
|
||||
|
||||
test_impl: hmm_test.cpp hmm_test.c
|
||||
|
||||
build_c_without_coverage: HandmadeMath.c test_impl
|
||||
@echo "\nCompiling in C mode"
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cd $(BUILD_DIR)\
|
||||
&& $(CC) $(CPPFLAGS) $(CXXFLAGS) -std=c99 \
|
||||
-DWITHOUT_COVERAGE \
|
||||
-c ../HandmadeMath.c ../hmm_test.c \
|
||||
-lm \
|
||||
&& $(CC) -ohmm_test_c HandmadeMath.o hmm_test.o -lm
|
||||
|
||||
build_cpp_without_coverage: HandmadeMath.cpp test_impl
|
||||
@echo "\nCompiling in C++ mode (no SSE)"
|
||||
mkdir -p $(BUILD_DIR)
|
||||
cd $(BUILD_DIR) \
|
||||
&& $(CXX) $(CPPFLAGS) $(CXXFLAGS) -ohmm_test_cpp_no_sse \
|
||||
-DHANDMADE_MATH_CPP_MODE -DWITHOUT_COVERAGE \
|
||||
../HandmadeMath.cpp ../hmm_test.cpp
|
||||
|
||||
|
||||
@@ -4,8 +4,13 @@ You can compile and run the tests yourself by running:
|
||||
|
||||
```
|
||||
make
|
||||
build/hmm_test_c
|
||||
build/hmm_test_c_no_sse
|
||||
build/hmm_test_cpp
|
||||
build/hmm_test_cpp_no_sse
|
||||
```
|
||||
|
||||
To run a specific test configuration, run one of:
|
||||
|
||||
```
|
||||
make c
|
||||
make c_no_sse
|
||||
make cpp
|
||||
make cpp_no_sse
|
||||
```
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
TEST(Addition, Vec2)
|
||||
{
|
||||
hmm_vec2 v2_1 = HMM_Vec2(1.0f, 2.0f);
|
||||
hmm_vec2 v2_2 = HMM_Vec2(3.0f, 4.0f);
|
||||
HMM_Vec2 v2_1 = HMM_V2(1.0f, 2.0f);
|
||||
HMM_Vec2 v2_2 = HMM_V2(3.0f, 4.0f);
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_AddVec2(v2_1, v2_2);
|
||||
HMM_Vec2 result = HMM_AddV2(v2_1, v2_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_Add(v2_1, v2_2);
|
||||
HMM_Vec2 result = HMM_Add(v2_1, v2_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec2 result = v2_1 + v2_2;
|
||||
HMM_Vec2 result = v2_1 + v2_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
}
|
||||
@@ -30,24 +30,24 @@ TEST(Addition, Vec2)
|
||||
|
||||
TEST(Addition, Vec3)
|
||||
{
|
||||
hmm_vec3 v3_1 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 v3_2 = HMM_Vec3(4.0f, 5.0f, 6.0f);
|
||||
HMM_Vec3 v3_1 = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 v3_2 = HMM_V3(4.0f, 5.0f, 6.0f);
|
||||
|
||||
{
|
||||
hmm_vec3 result = HMM_AddVec3(v3_1, v3_2);
|
||||
HMM_Vec3 result = HMM_AddV3(v3_1, v3_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 5.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 7.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec3 result = HMM_Add(v3_1, v3_2);
|
||||
HMM_Vec3 result = HMM_Add(v3_1, v3_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 5.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 7.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = v3_1 + v3_2;
|
||||
HMM_Vec3 result = v3_1 + v3_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 5.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 7.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
@@ -62,11 +62,11 @@ TEST(Addition, Vec3)
|
||||
|
||||
TEST(Addition, Vec4)
|
||||
{
|
||||
hmm_vec4 v4_1 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_vec4 v4_2 = HMM_Vec4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
HMM_Vec4 v4_1 = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 v4_2 = HMM_V4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
{
|
||||
hmm_vec4 result = HMM_AddVec4(v4_1, v4_2);
|
||||
HMM_Vec4 result = HMM_AddV4(v4_1, v4_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
@@ -74,14 +74,14 @@ TEST(Addition, Vec4)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec4 result = HMM_Add(v4_1, v4_2);
|
||||
HMM_Vec4 result = HMM_Add(v4_1, v4_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 12.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = v4_1 + v4_2;
|
||||
HMM_Vec4 result = v4_1 + v4_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
@@ -96,10 +96,134 @@ TEST(Addition, Vec4)
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Addition, Mat2)
|
||||
{
|
||||
HMM_Mat2 a = HMM_M2();
|
||||
HMM_Mat2 b = HMM_M2();
|
||||
|
||||
int Counter = 1;
|
||||
for (int Column = 0; Column < 2; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 2; ++Row)
|
||||
{
|
||||
a.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
for (int Column = 0; Column < 2; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 2; ++Row)
|
||||
{
|
||||
b.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 result = HMM_AddM2(a, b);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 12.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat2 result = HMM_Add(a, b);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 12.0f);
|
||||
}
|
||||
{
|
||||
HMM_Mat2 result = a + b;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 12.0f);
|
||||
}
|
||||
a += b;
|
||||
EXPECT_FLOAT_EQ(a.Elements[0][0], 6.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[0][1], 8.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[1][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[1][1], 12.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Addition, Mat3)
|
||||
{
|
||||
HMM_Mat3 a = HMM_M3();
|
||||
HMM_Mat3 b = HMM_M3();
|
||||
|
||||
int Counter = 1;
|
||||
for (int Column = 0; Column < 3; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 3; ++Row)
|
||||
{
|
||||
a.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
for (int Column = 0; Column < 3; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 3; ++Row)
|
||||
{
|
||||
b.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 result = HMM_AddM3(a, b);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 11.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 13.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 15.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 17.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 19.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 21.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 25.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 27.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat3 result = HMM_Add(a, b);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 11.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 13.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 15.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 17.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 19.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 21.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 25.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 27.0f);
|
||||
}
|
||||
{
|
||||
HMM_Mat3 result = a + b;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 11.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 13.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 15.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 17.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 19.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 21.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 25.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 27.0f);
|
||||
}
|
||||
a += b;
|
||||
EXPECT_FLOAT_EQ(a.Elements[0][0], 11.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[0][1], 13.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[0][2], 15.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[1][0], 17.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[1][1], 19.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[1][2], 21.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[2][0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[2][1], 25.0f);
|
||||
EXPECT_FLOAT_EQ(a.Elements[2][2], 27.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Addition, Mat4)
|
||||
{
|
||||
hmm_mat4 m4_1 = HMM_Mat4(); // will have 1 - 16
|
||||
hmm_mat4 m4_2 = HMM_Mat4(); // will have 17 - 32
|
||||
HMM_Mat4 m4_1 = HMM_M4(); // will have 1 - 16
|
||||
HMM_Mat4 m4_2 = HMM_M4(); // will have 17 - 32
|
||||
|
||||
// Fill the matrices
|
||||
int Counter = 1;
|
||||
@@ -122,7 +246,7 @@ TEST(Addition, Mat4)
|
||||
|
||||
// Test the results
|
||||
{
|
||||
hmm_mat4 result = HMM_AddMat4(m4_1, m4_2);
|
||||
HMM_Mat4 result = HMM_AddM4(m4_1, m4_2);
|
||||
float Expected = 18.0f;
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
@@ -135,7 +259,7 @@ TEST(Addition, Mat4)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_mat4 result = HMM_Add(m4_1, m4_2);
|
||||
HMM_Mat4 result = HMM_Add(m4_1, m4_2);
|
||||
float Expected = 18.0f;
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
@@ -147,7 +271,7 @@ TEST(Addition, Mat4)
|
||||
}
|
||||
}
|
||||
{
|
||||
hmm_mat4 result = m4_1 + m4_2;
|
||||
HMM_Mat4 result = m4_1 + m4_2;
|
||||
float Expected = 18.0f;
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
@@ -174,11 +298,11 @@ TEST(Addition, Mat4)
|
||||
|
||||
TEST(Addition, Quaternion)
|
||||
{
|
||||
hmm_quaternion q1 = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_quaternion q2 = HMM_Quaternion(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
HMM_Quat q1 = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat q2 = HMM_Q(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
{
|
||||
hmm_quaternion result = HMM_AddQuaternion(q1, q2);
|
||||
HMM_Quat result = HMM_AddQ(q1, q2);
|
||||
EXPECT_FLOAT_EQ(result.X, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
@@ -186,14 +310,14 @@ TEST(Addition, Quaternion)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_quaternion result = HMM_Add(q1, q2);
|
||||
HMM_Quat result = HMM_Add(q1, q2);
|
||||
EXPECT_FLOAT_EQ(result.X, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 12.0f);
|
||||
}
|
||||
{
|
||||
hmm_quaternion result = q1 + q2;
|
||||
HMM_Quat result = q1 + q2;
|
||||
EXPECT_FLOAT_EQ(result.X, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
TEST(Division, Vec2Vec2)
|
||||
{
|
||||
hmm_vec2 v2_1 = HMM_Vec2(1.0f, 3.0f);
|
||||
hmm_vec2 v2_2 = HMM_Vec2(2.0f, 4.0f);
|
||||
HMM_Vec2 v2_1 = HMM_V2(1.0f, 3.0f);
|
||||
HMM_Vec2 v2_2 = HMM_V2(2.0f, 4.0f);
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_DivideVec2(v2_1, v2_2);
|
||||
HMM_Vec2 result = HMM_DivV2(v2_1, v2_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_Divide(v2_1, v2_2);
|
||||
HMM_Vec2 result = HMM_Div(v2_1, v2_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
}
|
||||
{
|
||||
hmm_vec2 result = v2_1 / v2_2;
|
||||
HMM_Vec2 result = v2_1 / v2_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
}
|
||||
@@ -30,22 +30,22 @@ TEST(Division, Vec2Vec2)
|
||||
|
||||
TEST(Division, Vec2Scalar)
|
||||
{
|
||||
hmm_vec2 v2 = HMM_Vec2(1.0f, 2.0f);
|
||||
HMM_Vec2 v2 = HMM_V2(1.0f, 2.0f);
|
||||
float s = 2;
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_DivideVec2f(v2, s);
|
||||
HMM_Vec2 result = HMM_DivV2F(v2, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_Divide(v2, s);
|
||||
HMM_Vec2 result = HMM_Div(v2, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec2 result = v2 / s;
|
||||
HMM_Vec2 result = v2 / s;
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
}
|
||||
@@ -58,24 +58,24 @@ TEST(Division, Vec2Scalar)
|
||||
|
||||
TEST(Division, Vec3Vec3)
|
||||
{
|
||||
hmm_vec3 v3_1 = HMM_Vec3(1.0f, 3.0f, 5.0f);
|
||||
hmm_vec3 v3_2 = HMM_Vec3(2.0f, 4.0f, 0.5f);
|
||||
HMM_Vec3 v3_1 = HMM_V3(1.0f, 3.0f, 5.0f);
|
||||
HMM_Vec3 v3_2 = HMM_V3(2.0f, 4.0f, 0.5f);
|
||||
|
||||
{
|
||||
hmm_vec3 result = HMM_DivideVec3(v3_1, v3_2);
|
||||
HMM_Vec3 result = HMM_DivV3(v3_1, v3_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec3 result = HMM_Divide(v3_1, v3_2);
|
||||
HMM_Vec3 result = HMM_Div(v3_1, v3_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = v3_1 / v3_2;
|
||||
HMM_Vec3 result = v3_1 / v3_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
@@ -90,24 +90,24 @@ TEST(Division, Vec3Vec3)
|
||||
|
||||
TEST(Division, Vec3Scalar)
|
||||
{
|
||||
hmm_vec3 v3 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 v3 = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
float s = 2;
|
||||
|
||||
{
|
||||
hmm_vec3 result = HMM_DivideVec3f(v3, s);
|
||||
HMM_Vec3 result = HMM_DivV3F(v3, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec3 result = HMM_Divide(v3, s);
|
||||
HMM_Vec3 result = HMM_Div(v3, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = v3 / s;
|
||||
HMM_Vec3 result = v3 / s;
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
@@ -122,11 +122,11 @@ TEST(Division, Vec3Scalar)
|
||||
|
||||
TEST(Division, Vec4Vec4)
|
||||
{
|
||||
hmm_vec4 v4_1 = HMM_Vec4(1.0f, 3.0f, 5.0f, 1.0f);
|
||||
hmm_vec4 v4_2 = HMM_Vec4(2.0f, 4.0f, 0.5f, 4.0f);
|
||||
HMM_Vec4 v4_1 = HMM_V4(1.0f, 3.0f, 5.0f, 1.0f);
|
||||
HMM_Vec4 v4_2 = HMM_V4(2.0f, 4.0f, 0.5f, 4.0f);
|
||||
|
||||
{
|
||||
hmm_vec4 result = HMM_DivideVec4(v4_1, v4_2);
|
||||
HMM_Vec4 result = HMM_DivV4(v4_1, v4_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
@@ -134,14 +134,14 @@ TEST(Division, Vec4Vec4)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec4 result = HMM_Divide(v4_1, v4_2);
|
||||
HMM_Vec4 result = HMM_Div(v4_1, v4_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.25f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = v4_1 / v4_2;
|
||||
HMM_Vec4 result = v4_1 / v4_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.75f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 10.0f);
|
||||
@@ -158,11 +158,11 @@ TEST(Division, Vec4Vec4)
|
||||
|
||||
TEST(Division, Vec4Scalar)
|
||||
{
|
||||
hmm_vec4 v4 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 v4 = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
float s = 2;
|
||||
|
||||
{
|
||||
hmm_vec4 result = HMM_DivideVec4f(v4, s);
|
||||
HMM_Vec4 result = HMM_DivV4F(v4, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
@@ -170,14 +170,14 @@ TEST(Division, Vec4Scalar)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec4 result = HMM_Divide(v4, s);
|
||||
HMM_Vec4 result = HMM_Div(v4, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
EXPECT_FLOAT_EQ(result.W, 2.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = v4 / s;
|
||||
HMM_Vec4 result = v4 / s;
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
@@ -192,9 +192,103 @@ TEST(Division, Vec4Scalar)
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Division, Mat2Scalar)
|
||||
{
|
||||
HMM_Mat2 m = HMM_M2();
|
||||
float s = 0.5f;
|
||||
|
||||
int Counter = 1;
|
||||
for (int Column = 0; Column < 2; ++Column) {
|
||||
for (int Row = 0; Row < 2; ++Row) {
|
||||
m.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 result = HMM_DivM2F(m, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 8.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat2 result = HMM_Div(m, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 8.0f);
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 result = m / s;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 8.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
TEST(Division, Mat3Scalar)
|
||||
{
|
||||
HMM_Mat3 m = HMM_M3();
|
||||
float s = 0.5f;
|
||||
|
||||
int Counter = 1;
|
||||
for (int Column = 0; Column < 3; ++Column) {
|
||||
for (int Row = 0; Row < 3; ++Row) {
|
||||
m.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 result = HMM_DivM3F(m, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 12.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 14.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 16.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 18.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat3 result = HMM_Div(m, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 12.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 14.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 16.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 18.0f);
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 result = m / s;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 8.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 12.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 14.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 16.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 18.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Division, Mat4Scalar)
|
||||
{
|
||||
hmm_mat4 m4 = HMM_Mat4(); // will have 1 - 16
|
||||
HMM_Mat4 m4 = HMM_M4(); // will have 1 - 16
|
||||
float s = 2;
|
||||
|
||||
// Fill the matrix
|
||||
@@ -210,7 +304,7 @@ TEST(Division, Mat4Scalar)
|
||||
|
||||
// Test the results
|
||||
{
|
||||
hmm_mat4 result = HMM_DivideMat4f(m4, s);
|
||||
HMM_Mat4 result = HMM_DivM4F(m4, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 1.5f);
|
||||
@@ -230,7 +324,7 @@ TEST(Division, Mat4Scalar)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_mat4 result = HMM_Divide(m4, s);
|
||||
HMM_Mat4 result = HMM_Div(m4, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 1.5f);
|
||||
@@ -249,7 +343,7 @@ TEST(Division, Mat4Scalar)
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][3], 8.0f);
|
||||
}
|
||||
{
|
||||
hmm_mat4 result = m4 / s;
|
||||
HMM_Mat4 result = m4 / s;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 1.5f);
|
||||
@@ -290,11 +384,11 @@ TEST(Division, Mat4Scalar)
|
||||
|
||||
TEST(Division, QuaternionScalar)
|
||||
{
|
||||
hmm_quaternion q = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat q = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
float f = 2.0f;
|
||||
|
||||
{
|
||||
hmm_quaternion result = HMM_DivideQuaternionF(q, f);
|
||||
HMM_Quat result = HMM_DivQF(q, f);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
@@ -302,14 +396,14 @@ TEST(Division, QuaternionScalar)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_quaternion result = HMM_Divide(q, f);
|
||||
HMM_Quat result = HMM_Div(q, f);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
EXPECT_FLOAT_EQ(result.W, 2.0f);
|
||||
}
|
||||
{
|
||||
hmm_quaternion result = q / f;
|
||||
HMM_Quat result = q / f;
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 1.5f);
|
||||
|
||||
@@ -2,54 +2,63 @@
|
||||
|
||||
TEST(Equality, Vec2)
|
||||
{
|
||||
hmm_vec2 a = HMM_Vec2(1.0f, 2.0f);
|
||||
hmm_vec2 b = HMM_Vec2(1.0f, 2.0f);
|
||||
hmm_vec2 c = HMM_Vec2(3.0f, 4.0f);
|
||||
HMM_Vec2 a = HMM_V2(1.0f, 2.0f);
|
||||
HMM_Vec2 b = HMM_V2(1.0f, 2.0f);
|
||||
HMM_Vec2 c = HMM_V2(3.0f, 4.0f);
|
||||
|
||||
EXPECT_TRUE(HMM_EqualsVec2(a, b));
|
||||
EXPECT_FALSE(HMM_EqualsVec2(a, c));
|
||||
EXPECT_TRUE(HMM_EqV2(a, b));
|
||||
EXPECT_FALSE(HMM_EqV2(a, c));
|
||||
|
||||
#ifdef __cplusplus
|
||||
EXPECT_TRUE(HMM_Equals(a, b));
|
||||
EXPECT_FALSE(HMM_Equals(a, c));
|
||||
EXPECT_TRUE(HMM_Eq(a, b));
|
||||
EXPECT_FALSE(HMM_Eq(a, c));
|
||||
|
||||
EXPECT_TRUE(a == b);
|
||||
EXPECT_FALSE(a == c);
|
||||
|
||||
EXPECT_FALSE(a != b);
|
||||
EXPECT_TRUE(a != c);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Equality, Vec3)
|
||||
{
|
||||
hmm_vec3 a = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 b = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 c = HMM_Vec3(4.0f, 5.0f, 6.0f);
|
||||
HMM_Vec3 a = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 b = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 c = HMM_V3(4.0f, 5.0f, 6.0f);
|
||||
|
||||
EXPECT_TRUE(HMM_EqualsVec3(a, b));
|
||||
EXPECT_FALSE(HMM_EqualsVec3(a, c));
|
||||
EXPECT_TRUE(HMM_EqV3(a, b));
|
||||
EXPECT_FALSE(HMM_EqV3(a, c));
|
||||
|
||||
#ifdef __cplusplus
|
||||
EXPECT_TRUE(HMM_Equals(a, b));
|
||||
EXPECT_FALSE(HMM_Equals(a, c));
|
||||
EXPECT_TRUE(HMM_Eq(a, b));
|
||||
EXPECT_FALSE(HMM_Eq(a, c));
|
||||
|
||||
EXPECT_TRUE(a == b);
|
||||
EXPECT_FALSE(a == c);
|
||||
|
||||
EXPECT_FALSE(a != b);
|
||||
EXPECT_TRUE(a != c);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Equality, Vec4)
|
||||
{
|
||||
hmm_vec4 a = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_vec4 b = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_vec4 c = HMM_Vec4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
HMM_Vec4 a = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 b = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 c = HMM_V4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
EXPECT_TRUE(HMM_EqualsVec4(a, b));
|
||||
EXPECT_FALSE(HMM_EqualsVec4(a, c));
|
||||
EXPECT_TRUE(HMM_EqV4(a, b));
|
||||
EXPECT_FALSE(HMM_EqV4(a, c));
|
||||
|
||||
#ifdef __cplusplus
|
||||
EXPECT_TRUE(HMM_Equals(a, b));
|
||||
EXPECT_FALSE(HMM_Equals(a, c));
|
||||
EXPECT_TRUE(HMM_Eq(a, b));
|
||||
EXPECT_FALSE(HMM_Eq(a, c));
|
||||
|
||||
EXPECT_TRUE(a == b);
|
||||
EXPECT_FALSE(a == c);
|
||||
|
||||
EXPECT_FALSE(a != b);
|
||||
EXPECT_TRUE(a != c);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -4,9 +4,8 @@ TEST(Initialization, Vectors)
|
||||
{
|
||||
//
|
||||
// Test vec2
|
||||
//
|
||||
hmm_vec2 v2 = HMM_Vec2(1.0f, 2.0f);
|
||||
hmm_vec2 v2i = HMM_Vec2(1, 2);
|
||||
//
|
||||
HMM_Vec2 v2 = HMM_V2(1.0f, 2.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(v2.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2.Y, 2.0f);
|
||||
@@ -23,26 +22,10 @@ TEST(Initialization, Vectors)
|
||||
EXPECT_FLOAT_EQ(v2[1], 2.0f);
|
||||
#endif
|
||||
|
||||
EXPECT_FLOAT_EQ(v2i.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.Y, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.U, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.V, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.Left, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.Right, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.Width, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.Height, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2i.Elements[1], 2.0f);
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(v2i[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v2i[1], 2.0f);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Test vec3
|
||||
//
|
||||
hmm_vec3 v3 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 v3i = HMM_Vec3i(1, 2, 3);
|
||||
HMM_Vec3 v3 = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(v3.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3.Y, 2.0f);
|
||||
@@ -70,38 +53,11 @@ TEST(Initialization, Vectors)
|
||||
EXPECT_FLOAT_EQ(v3[2], 3.0f);
|
||||
#endif
|
||||
|
||||
EXPECT_FLOAT_EQ(v3i.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.Y, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.Z, 3.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.U, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.V, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.W, 3.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.R, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.G, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.B, 3.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.Elements[2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.XY.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.XY.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.YZ.Elements[0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.YZ.Elements[1], 3.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.UV.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.UV.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.VW.Elements[0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i.VW.Elements[1], 3.0f);
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(v3i[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v3i[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v3i[2], 3.0f);
|
||||
#endif
|
||||
|
||||
//
|
||||
// Test vec4
|
||||
//
|
||||
hmm_vec4 v4 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_vec4 v4i = HMM_Vec4i(1, 2, 3, 4);
|
||||
hmm_vec4 v4v = HMM_Vec4v(v3, 4.0f);
|
||||
HMM_Vec4 v4 = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 v4v = HMM_V4V(v3, 4.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(v4.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4.Y, 2.0f);
|
||||
@@ -132,35 +88,6 @@ TEST(Initialization, Vectors)
|
||||
EXPECT_FLOAT_EQ(v4[3], 4.0f);
|
||||
#endif
|
||||
|
||||
EXPECT_FLOAT_EQ(v4i.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.Y, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.Z, 3.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.W, 4.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.R, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.G, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.B, 3.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.A, 4.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.XY.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.XY.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.YZ.Elements[0], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.YZ.Elements[1], 3.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.ZW.Elements[0], 3.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.ZW.Elements[1], 4.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.XY.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.XY.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.XYZ.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.XYZ.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.XYZ.Elements[2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.RGB.Elements[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.RGB.Elements[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i.RGB.Elements[2], 3.0f);
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(v4i[0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4i[1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4i[2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(v4i[3], 4.0f);
|
||||
#endif
|
||||
|
||||
EXPECT_FLOAT_EQ(v4v.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(v4v.Y, 2.0f);
|
||||
EXPECT_FLOAT_EQ(v4v.Z, 3.0f);
|
||||
@@ -193,7 +120,40 @@ TEST(Initialization, Vectors)
|
||||
|
||||
TEST(Initialization, MatrixEmpty)
|
||||
{
|
||||
hmm_mat4 m4 = HMM_Mat4();
|
||||
//
|
||||
// Test mat2
|
||||
//
|
||||
HMM_Mat2 m2 = HMM_M2();
|
||||
for (int Column = 0; Column < 2; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 2; ++Row)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(m2.Elements[Column][Row], 0.0f);
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(m2[Column][Row], 0.0f);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Test mat3
|
||||
//
|
||||
HMM_Mat3 m3 = HMM_M3();
|
||||
for (int Column = 0; Column < 3; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 3; ++Row)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(m3.Elements[Column][Row], 0.0f);
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(m3[Column][Row], 0.0f);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Test mat4
|
||||
//
|
||||
HMM_Mat4 m4 = HMM_M4();
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 4; ++Row)
|
||||
@@ -208,7 +168,42 @@ TEST(Initialization, MatrixEmpty)
|
||||
|
||||
TEST(Initialization, MatrixDiagonal)
|
||||
{
|
||||
hmm_mat4 m4d = HMM_Mat4d(1.0f);
|
||||
//
|
||||
// Test mat2
|
||||
//
|
||||
HMM_Mat2 m2d = HMM_M2D(1.0f);
|
||||
for (int Column = 0; Column < 2; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 2; ++Row)
|
||||
{
|
||||
if (Column == Row) {
|
||||
EXPECT_FLOAT_EQ(m2d.Elements[Column][Row], 1.0f);
|
||||
} else {
|
||||
EXPECT_FLOAT_EQ(m2d.Elements[Column][Row], 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Test mat3
|
||||
//
|
||||
HMM_Mat3 m3d = HMM_M3D(1.0f);
|
||||
for (int Column = 0; Column < 3; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 3; ++Row)
|
||||
{
|
||||
if (Column == Row) {
|
||||
EXPECT_FLOAT_EQ(m3d.Elements[Column][Row], 1.0f);
|
||||
} else {
|
||||
EXPECT_FLOAT_EQ(m3d.Elements[Column][Row], 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Test mat4
|
||||
//
|
||||
HMM_Mat4 m4d = HMM_M4D(1.0f);
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 4; ++Row)
|
||||
@@ -224,7 +219,7 @@ TEST(Initialization, MatrixDiagonal)
|
||||
|
||||
TEST(Initialization, Quaternion)
|
||||
{
|
||||
hmm_quaternion q = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat q = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(q.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(q.Y, 2.0f);
|
||||
@@ -236,11 +231,91 @@ TEST(Initialization, Quaternion)
|
||||
EXPECT_FLOAT_EQ(q.Elements[2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(q.Elements[3], 4.0f);
|
||||
|
||||
hmm_vec4 v = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_quaternion qv = HMM_QuaternionV4(v);
|
||||
HMM_Vec4 v = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat qv = HMM_QV4(v);
|
||||
|
||||
EXPECT_FLOAT_EQ(qv.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(qv.Y, 2.0f);
|
||||
EXPECT_FLOAT_EQ(qv.Z, 3.0f);
|
||||
EXPECT_FLOAT_EQ(qv.W, 4.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
TEST(Initialization, MatrixOverloads)
|
||||
{
|
||||
// Operator overloads for matrix columns must allow mutation.
|
||||
|
||||
//
|
||||
// Test mat2
|
||||
//
|
||||
HMM_Mat2 m2 = {0};
|
||||
m2[0][0] = 1.0f;
|
||||
m2[0][1] = 2.0f;
|
||||
m2[1][0] = 3.0f;
|
||||
m2[1][1] = 4.0f;
|
||||
EXPECT_FLOAT_EQ(m2.Elements[0][0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(m2.Elements[0][1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(m2.Elements[1][0], 3.0f);
|
||||
EXPECT_FLOAT_EQ(m2.Elements[1][1], 4.0f);
|
||||
|
||||
//
|
||||
// Test mat3
|
||||
//
|
||||
HMM_Mat3 m3 = {0};
|
||||
m3[0][0] = 1.0f;
|
||||
m3[0][1] = 2.0f;
|
||||
m3[0][2] = 3.0f;
|
||||
m3[1][0] = 4.0f;
|
||||
m3[1][1] = 5.0f;
|
||||
m3[1][2] = 6.0f;
|
||||
m3[2][0] = 7.0f;
|
||||
m3[2][1] = 8.0f;
|
||||
m3[2][2] = 9.0f;
|
||||
EXPECT_FLOAT_EQ(m3.Elements[0][0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(m3.Elements[0][1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(m3.Elements[0][2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(m3.Elements[1][0], 4.0f);
|
||||
EXPECT_FLOAT_EQ(m3.Elements[1][1], 5.0f);
|
||||
EXPECT_FLOAT_EQ(m3.Elements[1][2], 6.0f);
|
||||
EXPECT_FLOAT_EQ(m3.Elements[2][0], 7.0f);
|
||||
EXPECT_FLOAT_EQ(m3.Elements[2][1], 8.0f);
|
||||
EXPECT_FLOAT_EQ(m3.Elements[2][2], 9.0f);
|
||||
|
||||
//
|
||||
// Test mat4
|
||||
//
|
||||
HMM_Mat4 m4 = {0};
|
||||
m4[0][0] = 1.0f;
|
||||
m4[0][1] = 2.0f;
|
||||
m4[0][2] = 3.0f;
|
||||
m4[0][3] = 4.0f;
|
||||
m4[1][0] = 5.0f;
|
||||
m4[1][1] = 6.0f;
|
||||
m4[1][2] = 7.0f;
|
||||
m4[1][3] = 8.0f;
|
||||
m4[2][0] = 9.0f;
|
||||
m4[2][1] = 10.0f;
|
||||
m4[2][2] = 11.0f;
|
||||
m4[2][3] = 12.0f;
|
||||
m4[3][0] = 13.0f;
|
||||
m4[3][1] = 14.0f;
|
||||
m4[3][2] = 15.0f;
|
||||
m4[3][3] = 16.0f;
|
||||
EXPECT_FLOAT_EQ(m4.Elements[0][0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[0][1], 2.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[0][2], 3.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[0][3], 4.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[1][0], 5.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[1][1], 6.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[1][2], 7.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[1][3], 8.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[2][0], 9.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[2][1], 10.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[2][2], 11.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[2][3], 12.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[3][0], 13.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[3][1], 14.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[3][2], 15.0f);
|
||||
EXPECT_FLOAT_EQ(m4.Elements[3][3], 16.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
359
test/categories/MatrixOps.h
Normal file
359
test/categories/MatrixOps.h
Normal file
@@ -0,0 +1,359 @@
|
||||
#include "../HandmadeTest.h"
|
||||
|
||||
TEST(InvMatrix, Transpose)
|
||||
{
|
||||
{
|
||||
HMM_Mat2 Matrix = {
|
||||
1.0f, 3.0f,
|
||||
2.0f, 4.0f,
|
||||
};
|
||||
HMM_Mat2 Expect = {
|
||||
1.0f, 2.0f,
|
||||
3.0f, 4.0f,
|
||||
};
|
||||
|
||||
{
|
||||
HMM_Mat2 result = HMM_TransposeM2(Matrix);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], Expect.Elements[1][1]);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat2 result = HMM_Transpose(Matrix);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], Expect.Elements[1][1]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 Matrix = {
|
||||
1.0f, 4.0f, 7.0f,
|
||||
2.0f, 5.0f, 8.0f,
|
||||
3.0f, 6.0f, 9.0f,
|
||||
};
|
||||
HMM_Mat3 Expect = {
|
||||
1.0f, 2.0f, 3.0f,
|
||||
4.0f, 5.0f, 6.0f,
|
||||
7.0f, 8.0f, 9.0f
|
||||
};
|
||||
|
||||
{
|
||||
HMM_Mat3 result = HMM_TransposeM3(Matrix);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], Expect.Elements[0][2]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], Expect.Elements[1][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], Expect.Elements[1][2]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], Expect.Elements[2][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], Expect.Elements[2][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], Expect.Elements[2][2]);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat3 result = HMM_Transpose(Matrix);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], Expect.Elements[0][2]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], Expect.Elements[1][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], Expect.Elements[1][2]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], Expect.Elements[2][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], Expect.Elements[2][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], Expect.Elements[2][2]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
{
|
||||
HMM_Mat4 Matrix = {
|
||||
1.0f, 5.0f, 9.0f, 13.0f,
|
||||
2.0f, 6.0f, 10.0f, 14.0f,
|
||||
3.0f, 7.0f, 11.0f, 15.0f,
|
||||
4.0f, 8.0f, 12.0f, 16.0f
|
||||
};
|
||||
HMM_Mat4 Expect = {
|
||||
1.0f, 2.0f, 3.0f, 4.0f,
|
||||
5.0f, 6.0f, 7.0f, 8.0f,
|
||||
9.0f, 10.0f, 11.0f, 12.0f,
|
||||
13.0f, 14.0f, 15.0f, 16.0f,
|
||||
};
|
||||
{
|
||||
HMM_Mat4 result = HMM_TransposeM4(Matrix);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], Expect.Elements[0][2]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], Expect.Elements[1][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], Expect.Elements[1][2]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], Expect.Elements[2][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], Expect.Elements[2][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], Expect.Elements[2][2]);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat4 result = HMM_Transpose(Matrix);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], Expect.Elements[0][2]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], Expect.Elements[1][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], Expect.Elements[1][2]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], Expect.Elements[2][0]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], Expect.Elements[2][1]);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], Expect.Elements[2][2]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(InvMatrix, InvGeneral)
|
||||
{
|
||||
{
|
||||
HMM_Mat4 Matrix = {
|
||||
12.0f, 2.0f, 1.0f, 1.0f,
|
||||
0.0f, 0.0f, 1.0f, 1.0f,
|
||||
0.0f, 1.0f, 5.0f, 1.0f,
|
||||
11.0f, 1.0f, 0.0f, 10.0f
|
||||
};
|
||||
|
||||
HMM_Mat4 Expect = HMM_M4D(1.0);
|
||||
HMM_Mat4 Inverse = HMM_InvGeneralM4(Matrix);
|
||||
HMM_Mat4 Result = HMM_MulM4(Matrix, Inverse);
|
||||
|
||||
float Det = HMM_DeterminantM4(Matrix);
|
||||
EXPECT_FLOAT_EQ(Det, -80.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][2], Expect.Elements[0][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][3], Expect.Elements[0][3]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][1], Expect.Elements[1][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][2], Expect.Elements[1][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][3], Expect.Elements[1][3]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][0], Expect.Elements[2][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][1], Expect.Elements[2][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][2], Expect.Elements[2][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][3], Expect.Elements[2][3]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][0], Expect.Elements[3][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][1], Expect.Elements[3][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][2], Expect.Elements[3][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][3], Expect.Elements[3][3]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
Inverse = HMM_InvGeneral(Matrix);
|
||||
Result = HMM_Mul(Matrix, Inverse);
|
||||
|
||||
Det = HMM_Determinant(Matrix);
|
||||
EXPECT_FLOAT_EQ(Det, -80.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][2], Expect.Elements[0][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][3], Expect.Elements[0][3]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][1], Expect.Elements[1][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][2], Expect.Elements[1][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][3], Expect.Elements[1][3]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][0], Expect.Elements[2][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][1], Expect.Elements[2][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][2], Expect.Elements[2][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][3], Expect.Elements[2][3]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][0], Expect.Elements[3][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][1], Expect.Elements[3][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][2], Expect.Elements[3][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][3], Expect.Elements[3][3]);
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 Matrix = {
|
||||
12.0f, 2.0f, 1.0f,
|
||||
0.0f, 0.0f, 1.0f,
|
||||
0.0f, 1.0f, 5.0f
|
||||
};
|
||||
|
||||
HMM_Mat3 Expect = HMM_M3D(1.0);
|
||||
HMM_Mat3 Inverse = HMM_InvGeneralM3(Matrix);
|
||||
HMM_Mat3 Result = HMM_MulM3(Matrix, Inverse);
|
||||
|
||||
float Det = HMM_DeterminantM3(Matrix);
|
||||
EXPECT_FLOAT_EQ(Det, -12.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][2], Expect.Elements[0][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][1], Expect.Elements[1][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][2], Expect.Elements[1][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][0], Expect.Elements[2][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][1], Expect.Elements[2][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][2], Expect.Elements[2][2]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
Inverse = HMM_InvGeneral(Matrix);
|
||||
Result = HMM_Mul(Matrix, Inverse);
|
||||
Det = HMM_Determinant(Matrix);
|
||||
EXPECT_FLOAT_EQ(Det, -12.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][2], Expect.Elements[0][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][1], Expect.Elements[1][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][2], Expect.Elements[1][2]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][0], Expect.Elements[2][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][1], Expect.Elements[2][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][2], Expect.Elements[2][2]);
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 Matrix = {
|
||||
12.0f, 2.0f,
|
||||
1.0f, 5.0f
|
||||
};
|
||||
|
||||
HMM_Mat2 Expect = HMM_M2D(1.0);
|
||||
HMM_Mat2 Inverse = HMM_InvGeneralM2(Matrix);
|
||||
HMM_Mat2 Result = HMM_MulM2(Matrix, Inverse);
|
||||
|
||||
float Det = HMM_DeterminantM2(Matrix);
|
||||
EXPECT_FLOAT_EQ(Det, 58.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][1], Expect.Elements[1][1]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
Inverse = HMM_InvGeneral(Matrix);
|
||||
Result = HMM_Mul(Matrix, Inverse);
|
||||
Det = HMM_Determinant(Matrix);
|
||||
EXPECT_FLOAT_EQ(Det, 58.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][0], Expect.Elements[0][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][1], Expect.Elements[0][1]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][0], Expect.Elements[1][0]);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][1], Expect.Elements[1][1]);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
TEST(InvMatrix, InvOrthographic)
|
||||
{
|
||||
{
|
||||
HMM_Mat4 Matrix = HMM_Orthographic_RH_NO(-160+100, 160+100, -90+200, 90+200, 10, 10000);
|
||||
HMM_Mat4 Inverse = HMM_InvOrthographic(Matrix);
|
||||
EXPECT_M4_EQ(HMM_MulM4(Matrix, Inverse), HMM_M4D(1.0f));
|
||||
}
|
||||
{
|
||||
HMM_Mat4 Matrix = HMM_Orthographic_RH_ZO(-160+100, 160+100, -90+200, 90+200, 10, 10000);
|
||||
HMM_Mat4 Inverse = HMM_InvOrthographic(Matrix);
|
||||
EXPECT_M4_EQ(HMM_MulM4(Matrix, Inverse), HMM_M4D(1.0f));
|
||||
}
|
||||
{
|
||||
HMM_Mat4 Matrix = HMM_Orthographic_LH_NO(-160+100, 160+100, -90+200, 90+200, 10, 10000);
|
||||
HMM_Mat4 Inverse = HMM_InvOrthographic(Matrix);
|
||||
EXPECT_M4_EQ(HMM_MulM4(Matrix, Inverse), HMM_M4D(1.0f));
|
||||
}
|
||||
{
|
||||
HMM_Mat4 Matrix = HMM_Orthographic_LH_ZO(-160+100, 160+100, -90+200, 90+200, 10, 10000);
|
||||
HMM_Mat4 Inverse = HMM_InvOrthographic(Matrix);
|
||||
EXPECT_M4_EQ(HMM_MulM4(Matrix, Inverse), HMM_M4D(1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(InvMatrix, InvPerspective)
|
||||
{
|
||||
{
|
||||
HMM_Mat4 Matrix = HMM_Perspective_RH_NO(HMM_AngleDeg(120), 16.0/9.0, 10, 10000);
|
||||
HMM_Mat4 Inverse = HMM_InvPerspective_RH(Matrix);
|
||||
EXPECT_M4_EQ(HMM_MulM4(Matrix, Inverse), HMM_M4D(1.0f));
|
||||
}
|
||||
{
|
||||
HMM_Mat4 Matrix = HMM_Perspective_RH_ZO(HMM_AngleDeg(120), 16.0/9.0, 10, 10000);
|
||||
HMM_Mat4 Inverse = HMM_InvPerspective_RH(Matrix);
|
||||
EXPECT_M4_EQ(HMM_MulM4(Matrix, Inverse), HMM_M4D(1.0f));
|
||||
}
|
||||
{
|
||||
HMM_Mat4 Matrix = HMM_Perspective_LH_NO(HMM_AngleDeg(120), 16.0/9.0, 10, 10000);
|
||||
HMM_Mat4 Inverse = HMM_InvPerspective_LH(Matrix);
|
||||
EXPECT_M4_EQ(HMM_MulM4(Matrix, Inverse), HMM_M4D(1.0f));
|
||||
}
|
||||
{
|
||||
HMM_Mat4 Matrix = HMM_Perspective_LH_ZO(HMM_AngleDeg(120), 16.0/9.0, 10, 10000);
|
||||
HMM_Mat4 Inverse = HMM_InvPerspective_LH(Matrix);
|
||||
EXPECT_M4_EQ(HMM_MulM4(Matrix, Inverse), HMM_M4D(1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
TEST(InvMatrix, InvLookAt)
|
||||
{
|
||||
{
|
||||
HMM_Vec3 Eye = {10.0f, 10.0f, 10.0f};
|
||||
HMM_Vec3 Center = {100.0f, 200.0f, 30.0f};
|
||||
HMM_Vec3 Up = {0.0f, 0.0f, 1.0f};
|
||||
HMM_Mat4 Matrix = HMM_LookAt_RH(Eye, Center, Up);
|
||||
HMM_Mat4 Expect = HMM_M4D(1.0f);
|
||||
HMM_Mat4 Inverse = HMM_InvLookAt(Matrix);
|
||||
HMM_Mat4 Result = HMM_MulM4(Matrix, Inverse);
|
||||
EXPECT_M4_NEAR(Result, Expect, 0.001f);
|
||||
}
|
||||
{
|
||||
HMM_Vec3 Eye = {10.0f, 10.0f, 10.0f};
|
||||
HMM_Vec3 Center = {100.0f, 200.0f, 30.0f};
|
||||
HMM_Vec3 Up = {0.0f, 0.0f, 1.0f};
|
||||
HMM_Mat4 Matrix = HMM_LookAt_LH(Eye, Center, Up);
|
||||
HMM_Mat4 Expect = HMM_M4D(1.0f);
|
||||
HMM_Mat4 Inverse = HMM_InvLookAt(Matrix);
|
||||
HMM_Mat4 Result = HMM_MulM4(Matrix, Inverse);
|
||||
EXPECT_M4_NEAR(Result, Expect, 0.001f);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(InvMatrix, InvRotate)
|
||||
{
|
||||
{
|
||||
HMM_Vec3 Axis = {1.0f, -1.0f, 0.5f};
|
||||
HMM_Mat4 Matrix = HMM_Rotate_RH(HMM_AngleDeg(30), HMM_NormV3(Axis));
|
||||
HMM_Mat4 Expect = HMM_M4D(1.0f);
|
||||
HMM_Mat4 Inverse = HMM_InvRotate(Matrix);
|
||||
HMM_Mat4 Result = HMM_MulM4(Matrix, Inverse);
|
||||
EXPECT_M4_NEAR(Result, Expect, 0.001f);
|
||||
}
|
||||
{
|
||||
HMM_Vec3 Axis = {1.0f, -1.0f, 0.5f};
|
||||
HMM_Mat4 Matrix = HMM_Rotate_LH(HMM_AngleDeg(30), HMM_NormV3(Axis));
|
||||
HMM_Mat4 Expect = HMM_M4D(1.0f);
|
||||
HMM_Mat4 Inverse = HMM_InvRotate(Matrix);
|
||||
HMM_Mat4 Result = HMM_MulM4(Matrix, Inverse);
|
||||
EXPECT_M4_NEAR(Result, Expect, 0.001f);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(InvMatrix, InvScale)
|
||||
{
|
||||
HMM_Vec3 Scale = {1.0f, -1.0f, 0.5f};
|
||||
HMM_Mat4 Matrix = HMM_Scale(Scale);
|
||||
HMM_Mat4 Expect = HMM_M4D(1.0f);
|
||||
HMM_Mat4 Inverse = HMM_InvScale(Matrix);
|
||||
HMM_Mat4 Result = HMM_MulM4(Matrix, Inverse);
|
||||
EXPECT_M4_EQ(Result, Expect);
|
||||
}
|
||||
|
||||
TEST(InvMatrix, InvTranslate)
|
||||
{
|
||||
HMM_Vec3 Move = {1.0f, -1.0f, 0.5f};
|
||||
HMM_Mat4 Matrix = HMM_Translate(Move);
|
||||
HMM_Mat4 Expect = HMM_M4D(1.0f);
|
||||
HMM_Mat4 Inverse = HMM_InvTranslate(Matrix);
|
||||
HMM_Mat4 Result = HMM_MulM4(Matrix, Inverse);
|
||||
EXPECT_M4_EQ(Result, Expect);
|
||||
}
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
TEST(Multiplication, Vec2Vec2)
|
||||
{
|
||||
hmm_vec2 v2_1 = HMM_Vec2(1.0f, 2.0f);
|
||||
hmm_vec2 v2_2 = HMM_Vec2(3.0f, 4.0f);
|
||||
HMM_Vec2 v2_1 = HMM_V2(1.0f, 2.0f);
|
||||
HMM_Vec2 v2_2 = HMM_V2(3.0f, 4.0f);
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_MultiplyVec2(v2_1, v2_2);
|
||||
HMM_Vec2 result = HMM_MulV2(v2_1, v2_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_Multiply(v2_1, v2_2);
|
||||
HMM_Vec2 result = HMM_Mul(v2_1, v2_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec2 result = v2_1 * v2_2;
|
||||
HMM_Vec2 result = v2_1 * v2_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 8.0f);
|
||||
}
|
||||
@@ -30,27 +30,27 @@ TEST(Multiplication, Vec2Vec2)
|
||||
|
||||
TEST(Multiplication, Vec2Scalar)
|
||||
{
|
||||
hmm_vec2 v2 = HMM_Vec2(1.0f, 2.0f);
|
||||
HMM_Vec2 v2 = HMM_V2(1.0f, 2.0f);
|
||||
float s = 3.0f;
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_MultiplyVec2f(v2, s);
|
||||
HMM_Vec2 result = HMM_MulV2F(v2, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_Multiply(v2, s);
|
||||
HMM_Vec2 result = HMM_Mul(v2, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec2 result = v2 * s;
|
||||
HMM_Vec2 result = v2 * s;
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec2 result = s * v2;
|
||||
HMM_Vec2 result = s * v2;
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
}
|
||||
@@ -63,24 +63,24 @@ TEST(Multiplication, Vec2Scalar)
|
||||
|
||||
TEST(Multiplication, Vec3Vec3)
|
||||
{
|
||||
hmm_vec3 v3_1 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 v3_2 = HMM_Vec3(4.0f, 5.0f, 6.0f);
|
||||
HMM_Vec3 v3_1 = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 v3_2 = HMM_V3(4.0f, 5.0f, 6.0f);
|
||||
|
||||
{
|
||||
hmm_vec3 result = HMM_MultiplyVec3(v3_1, v3_2);
|
||||
HMM_Vec3 result = HMM_MulV3(v3_1, v3_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 18.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec3 result = HMM_Multiply(v3_1, v3_2);
|
||||
HMM_Vec3 result = HMM_Mul(v3_1, v3_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 18.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = v3_1 * v3_2;
|
||||
HMM_Vec3 result = v3_1 * v3_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 18.0f);
|
||||
@@ -95,30 +95,30 @@ TEST(Multiplication, Vec3Vec3)
|
||||
|
||||
TEST(Multiplication, Vec3Scalar)
|
||||
{
|
||||
hmm_vec3 v3 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 v3 = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
float s = 3.0f;
|
||||
|
||||
{
|
||||
hmm_vec3 result = HMM_MultiplyVec3f(v3, s);
|
||||
HMM_Vec3 result = HMM_MulV3F(v3, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec3 result = HMM_Multiply(v3, s);
|
||||
HMM_Vec3 result = HMM_Mul(v3, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = v3 * s;
|
||||
HMM_Vec3 result = v3 * s;
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = s * v3;
|
||||
HMM_Vec3 result = s * v3;
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
@@ -133,11 +133,11 @@ TEST(Multiplication, Vec3Scalar)
|
||||
|
||||
TEST(Multiplication, Vec4Vec4)
|
||||
{
|
||||
hmm_vec4 v4_1 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_vec4 v4_2 = HMM_Vec4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
HMM_Vec4 v4_1 = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 v4_2 = HMM_V4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
{
|
||||
hmm_vec4 result = HMM_MultiplyVec4(v4_1, v4_2);
|
||||
HMM_Vec4 result = HMM_MulV4(v4_1, v4_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 5.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 12.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 21.0f);
|
||||
@@ -145,14 +145,14 @@ TEST(Multiplication, Vec4Vec4)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec4 result = HMM_Multiply(v4_1, v4_2);
|
||||
HMM_Vec4 result = HMM_Mul(v4_1, v4_2);
|
||||
EXPECT_FLOAT_EQ(result.X, 5.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 12.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 21.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 32.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = v4_1 * v4_2;
|
||||
HMM_Vec4 result = v4_1 * v4_2;
|
||||
EXPECT_FLOAT_EQ(result.X, 5.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 12.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 21.0f);
|
||||
@@ -169,11 +169,11 @@ TEST(Multiplication, Vec4Vec4)
|
||||
|
||||
TEST(Multiplication, Vec4Scalar)
|
||||
{
|
||||
hmm_vec4 v4 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 v4 = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
float s = 3.0f;
|
||||
|
||||
{
|
||||
hmm_vec4 result = HMM_MultiplyVec4f(v4, s);
|
||||
HMM_Vec4 result = HMM_MulV4F(v4, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
@@ -181,21 +181,21 @@ TEST(Multiplication, Vec4Scalar)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec4 result = HMM_Multiply(v4, s);
|
||||
HMM_Vec4 result = HMM_Mul(v4, s);
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 12.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = v4 * s;
|
||||
HMM_Vec4 result = v4 * s;
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 12.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = s * v4;
|
||||
HMM_Vec4 result = s * v4;
|
||||
EXPECT_FLOAT_EQ(result.X, 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 9.0f);
|
||||
@@ -209,10 +209,309 @@ TEST(Multiplication, Vec4Scalar)
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Multiplication, Mat2Mat2) {
|
||||
HMM_Mat2 a = HMM_M2();
|
||||
HMM_Mat2 b = HMM_M2();
|
||||
|
||||
int counter = 1;
|
||||
for (int Column = 0; Column < 2; Column++) {
|
||||
for (int Row = 0; Row < 2; Row++) {
|
||||
a.Elements[Column][Row] = counter++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int Column = 0; Column < 2; Column++) {
|
||||
for (int Row = 0; Row < 2; Row++) {
|
||||
b.Elements[Column][Row] = counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 result = HMM_MulM2(a,b);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 34.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 31.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 46.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat2 result = HMM_Mul(a,b);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 34.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 31.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 46.0f);
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 result = a * b;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 34.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 31.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 46.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Multiplication, Mat2Scalar) {
|
||||
HMM_Mat2 m = HMM_M2();
|
||||
float s = 10.0f;
|
||||
|
||||
int counter = 1;
|
||||
for (int Column = 0; Column < 2; Column++) {
|
||||
for (int Row = 0; Row < 2; Row++) {
|
||||
m.Elements[Column][Row] = counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 result = HMM_MulM2F(m, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 30.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 40.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat2 result = HMM_Mul(m, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 30.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 40.0f);
|
||||
}
|
||||
{
|
||||
HMM_Mat2 result = m * s;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 30.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 40.0f);
|
||||
}
|
||||
{
|
||||
HMM_Mat2 result = s * m;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 30.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 40.0f);
|
||||
}
|
||||
m *= s;
|
||||
EXPECT_FLOAT_EQ(m.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[1][0], 30.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[1][1], 40.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Multiplication, Mat2Vec2) {
|
||||
HMM_Mat2 m = HMM_M2();
|
||||
HMM_Vec2 v = HMM_V2(0.0f, 0.0f);
|
||||
|
||||
int counter = 1;
|
||||
for (int Column = 0; Column < 2; Column++) {
|
||||
for (int Row = 0; Row < 2; Row++) {
|
||||
m.Elements[Column][Row] = counter++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int Row = 0; Row < 2; Row++) {
|
||||
v.Elements[Row] = counter++;
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Vec2 result = HMM_MulM2V2(m, v);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1], 34.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Vec2 result = HMM_Mul(m, v);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1], 34.0f);
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Vec2 result = m * v;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0], 23.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1], 34.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Multiplication, Mat3Mat3)
|
||||
{
|
||||
HMM_Mat3 a = HMM_M3();
|
||||
HMM_Mat3 b = HMM_M3();
|
||||
|
||||
int counter = 1;
|
||||
for (int Column = 0; Column < 3; Column++) {
|
||||
for (int Row = 0; Row < 3; Row++) {
|
||||
a.Elements[Column][Row] = counter++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int Column = 0; Column < 3; Column++) {
|
||||
for (int Row = 0; Row < 3; Row++) {
|
||||
b.Elements[Column][Row] = counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 result = HMM_MulM3(a,b);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 138.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 171.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 204.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 174.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 216.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 258.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 210.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 261.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 312.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat3 result = HMM_Mul(a,b);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 138.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 171.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 204.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 174.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 216.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 258.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 210.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 261.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 312.0f);
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 result = a * b;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 138.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 171.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 204.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 174.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 216.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 258.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 210.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 261.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 312.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Multiplication, Mat3Scalar) {
|
||||
HMM_Mat3 m = HMM_M3();
|
||||
float s = 10.0f;
|
||||
|
||||
int counter = 1;
|
||||
for (int Column = 0; Column < 3; Column++) {
|
||||
for (int Row = 0; Row < 3; Row++) {
|
||||
m.Elements[Column][Row] = counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 result = HMM_MulM3F(m, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 30.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 40.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 50.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 60.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 70.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 80.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 90.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat3 result = HMM_Mul(m, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 30.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 40.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 50.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 60.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 70.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 80.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 90.0f);
|
||||
}
|
||||
{
|
||||
HMM_Mat3 result = m * s;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 30.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 40.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 50.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 60.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 70.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 80.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 90.0f);
|
||||
}
|
||||
{
|
||||
HMM_Mat3 result = s * m;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 30.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 40.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 50.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 60.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 70.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 80.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 90.0f);
|
||||
}
|
||||
m *= s;
|
||||
EXPECT_FLOAT_EQ(m.Elements[0][0], 10.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[0][1], 20.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[0][2], 30.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[1][0], 40.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[1][1], 50.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[1][2], 60.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[2][0], 70.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[2][1], 80.0f);
|
||||
EXPECT_FLOAT_EQ(m.Elements[2][2], 90.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Multiplication, Mat3Vec3) {
|
||||
HMM_Mat3 m = HMM_M3();
|
||||
HMM_Vec3 v = HMM_V3(0.0f, 0.0f, 0.0f);
|
||||
|
||||
int counter = 1;
|
||||
for (int Column = 0; Column < 3; Column++) {
|
||||
for (int Row = 0; Row < 3; Row++) {
|
||||
m.Elements[Column][Row] = counter++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int Row = 0; Row < 3; Row++) {
|
||||
v.Elements[Row] = counter++;
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Vec3 result = HMM_MulM3V3(m, v);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0], 138.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1], 171.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2], 204.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Vec3 result = HMM_Mul(m, v);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0], 138.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1], 171.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2], 204.0f);
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Vec3 result = m * v;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0], 138.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1], 171.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2], 204.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Multiplication, Mat4Mat4)
|
||||
{
|
||||
hmm_mat4 m4_1 = HMM_Mat4(); // will have 1 - 16
|
||||
hmm_mat4 m4_2 = HMM_Mat4(); // will have 17 - 32
|
||||
HMM_Mat4 m4_1 = HMM_M4(); // will have 1 - 16
|
||||
HMM_Mat4 m4_2 = HMM_M4(); // will have 17 - 32
|
||||
|
||||
// Fill the matrices
|
||||
int Counter = 1;
|
||||
@@ -235,7 +534,7 @@ TEST(Multiplication, Mat4Mat4)
|
||||
|
||||
// Test the results
|
||||
{
|
||||
hmm_mat4 result = HMM_MultiplyMat4(m4_1, m4_2);
|
||||
HMM_Mat4 result = HMM_MulM4(m4_1, m4_2);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 538.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 612.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 686.0f);
|
||||
@@ -255,7 +554,7 @@ TEST(Multiplication, Mat4Mat4)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_mat4 result = HMM_Multiply(m4_1, m4_2);
|
||||
HMM_Mat4 result = HMM_Mul(m4_1, m4_2);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 538.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 612.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 686.0f);
|
||||
@@ -274,7 +573,7 @@ TEST(Multiplication, Mat4Mat4)
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][3], 1240.0f);
|
||||
}
|
||||
{
|
||||
hmm_mat4 result = m4_1 * m4_2;
|
||||
HMM_Mat4 result = m4_1 * m4_2;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 538.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 612.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 686.0f);
|
||||
@@ -301,7 +600,7 @@ TEST(Multiplication, Mat4Mat4)
|
||||
|
||||
TEST(Multiplication, Mat4Scalar)
|
||||
{
|
||||
hmm_mat4 m4 = HMM_Mat4(); // will have 1 - 16
|
||||
HMM_Mat4 m4 = HMM_M4(); // will have 1 - 16
|
||||
float s = 3;
|
||||
|
||||
// Fill the matrix
|
||||
@@ -317,7 +616,7 @@ TEST(Multiplication, Mat4Scalar)
|
||||
|
||||
// Test the results
|
||||
{
|
||||
hmm_mat4 result = HMM_MultiplyMat4f(m4, s);
|
||||
HMM_Mat4 result = HMM_MulM4F(m4, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f);
|
||||
@@ -337,7 +636,7 @@ TEST(Multiplication, Mat4Scalar)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_mat4 result = HMM_Multiply(m4, s);
|
||||
HMM_Mat4 result = HMM_Mul(m4, s);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f);
|
||||
@@ -356,7 +655,7 @@ TEST(Multiplication, Mat4Scalar)
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][3], 48.0f);
|
||||
}
|
||||
{
|
||||
hmm_mat4 result = m4 * s;
|
||||
HMM_Mat4 result = m4 * s;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f);
|
||||
@@ -375,7 +674,7 @@ TEST(Multiplication, Mat4Scalar)
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][3], 48.0f);
|
||||
}
|
||||
{
|
||||
hmm_mat4 result = s * m4;
|
||||
HMM_Mat4 result = s * m4;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f);
|
||||
@@ -416,8 +715,8 @@ TEST(Multiplication, Mat4Scalar)
|
||||
|
||||
TEST(Multiplication, Mat4Vec4)
|
||||
{
|
||||
hmm_mat4 m4 = HMM_Mat4(); // will have 1 - 16
|
||||
hmm_vec4 v4 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Mat4 m4 = HMM_M4(); // will have 1 - 16
|
||||
HMM_Vec4 v4 = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
|
||||
// Fill the matrix
|
||||
int Counter = 1;
|
||||
@@ -432,7 +731,7 @@ TEST(Multiplication, Mat4Vec4)
|
||||
|
||||
// Test the results
|
||||
{
|
||||
hmm_vec4 result = HMM_MultiplyMat4ByVec4(m4, v4);
|
||||
HMM_Vec4 result = HMM_MulM4V4(m4, v4);
|
||||
EXPECT_FLOAT_EQ(result.X, 90.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 100.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 110.0f);
|
||||
@@ -440,14 +739,14 @@ TEST(Multiplication, Mat4Vec4)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec4 result = HMM_Multiply(m4, v4);
|
||||
HMM_Vec4 result = HMM_Mul(m4, v4);
|
||||
EXPECT_FLOAT_EQ(result.X, 90.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 100.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 110.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 120.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = m4 * v4;
|
||||
HMM_Vec4 result = m4 * v4;
|
||||
EXPECT_FLOAT_EQ(result.X, 90.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 100.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 110.0f);
|
||||
@@ -460,11 +759,11 @@ TEST(Multiplication, Mat4Vec4)
|
||||
|
||||
TEST(Multiplication, QuaternionQuaternion)
|
||||
{
|
||||
hmm_quaternion q1 = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_quaternion q2 = HMM_Quaternion(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
HMM_Quat q1 = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat q2 = HMM_Q(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
{
|
||||
hmm_quaternion result = HMM_MultiplyQuaternion(q1, q2);
|
||||
HMM_Quat result = HMM_MulQ(q1, q2);
|
||||
EXPECT_FLOAT_EQ(result.X, 24.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 48.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 48.0f);
|
||||
@@ -472,14 +771,14 @@ TEST(Multiplication, QuaternionQuaternion)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_quaternion result = HMM_Multiply(q1, q2);
|
||||
HMM_Quat result = HMM_Mul(q1, q2);
|
||||
EXPECT_FLOAT_EQ(result.X, 24.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 48.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 48.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, -6.0f);
|
||||
}
|
||||
{
|
||||
hmm_quaternion result = q1 * q2;
|
||||
HMM_Quat result = q1 * q2;
|
||||
EXPECT_FLOAT_EQ(result.X, 24.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 48.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 48.0f);
|
||||
@@ -494,11 +793,11 @@ TEST(Multiplication, QuaternionQuaternion)
|
||||
|
||||
TEST(Multiplication, QuaternionScalar)
|
||||
{
|
||||
hmm_quaternion q = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat q = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
float f = 2.0f;
|
||||
|
||||
{
|
||||
hmm_quaternion result = HMM_MultiplyQuaternionF(q, f);
|
||||
HMM_Quat result = HMM_MulQF(q, f);
|
||||
EXPECT_FLOAT_EQ(result.X, 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 6.0f);
|
||||
@@ -506,21 +805,21 @@ TEST(Multiplication, QuaternionScalar)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_quaternion result = HMM_Multiply(q, f);
|
||||
HMM_Quat result = HMM_Mul(q, f);
|
||||
EXPECT_FLOAT_EQ(result.X, 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 8.0f);
|
||||
}
|
||||
{
|
||||
hmm_quaternion result = q * f;
|
||||
HMM_Quat result = q * f;
|
||||
EXPECT_FLOAT_EQ(result.X, 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 6.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 8.0f);
|
||||
}
|
||||
{
|
||||
hmm_quaternion result = f * q;
|
||||
HMM_Quat result = f * q;
|
||||
EXPECT_FLOAT_EQ(result.X, 2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 6.0f);
|
||||
|
||||
@@ -2,35 +2,84 @@
|
||||
|
||||
TEST(Projection, Orthographic)
|
||||
{
|
||||
hmm_mat4 projection = HMM_Orthographic(-10.0f, 10.0f, -5.0f, 5.0f, 0.0f, -10.0f);
|
||||
#define ORTHO_BOUNDS -8.0f, 12.0f, 5.0f, 10.0f, 1.0f, 100.0f
|
||||
|
||||
hmm_vec3 original = HMM_Vec3(5.0f, 5.0f, -5.0f);
|
||||
hmm_vec4 projected = HMM_MultiplyMat4ByVec4(projection, HMM_Vec4v(original, 1));
|
||||
// Right-handed
|
||||
{
|
||||
// Near and far distances correspond to negative Z, hence the Z coordinates here are negative.
|
||||
HMM_Vec4 minCorner = HMM_V4(-8.0f, 5.0f, -1.0f, 1.0);
|
||||
HMM_Vec4 maxCorner = HMM_V4(12.0f, 10.0f, -100.0f, 1.0);
|
||||
|
||||
EXPECT_FLOAT_EQ(projected.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(projected.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(projected.Z, -2.0f);
|
||||
EXPECT_FLOAT_EQ(projected.W, 1.0f);
|
||||
// Z from -1 to 1 (GL convention)
|
||||
{
|
||||
HMM_Mat4 projection = HMM_Orthographic_RH_NO(ORTHO_BOUNDS);
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, minCorner), HMM_V4(-1.0f, -1.0f, -1.0f, 1.0f));
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, maxCorner), HMM_V4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
// Z from 0 to 1 (DX convention)
|
||||
{
|
||||
HMM_Mat4 projection = HMM_Orthographic_RH_ZO(ORTHO_BOUNDS);
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, minCorner), HMM_V4(-1.0f, -1.0f, 0.0f, 1.0f));
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, maxCorner), HMM_V4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
// Left-handed
|
||||
{
|
||||
// Near and far distances correspond to positive Z, hence the Z coordinates here are positive.
|
||||
HMM_Vec4 minCorner = HMM_V4(-8.0f, 5.0f, 1.0f, 1.0);
|
||||
HMM_Vec4 maxCorner = HMM_V4(12.0f, 10.0f, 100.0f, 1.0);
|
||||
|
||||
// Z from -1 to 1 (GL convention)
|
||||
{
|
||||
HMM_Mat4 projection = HMM_Orthographic_LH_NO(ORTHO_BOUNDS);
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, minCorner), HMM_V4(-1.0f, -1.0f, -1.0f, 1.0f));
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, maxCorner), HMM_V4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
|
||||
// Z from 0 to 1 (DX convention)
|
||||
{
|
||||
HMM_Mat4 projection = HMM_Orthographic_LH_ZO(ORTHO_BOUNDS);
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, minCorner), HMM_V4(-1.0f, -1.0f, 0.0f, 1.0f));
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, maxCorner), HMM_V4(1.0f, 1.0f, 1.0f, 1.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(Projection, Perspective)
|
||||
{
|
||||
hmm_mat4 projection = HMM_Perspective(90.0f, 2.0f, 5.0f, 15.0f);
|
||||
// Right-handed
|
||||
{
|
||||
// Z from -1 to 1 (GL convention)
|
||||
{
|
||||
HMM_Mat4 projection = HMM_Perspective_RH_NO(HMM_AngleDeg(90.0f), 2.0f, 1.0f, 15.0f);
|
||||
HMM_Vec4 original = HMM_V4(5.0f, 5.0f, -1.0f, 1.0f);
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, original), HMM_V4(2.5f, 5.0f, -1.0f, 1.0f));
|
||||
}
|
||||
|
||||
{
|
||||
hmm_vec3 original = HMM_Vec3(5.0f, 5.0f, -15.0f);
|
||||
hmm_vec4 projected = HMM_MultiplyMat4ByVec4(projection, HMM_Vec4v(original, 1));
|
||||
EXPECT_FLOAT_EQ(projected.X, 5.0f);
|
||||
EXPECT_FLOAT_EQ(projected.Y, 10.0f);
|
||||
EXPECT_FLOAT_EQ(projected.Z, 15.0f);
|
||||
EXPECT_FLOAT_EQ(projected.W, 15.0f);
|
||||
// Z from 0 to 1 (DX convention)
|
||||
{
|
||||
HMM_Mat4 projection = HMM_Perspective_RH_ZO(HMM_AngleDeg(90.0f), 2.0f, 1.0f, 15.0f);
|
||||
HMM_Vec4 original = HMM_V4(5.0f, 5.0f, -1.0f, 1.0f);
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, original), HMM_V4(2.5f, 5.0f, 0.0f, 1.0f));
|
||||
}
|
||||
}
|
||||
|
||||
// Left-handed
|
||||
{
|
||||
hmm_vec3 original = HMM_Vec3(5.0f, 5.0f, -5.0f);
|
||||
hmm_vec4 projected = HMM_MultiplyMat4ByVec4(projection, HMM_Vec4v(original, 1));
|
||||
EXPECT_FLOAT_EQ(projected.X, 5.0f);
|
||||
EXPECT_FLOAT_EQ(projected.Y, 10.0f);
|
||||
EXPECT_FLOAT_EQ(projected.Z, -5.0f);
|
||||
EXPECT_FLOAT_EQ(projected.W, 5.0f);
|
||||
// Z from -1 to 1 (GL convention)
|
||||
{
|
||||
HMM_Mat4 projection = HMM_Perspective_LH_NO(HMM_AngleDeg(90.0f), 2.0f, 1.0f, 15.0f);
|
||||
HMM_Vec4 original = HMM_V4(5.0f, 5.0f, 1.0f, 1.0f);
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, original), HMM_V4(2.5f, 5.0f, -1.0f, 1.0f));
|
||||
}
|
||||
|
||||
// Z from 0 to 1 (DX convention)
|
||||
{
|
||||
HMM_Mat4 projection = HMM_Perspective_LH_ZO(HMM_AngleDeg(90.0f), 2.0f, 1.0f, 15.0f);
|
||||
HMM_Vec4 original = HMM_V4(5.0f, 5.0f, 1.0f, 1.0f);
|
||||
EXPECT_V4_EQ(HMM_MulM4V4(projection, original), HMM_V4(2.5f, 5.0f, 0.0f, 1.0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
TEST(QuaternionOps, Inverse)
|
||||
{
|
||||
hmm_quaternion q1 = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_quaternion inverse = HMM_InverseQuaternion(q1);
|
||||
HMM_Quat q1 = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat inverse = HMM_InvQ(q1);
|
||||
|
||||
hmm_quaternion result = HMM_MultiplyQuaternion(q1, inverse);
|
||||
HMM_Quat result = HMM_MulQ(q1, inverse);
|
||||
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
@@ -15,11 +15,11 @@ TEST(QuaternionOps, Inverse)
|
||||
|
||||
TEST(QuaternionOps, Dot)
|
||||
{
|
||||
hmm_quaternion q1 = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_quaternion q2 = HMM_Quaternion(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
HMM_Quat q1 = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat q2 = HMM_Q(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
{
|
||||
float result = HMM_DotQuaternion(q1, q2);
|
||||
float result = HMM_DotQ(q1, q2);
|
||||
EXPECT_FLOAT_EQ(result, 70.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
@@ -32,57 +32,87 @@ TEST(QuaternionOps, Dot)
|
||||
|
||||
TEST(QuaternionOps, Normalize)
|
||||
{
|
||||
hmm_quaternion q = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat q = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
|
||||
{
|
||||
hmm_quaternion result = HMM_NormalizeQuaternion(q);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.1825741858f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.3651483717f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.5477225575f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.7302967433f);
|
||||
HMM_Quat result = HMM_NormQ(q);
|
||||
EXPECT_NEAR(result.X, 0.1825741858f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.3651483717f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, 0.5477225575f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.7302967433f, 0.001f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_quaternion result = HMM_Normalize(q);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.1825741858f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.3651483717f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.5477225575f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.7302967433f);
|
||||
HMM_Quat result = HMM_Norm(q);
|
||||
EXPECT_NEAR(result.X, 0.1825741858f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.3651483717f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, 0.5477225575f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.7302967433f, 0.001f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(QuaternionOps, NLerp)
|
||||
{
|
||||
hmm_quaternion from = HMM_Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
hmm_quaternion to = HMM_Quaternion(0.5f, 0.5f, -0.5f, 0.5f);
|
||||
HMM_Quat from = HMM_Q(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
HMM_Quat to = HMM_Q(0.5f, 0.5f, -0.5f, 0.5f);
|
||||
|
||||
hmm_quaternion result = HMM_NLerp(from, 0.5f, to);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.86602540f);
|
||||
HMM_Quat result = HMM_NLerp(from, 0.5f, to);
|
||||
EXPECT_NEAR(result.X, 0.28867513f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.28867513f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, -0.28867513f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.86602540f, 0.001f);
|
||||
}
|
||||
|
||||
TEST(QuaternionOps, Slerp)
|
||||
TEST(QuaternionOps, SLerp)
|
||||
{
|
||||
hmm_quaternion from = HMM_Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
hmm_quaternion to = HMM_Quaternion(0.5f, 0.5f, -0.5f, 0.5f);
|
||||
HMM_Quat from = HMM_Q(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
HMM_Quat to = HMM_Q(0.5f, 0.5f, -0.5f, 0.5f);
|
||||
|
||||
hmm_quaternion result = HMM_Slerp(from, 0.5f, to);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -0.28867513f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.86602540f);
|
||||
{
|
||||
HMM_Quat result = HMM_SLerp(from, 0.0f, to);
|
||||
EXPECT_NEAR(result.X, 0.0f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.0f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, 0.0f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 1.0, 0.001f);
|
||||
}
|
||||
{
|
||||
HMM_Quat result = HMM_SLerp(from, 0.25f, to);
|
||||
EXPECT_NEAR(result.X, 0.149429246f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.149429246f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, -0.149429246f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.965925812f, 0.001f);
|
||||
}
|
||||
{
|
||||
HMM_Quat result = HMM_SLerp(from, 0.5f, to);
|
||||
EXPECT_NEAR(result.X, 0.28867513f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.28867513f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, -0.28867513f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.86602540f, 0.001f);
|
||||
}
|
||||
{
|
||||
HMM_Quat result = HMM_SLerp(from, 0.75f, to);
|
||||
EXPECT_NEAR(result.X, 0.40824830f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.40824830f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, -0.40824830f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.70710676f, 0.001f);
|
||||
}
|
||||
{
|
||||
HMM_Quat result = HMM_SLerp(from, 1.0f, to);
|
||||
EXPECT_NEAR(result.X, 0.5f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.5f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, -0.5f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.5f, 0.001f);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(QuaternionOps, ToMat4)
|
||||
TEST(QuaternionOps, QuatToMat4)
|
||||
{
|
||||
const float abs_error = 0.0001f;
|
||||
const float abs_error = 0.001f;
|
||||
|
||||
hmm_quaternion rot = HMM_Quaternion(0.707107f, 0.0f, 0.0f, 0.707107f);
|
||||
HMM_Quat rot = HMM_Q(0.707107f, 0.0f, 0.0f, 0.707107f);
|
||||
|
||||
hmm_mat4 result = HMM_QuaternionToMat4(rot);
|
||||
HMM_Mat4 result = HMM_QToM4(rot);
|
||||
|
||||
EXPECT_NEAR(result.Elements[0][0], 1.0f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][1], 0.0f, abs_error);
|
||||
@@ -105,14 +135,142 @@ TEST(QuaternionOps, ToMat4)
|
||||
EXPECT_NEAR(result.Elements[3][3], 1.0f, abs_error);
|
||||
}
|
||||
|
||||
TEST(QuaternionOps, Mat4ToQuat)
|
||||
{
|
||||
const float abs_error = 0.0001f;
|
||||
|
||||
// Rotate 90 degrees on the X axis
|
||||
{
|
||||
HMM_Mat4 m = HMM_Rotate_RH(HMM_AngleDeg(90.0f), HMM_V3(1, 0, 0));
|
||||
HMM_Quat result = HMM_M4ToQ_RH(m);
|
||||
|
||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||
float sinf = 0.707107f; // sin(90/2 degrees)
|
||||
|
||||
EXPECT_NEAR(result.X, sinf, abs_error);
|
||||
EXPECT_NEAR(result.Y, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Z, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.W, cosf, abs_error);
|
||||
}
|
||||
|
||||
// Rotate 90 degrees on the Y axis (axis not normalized, just for fun)
|
||||
{
|
||||
HMM_Mat4 m = HMM_Rotate_RH(HMM_AngleDeg(90.0f), HMM_V3(0, 2, 0));
|
||||
HMM_Quat result = HMM_M4ToQ_RH(m);
|
||||
|
||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||
float sinf = 0.707107f; // sin(90/2 degrees)
|
||||
|
||||
EXPECT_NEAR(result.X, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Y, sinf, abs_error);
|
||||
EXPECT_NEAR(result.Z, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.W, cosf, abs_error);
|
||||
}
|
||||
|
||||
// Rotate 90 degrees on the Z axis
|
||||
{
|
||||
HMM_Mat4 m = HMM_Rotate_RH(HMM_AngleDeg(90.0f), HMM_V3(0, 0, 1));
|
||||
HMM_Quat result = HMM_M4ToQ_RH(m);
|
||||
|
||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||
float sinf = 0.707107f; // sin(90/2 degrees)
|
||||
|
||||
EXPECT_NEAR(result.X, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Y, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Z, sinf, abs_error);
|
||||
EXPECT_NEAR(result.W, cosf, abs_error);
|
||||
}
|
||||
|
||||
// Rotate 45 degrees on the X axis (this hits case 4)
|
||||
{
|
||||
HMM_Mat4 m = HMM_Rotate_RH(HMM_AngleDeg(45.0f), HMM_V3(1, 0, 0));
|
||||
HMM_Quat result = HMM_M4ToQ_RH(m);
|
||||
|
||||
float cosf = 0.9238795325f; // cos(90/2 degrees)
|
||||
float sinf = 0.3826834324f; // sin(90/2 degrees)
|
||||
|
||||
EXPECT_NEAR(result.X, sinf, abs_error);
|
||||
EXPECT_NEAR(result.Y, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Z, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.W, cosf, abs_error);
|
||||
}
|
||||
|
||||
/* NOTE(lcf): Left-handed cases. Since both Rotate and M4ToQ are LH results should be
|
||||
the same with no changes to input. */
|
||||
// Rotate 90 degrees on the X axis
|
||||
{
|
||||
HMM_Mat4 m = HMM_Rotate_LH(HMM_AngleDeg(90.0f), HMM_V3(1, 0, 0));
|
||||
HMM_Quat result = HMM_M4ToQ_LH(m);
|
||||
|
||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||
float sinf = 0.707107f; // sin(90/2 degrees)
|
||||
|
||||
EXPECT_NEAR(result.X, sinf, abs_error);
|
||||
EXPECT_NEAR(result.Y, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Z, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.W, cosf, abs_error);
|
||||
}
|
||||
|
||||
// Rotate 90 degrees on the Y axis (axis not normalized, just for fun)
|
||||
{
|
||||
HMM_Mat4 m = HMM_Rotate_LH(HMM_AngleDeg(90.0f), HMM_V3(0, 2, 0));
|
||||
HMM_Quat result = HMM_M4ToQ_LH(m);
|
||||
|
||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||
float sinf = 0.707107f; // sin(90/2 degrees)
|
||||
|
||||
EXPECT_NEAR(result.X, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Y, sinf, abs_error);
|
||||
EXPECT_NEAR(result.Z, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.W, cosf, abs_error);
|
||||
}
|
||||
|
||||
// Rotate 90 degrees on the Z axis
|
||||
{
|
||||
HMM_Mat4 m = HMM_Rotate_LH(HMM_AngleDeg(90.0f), HMM_V3(0, 0, 1));
|
||||
HMM_Quat result = HMM_M4ToQ_LH(m);
|
||||
|
||||
float cosf = 0.707107f; // cos(90/2 degrees)
|
||||
float sinf = 0.707107f; // sin(90/2 degrees)
|
||||
|
||||
EXPECT_NEAR(result.X, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Y, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Z, sinf, abs_error);
|
||||
EXPECT_NEAR(result.W, cosf, abs_error);
|
||||
}
|
||||
|
||||
// Rotate 45 degrees on the X axis (this hits case 4)
|
||||
{
|
||||
HMM_Mat4 m = HMM_Rotate_LH(HMM_AngleDeg(45.0f), HMM_V3(1, 0, 0));
|
||||
HMM_Quat result = HMM_M4ToQ_LH(m);
|
||||
|
||||
float cosf = 0.9238795325f; // cos(90/2 degrees)
|
||||
float sinf = 0.3826834324f; // sin(90/2 degrees)
|
||||
|
||||
EXPECT_NEAR(result.X, sinf, abs_error);
|
||||
EXPECT_NEAR(result.Y, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Z, 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.W, cosf, abs_error);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(QuaternionOps, FromAxisAngle)
|
||||
{
|
||||
hmm_vec3 axis = HMM_Vec3(1.0f, 0.0f, 0.0f);
|
||||
HMM_Vec3 axis = HMM_V3(1.0f, 0.0f, 0.0f);
|
||||
float angle = HMM_PI32 / 2.0f;
|
||||
|
||||
hmm_quaternion result = HMM_QuaternionFromAxisAngle(axis, angle);
|
||||
EXPECT_NEAR(result.X, 0.707107f, FLT_EPSILON * 2);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
EXPECT_NEAR(result.W, 0.707107f, FLT_EPSILON * 2);
|
||||
}
|
||||
{
|
||||
HMM_Quat result = HMM_QFromAxisAngle_RH(axis, angle);
|
||||
EXPECT_NEAR(result.X, 0.707107f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.0f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, 0.0f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.707107f, 0.001f);
|
||||
}
|
||||
{
|
||||
HMM_Quat result = HMM_QFromAxisAngle_LH(axis, angle);
|
||||
EXPECT_NEAR(result.X, -0.707107f, 0.001f);
|
||||
EXPECT_NEAR(result.Y, 0.0f, 0.001f);
|
||||
EXPECT_NEAR(result.Z, 0.0f, 0.001f);
|
||||
EXPECT_NEAR(result.W, 0.707107f, 0.001f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,36 +4,36 @@
|
||||
|
||||
TEST(SSE, LinearCombine)
|
||||
{
|
||||
hmm_mat4 MatrixOne = HMM_Mat4d(2.0f);
|
||||
hmm_mat4 MatrixTwo = HMM_Mat4d(4.0f);
|
||||
hmm_mat4 Result;
|
||||
|
||||
Result.Columns[0] = HMM_LinearCombineSSE(MatrixOne.Columns[0], MatrixTwo);
|
||||
Result.Columns[1] = HMM_LinearCombineSSE(MatrixOne.Columns[1], MatrixTwo);
|
||||
Result.Columns[2] = HMM_LinearCombineSSE(MatrixOne.Columns[2], MatrixTwo);
|
||||
Result.Columns[3] = HMM_LinearCombineSSE(MatrixOne.Columns[3], MatrixTwo);
|
||||
|
||||
HMM_Mat4 MatrixOne = HMM_M4D(2.0f);
|
||||
HMM_Mat4 MatrixTwo = HMM_M4D(4.0f);
|
||||
HMM_Mat4 Result;
|
||||
|
||||
Result.Columns[0] = HMM_LinearCombineV4M4(MatrixOne.Columns[0], MatrixTwo);
|
||||
Result.Columns[1] = HMM_LinearCombineV4M4(MatrixOne.Columns[1], MatrixTwo);
|
||||
Result.Columns[2] = HMM_LinearCombineV4M4(MatrixOne.Columns[2], MatrixTwo);
|
||||
Result.Columns[3] = HMM_LinearCombineV4M4(MatrixOne.Columns[3], MatrixTwo);
|
||||
|
||||
{
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][0], 8.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][1], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][2], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[0][3], 0.0f);
|
||||
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][0], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][1], 8.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][1], 8.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][2], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[1][3], 0.0f);
|
||||
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][0], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][1], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][1], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][2], 8.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[2][3], 0.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][0], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][1], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][1], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][2], 0.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][3], 8.0f);
|
||||
}
|
||||
EXPECT_FLOAT_EQ(Result.Elements[3][3], 8.0f);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -28,47 +28,26 @@ TEST(ScalarMath, Trigonometry)
|
||||
// checking that things work by default.
|
||||
}
|
||||
|
||||
TEST(ScalarMath, ToRadians)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_ToRadians(0.0f), 0.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_ToRadians(180.0f), HMM_PI32);
|
||||
EXPECT_FLOAT_EQ(HMM_ToRadians(-180.0f), -HMM_PI32);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, SquareRoot)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_SquareRootF(16.0f), 4.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_SqrtF(16.0f), 4.0f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, RSquareRootF)
|
||||
{
|
||||
EXPECT_NEAR(HMM_RSquareRootF(10.0f), 0.31616211f, 0.0001f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, Power)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_Power(2.0f, 0), 1.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Power(2.0f, 4), 16.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Power(2.0f, -2), 0.25f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, PowerF)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_PowerF(2.0f, 0), 1.0f);
|
||||
EXPECT_NEAR(HMM_PowerF(2.0f, 4.1), 17.148376f, 0.0001f);
|
||||
EXPECT_NEAR(HMM_PowerF(2.0f, -2.5), 0.176777f, 0.0001f);
|
||||
EXPECT_NEAR(HMM_InvSqrtF(10.0f), 0.31616211f, 0.0001f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, Lerp)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.0f, 2.0f), -2.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.5f, 2.0f), 0.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.0f, 2.0f), -2.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 0.5f, 2.0f), 0.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Lerp(-2.0f, 1.0f, 2.0f), 2.0f);
|
||||
}
|
||||
|
||||
TEST(ScalarMath, Clamp)
|
||||
{
|
||||
EXPECT_FLOAT_EQ(HMM_Clamp(-2.0f, 0.0f, 2.0f), 0.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Clamp(-2.0f, -3.0f, 2.0f), -2.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Clamp(-2.0f, 0.0f, 2.0f), 0.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Clamp(-2.0f, -3.0f, 2.0f), -2.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Clamp(-2.0f, 3.0f, 2.0f), 2.0f);
|
||||
}
|
||||
|
||||
@@ -2,22 +2,22 @@
|
||||
|
||||
TEST(Subtraction, Vec2)
|
||||
{
|
||||
hmm_vec2 v2_1 = HMM_Vec2(1.0f, 2.0f);
|
||||
hmm_vec2 v2_2 = HMM_Vec2(3.0f, 4.0f);
|
||||
HMM_Vec2 v2_1 = HMM_V2(1.0f, 2.0f);
|
||||
HMM_Vec2 v2_2 = HMM_V2(3.0f, 4.0f);
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_SubtractVec2(v2_1, v2_2);
|
||||
HMM_Vec2 result = HMM_SubV2(v2_1, v2_2);
|
||||
EXPECT_FLOAT_EQ(result.X, -2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -2.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_Subtract(v2_1, v2_2);
|
||||
HMM_Vec2 result = HMM_Sub(v2_1, v2_2);
|
||||
EXPECT_FLOAT_EQ(result.X, -2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -2.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec2 result = v2_1 - v2_2;
|
||||
HMM_Vec2 result = v2_1 - v2_2;
|
||||
EXPECT_FLOAT_EQ(result.X, -2.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -2.0f);
|
||||
}
|
||||
@@ -30,24 +30,24 @@ TEST(Subtraction, Vec2)
|
||||
|
||||
TEST(Subtraction, Vec3)
|
||||
{
|
||||
hmm_vec3 v3_1 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 v3_2 = HMM_Vec3(4.0f, 5.0f, 6.0f);
|
||||
HMM_Vec3 v3_1 = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 v3_2 = HMM_V3(4.0f, 5.0f, 6.0f);
|
||||
|
||||
{
|
||||
hmm_vec3 result = HMM_SubtractVec3(v3_1, v3_2);
|
||||
HMM_Vec3 result = HMM_SubV3(v3_1, v3_2);
|
||||
EXPECT_FLOAT_EQ(result.X, -3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -3.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec3 result = HMM_Subtract(v3_1, v3_2);
|
||||
HMM_Vec3 result = HMM_Sub(v3_1, v3_2);
|
||||
EXPECT_FLOAT_EQ(result.X, -3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -3.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = v3_1 - v3_2;
|
||||
HMM_Vec3 result = v3_1 - v3_2;
|
||||
EXPECT_FLOAT_EQ(result.X, -3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -3.0f);
|
||||
@@ -62,11 +62,11 @@ TEST(Subtraction, Vec3)
|
||||
|
||||
TEST(Subtraction, Vec4)
|
||||
{
|
||||
hmm_vec4 v4_1 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_vec4 v4_2 = HMM_Vec4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
HMM_Vec4 v4_1 = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 v4_2 = HMM_V4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
{
|
||||
hmm_vec4 result = HMM_SubtractVec4(v4_1, v4_2);
|
||||
HMM_Vec4 result = HMM_SubV4(v4_1, v4_2);
|
||||
EXPECT_FLOAT_EQ(result.X, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -4.0f);
|
||||
@@ -74,14 +74,14 @@ TEST(Subtraction, Vec4)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec4 result = HMM_Subtract(v4_1, v4_2);
|
||||
HMM_Vec4 result = HMM_Sub(v4_1, v4_2);
|
||||
EXPECT_FLOAT_EQ(result.X, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, -4.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = v4_1 - v4_2;
|
||||
HMM_Vec4 result = v4_1 - v4_2;
|
||||
EXPECT_FLOAT_EQ(result.X, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -4.0f);
|
||||
@@ -96,10 +96,124 @@ TEST(Subtraction, Vec4)
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Subtraction, Mat2)
|
||||
{
|
||||
HMM_Mat2 a = HMM_M2();
|
||||
HMM_Mat2 b = HMM_M2();
|
||||
|
||||
int Counter = 1;
|
||||
for (int Column = 0; Column < 2; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 2; ++Row)
|
||||
{
|
||||
a.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
for (int Column = 0; Column < 2; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 2; ++Row)
|
||||
{
|
||||
b.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 result = HMM_SubM2(b,a);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 4.0);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat2 result = HMM_Sub(b,a);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 4.0);
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat2 result = b - a;
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 4.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 4.0);
|
||||
}
|
||||
|
||||
b -= a;
|
||||
EXPECT_FLOAT_EQ(b.Elements[0][0], 4.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[0][1], 4.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[1][0], 4.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[1][1], 4.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
TEST(Subtraction, Mat3)
|
||||
{
|
||||
HMM_Mat3 a = HMM_M3();
|
||||
HMM_Mat3 b = HMM_M3();
|
||||
|
||||
int Counter = 1;
|
||||
for (int Column = 0; Column < 3; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 3; ++Row)
|
||||
{
|
||||
a.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
for (int Column = 0; Column < 3; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 3; ++Row)
|
||||
{
|
||||
b.Elements[Column][Row] = Counter++;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
HMM_Mat3 result = HMM_SubM3(b,a);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 9.0);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Mat3 result = HMM_Sub(b,a);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][2], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][2], 9.0);
|
||||
}
|
||||
|
||||
b -= a;
|
||||
EXPECT_FLOAT_EQ(b.Elements[0][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[0][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[0][2], 9.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[1][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[1][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[1][2], 9.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[2][0], 9.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[2][1], 9.0);
|
||||
EXPECT_FLOAT_EQ(b.Elements[2][2], 9.0);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Subtraction, Mat4)
|
||||
{
|
||||
hmm_mat4 m4_1 = HMM_Mat4(); // will have 1 - 16
|
||||
hmm_mat4 m4_2 = HMM_Mat4(); // will have 17 - 32
|
||||
HMM_Mat4 m4_1 = HMM_M4(); // will have 1 - 16
|
||||
HMM_Mat4 m4_2 = HMM_M4(); // will have 17 - 32
|
||||
|
||||
// Fill the matrices
|
||||
int Counter = 1;
|
||||
@@ -122,7 +236,7 @@ TEST(Subtraction, Mat4)
|
||||
|
||||
// Test the results
|
||||
{
|
||||
hmm_mat4 result = HMM_SubtractMat4(m4_1, m4_2);
|
||||
HMM_Mat4 result = HMM_SubM4(m4_1, m4_2);
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 4; ++Row)
|
||||
@@ -133,7 +247,7 @@ TEST(Subtraction, Mat4)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_mat4 result = HMM_Subtract(m4_1, m4_2);
|
||||
HMM_Mat4 result = HMM_Sub(m4_1, m4_2);
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 4; ++Row)
|
||||
@@ -143,7 +257,7 @@ TEST(Subtraction, Mat4)
|
||||
}
|
||||
}
|
||||
{
|
||||
hmm_mat4 result = m4_1 - m4_2;
|
||||
HMM_Mat4 result = m4_1 - m4_2;
|
||||
for (int Column = 0; Column < 4; ++Column)
|
||||
{
|
||||
for (int Row = 0; Row < 4; ++Row)
|
||||
@@ -166,11 +280,11 @@ TEST(Subtraction, Mat4)
|
||||
|
||||
TEST(Subtraction, Quaternion)
|
||||
{
|
||||
hmm_quaternion q1 = HMM_Quaternion(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_quaternion q2 = HMM_Quaternion(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
HMM_Quat q1 = HMM_Q(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Quat q2 = HMM_Q(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
{
|
||||
hmm_quaternion result = HMM_SubtractQuaternion(q1, q2);
|
||||
HMM_Quat result = HMM_SubQ(q1, q2);
|
||||
EXPECT_FLOAT_EQ(result.X, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -4.0f);
|
||||
@@ -178,14 +292,14 @@ TEST(Subtraction, Quaternion)
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_quaternion result = HMM_Subtract(q1, q2);
|
||||
HMM_Quat result = HMM_Sub(q1, q2);
|
||||
EXPECT_FLOAT_EQ(result.X, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, -4.0f);
|
||||
}
|
||||
{
|
||||
hmm_quaternion result = q1 - q2;
|
||||
HMM_Quat result = q1 - q2;
|
||||
EXPECT_FLOAT_EQ(result.X, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, -4.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, -4.0f);
|
||||
@@ -199,3 +313,32 @@ TEST(Subtraction, Quaternion)
|
||||
EXPECT_FLOAT_EQ(q1.W, -4.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
TEST(UnaryMinus, Vec2)
|
||||
{
|
||||
HMM_Vec2 VectorOne = {1.0f, 2.0f};
|
||||
HMM_Vec2 Result = -VectorOne;
|
||||
EXPECT_FLOAT_EQ(Result.X, -1.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
|
||||
}
|
||||
|
||||
TEST(UnaryMinus, Vec3)
|
||||
{
|
||||
HMM_Vec3 VectorOne = {1.0f, 2.0f, 3.0f};
|
||||
HMM_Vec3 Result = -VectorOne;
|
||||
EXPECT_FLOAT_EQ(Result.X, -1.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Z, -3.0f);
|
||||
}
|
||||
|
||||
TEST(UnaryMinus, Vec4)
|
||||
{
|
||||
HMM_Vec4 VectorOne = {1.0f, 2.0f, 3.0f, 4.0f};
|
||||
HMM_Vec4 Result = -VectorOne;
|
||||
EXPECT_FLOAT_EQ(Result.X, -1.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Y, -2.0f);
|
||||
EXPECT_FLOAT_EQ(Result.Z, -3.0f);
|
||||
EXPECT_FLOAT_EQ(Result.W, -4.0f);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -2,76 +2,104 @@
|
||||
|
||||
TEST(Transformations, Translate)
|
||||
{
|
||||
hmm_mat4 translate = HMM_Translate(HMM_Vec3(1.0f, -3.0f, 6.0f));
|
||||
HMM_Mat4 translate = HMM_Translate(HMM_V3(1.0f, -3.0f, 6.0f));
|
||||
|
||||
hmm_vec3 original = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec4 translated = HMM_MultiplyMat4ByVec4(translate, HMM_Vec4v(original, 1));
|
||||
HMM_Vec3 original = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec4 translated = HMM_MulM4V4(translate, HMM_V4V(original, 1));
|
||||
|
||||
EXPECT_FLOAT_EQ(translated.X, 2.0f);
|
||||
EXPECT_FLOAT_EQ(translated.Y, -1.0f);
|
||||
EXPECT_FLOAT_EQ(translated.Z, 9.0f);
|
||||
EXPECT_FLOAT_EQ(translated.W, 1.0f);
|
||||
EXPECT_NEAR(translated.X, 2.0f, 0.001f);
|
||||
EXPECT_NEAR(translated.Y, -1.0f, 0.001f);
|
||||
EXPECT_NEAR(translated.Z, 9.0f, 0.001f);
|
||||
EXPECT_NEAR(translated.W, 1.0f, 0.001f);
|
||||
}
|
||||
|
||||
TEST(Transformations, Rotate)
|
||||
{
|
||||
hmm_vec3 original = HMM_Vec3(1.0f, 1.0f, 1.0f);
|
||||
HMM_Vec3 original = HMM_V3(1.0f, 1.0f, 1.0f);
|
||||
|
||||
hmm_mat4 rotateX = HMM_Rotate(90, HMM_Vec3(1, 0, 0));
|
||||
hmm_vec4 rotatedX = HMM_MultiplyMat4ByVec4(rotateX, HMM_Vec4v(original, 1));
|
||||
EXPECT_FLOAT_EQ(rotatedX.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedX.Y, -1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedX.Z, 1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedX.W, 1.0f);
|
||||
HMM_Mat4 rotateX = HMM_Rotate_RH(HMM_AngleDeg(90.0f), HMM_V3(1, 0, 0));
|
||||
HMM_Vec4 rotatedX = HMM_MulM4V4(rotateX, HMM_V4V(original, 1));
|
||||
EXPECT_NEAR(rotatedX.X, 1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedX.Y, -1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedX.Z, 1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedX.W, 1.0f, 0.001f);
|
||||
|
||||
hmm_mat4 rotateY = HMM_Rotate(90, HMM_Vec3(0, 1, 0));
|
||||
hmm_vec4 rotatedY = HMM_MultiplyMat4ByVec4(rotateY, HMM_Vec4v(original, 1));
|
||||
EXPECT_FLOAT_EQ(rotatedY.X, 1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedY.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedY.Z, -1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedY.W, 1.0f);
|
||||
HMM_Mat4 rotateY = HMM_Rotate_RH(HMM_AngleDeg(90.0f), HMM_V3(0, 1, 0));
|
||||
HMM_Vec4 rotatedY = HMM_MulM4V4(rotateY, HMM_V4V(original, 1));
|
||||
EXPECT_NEAR(rotatedY.X, 1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedY.Y, 1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedY.Z, -1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedY.W, 1.0f, 0.001f);
|
||||
|
||||
hmm_mat4 rotateZ = HMM_Rotate(90, HMM_Vec3(0, 0, 1));
|
||||
hmm_vec4 rotatedZ = HMM_MultiplyMat4ByVec4(rotateZ, HMM_Vec4v(original, 1));
|
||||
EXPECT_FLOAT_EQ(rotatedZ.X, -1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedZ.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedZ.Z, 1.0f);
|
||||
EXPECT_FLOAT_EQ(rotatedZ.W, 1.0f);
|
||||
HMM_Mat4 rotateZ = HMM_Rotate_RH(HMM_AngleDeg(90.0f), HMM_V3(0, 0, 1));
|
||||
HMM_Vec4 rotatedZ = HMM_MulM4V4(rotateZ, HMM_V4V(original, 1));
|
||||
EXPECT_NEAR(rotatedZ.X, -1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedZ.Y, 1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedZ.Z, 1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedZ.W, 1.0f, 0.001f);
|
||||
|
||||
HMM_Mat4 rotateZLH = HMM_Rotate_LH(HMM_AngleDeg(90.0f), HMM_V3(0, 0, 1));
|
||||
HMM_Vec4 rotatedZLH = HMM_MulM4V4(rotateZLH, HMM_V4V(original, 1));
|
||||
EXPECT_NEAR(rotatedZLH.X, 1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedZLH.Y, -1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedZLH.Z, 1.0f, 0.001f);
|
||||
EXPECT_NEAR(rotatedZLH.W, 1.0f, 0.001f);
|
||||
}
|
||||
|
||||
TEST(Transformations, Scale)
|
||||
{
|
||||
hmm_mat4 scale = HMM_Scale(HMM_Vec3(2.0f, -3.0f, 0.5f));
|
||||
HMM_Mat4 scale = HMM_Scale(HMM_V3(2.0f, -3.0f, 0.5f));
|
||||
|
||||
hmm_vec3 original = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec4 scaled = HMM_MultiplyMat4ByVec4(scale, HMM_Vec4v(original, 1));
|
||||
HMM_Vec3 original = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec4 scaled = HMM_MulM4V4(scale, HMM_V4V(original, 1));
|
||||
|
||||
EXPECT_FLOAT_EQ(scaled.X, 2.0f);
|
||||
EXPECT_FLOAT_EQ(scaled.Y, -6.0f);
|
||||
EXPECT_FLOAT_EQ(scaled.Z, 1.5f);
|
||||
EXPECT_FLOAT_EQ(scaled.W, 1.0f);
|
||||
EXPECT_NEAR(scaled.X, 2.0f, 0.001f);
|
||||
EXPECT_NEAR(scaled.Y, -6.0f, 0.001f);
|
||||
EXPECT_NEAR(scaled.Z, 1.5f, 0.001f);
|
||||
EXPECT_NEAR(scaled.W, 1.0f, 0.001f);
|
||||
}
|
||||
|
||||
TEST(Transformations, LookAt)
|
||||
{
|
||||
const float abs_error = 0.0001f;
|
||||
const float abs_error = 0.001f;
|
||||
|
||||
hmm_mat4 result = HMM_LookAt(HMM_Vec3(1.0f, 0.0f, 0.0f), HMM_Vec3(0.0f, 2.0f, 1.0f), HMM_Vec3(2.0f, 1.0f, 1.0f));
|
||||
{ HMM_Mat4 result = HMM_LookAt_RH(HMM_V3(1.0f, 0.0f, 0.0f), HMM_V3(0.0f, 2.0f, 1.0f), HMM_V3(2.0f, 1.0f, 1.0f));
|
||||
|
||||
EXPECT_NEAR(result.Elements[0][0], 0.169031f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][1], 0.897085f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][2], 0.408248f, abs_error);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][3], 0.0f);
|
||||
EXPECT_NEAR(result.Elements[1][0], 0.507093f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][1], 0.276026f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][2], -0.816497f, abs_error);
|
||||
EXPECT_FLOAT_EQ(result.Elements[1][3], 0.0f);
|
||||
EXPECT_NEAR(result.Elements[2][0], -0.845154f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][1], 0.345033f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][2], -0.408248f, abs_error);
|
||||
EXPECT_FLOAT_EQ(result.Elements[2][3], 0.0f);
|
||||
EXPECT_NEAR(result.Elements[3][0], -0.169031f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][1], -0.897085f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][2], -0.408248f, abs_error);
|
||||
EXPECT_FLOAT_EQ(result.Elements[3][3], 1.0f);
|
||||
EXPECT_NEAR(result.Elements[0][0], 0.169031f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][1], 0.897085f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][2], 0.408248f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][3], 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][0], 0.507093f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][1], 0.276026f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][2], -0.816497f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][3], 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][0], -0.845154f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][1], 0.345033f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][2], -0.408248f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][3], 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][0], -0.169031f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][1], -0.897085f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][2], -0.408248f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][3], 1.0f, abs_error);
|
||||
}
|
||||
{
|
||||
HMM_Mat4 result = HMM_LookAt_LH(HMM_V3(1.0f, 0.0f, 0.0f), HMM_V3(0.0f, 2.0f, 1.0f), HMM_V3(2.0f, 1.0f, 1.0f));
|
||||
|
||||
EXPECT_NEAR(result.Elements[0][0], -0.169031f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][1], 0.897085f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][2], -0.408248f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[0][3], 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][0], -0.507093f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][1], 0.276026f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][2], 0.816497f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[1][3], 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][0], 0.845154f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][1], 0.345033f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][2], 0.408248f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[2][3], 0.0f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][0], 0.169031f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][1], -0.897085f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][2], 0.408248f, abs_error);
|
||||
EXPECT_NEAR(result.Elements[3][3], 1.0f, abs_error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,60 +2,60 @@
|
||||
|
||||
TEST(VectorOps, LengthSquared)
|
||||
{
|
||||
hmm_vec2 v2 = HMM_Vec2(1.0f, -2.0f);
|
||||
hmm_vec3 v3 = HMM_Vec3(1.0f, -2.0f, 3.0f);
|
||||
hmm_vec4 v4 = HMM_Vec4(1.0f, -2.0f, 3.0f, 1.0f);
|
||||
HMM_Vec2 v2 = HMM_V2(1.0f, -2.0f);
|
||||
HMM_Vec3 v3 = HMM_V3(1.0f, -2.0f, 3.0f);
|
||||
HMM_Vec4 v4 = HMM_V4(1.0f, -2.0f, 3.0f, 1.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(HMM_LengthSquaredVec2(v2), 5.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthSquaredVec3(v3), 14.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthSquaredVec4(v4), 15.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenSqrV2(v2), 5.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenSqrV3(v3), 14.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenSqrV4(v4), 15.0f);
|
||||
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(HMM_LengthSquared(v2), 5.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthSquared(v3), 14.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthSquared(v4), 15.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenSqr(v2), 5.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenSqr(v3), 14.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenSqr(v4), 15.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(VectorOps, Length)
|
||||
{
|
||||
hmm_vec2 v2 = HMM_Vec2(1.0f, -9.0f);
|
||||
hmm_vec3 v3 = HMM_Vec3(2.0f, -3.0f, 6.0f);
|
||||
hmm_vec4 v4 = HMM_Vec4(2.0f, -3.0f, 6.0f, 12.0f);
|
||||
HMM_Vec2 v2 = HMM_V2(1.0f, -9.0f);
|
||||
HMM_Vec3 v3 = HMM_V3(2.0f, -3.0f, 6.0f);
|
||||
HMM_Vec4 v4 = HMM_V4(2.0f, -3.0f, 6.0f, 12.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec2(v2), 9.0553856f);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec3(v3), 7.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec4(v4), 13.892444f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenV2(v2), 9.0553856f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenV3(v3), 7.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_LenV4(v4), 13.892444f);
|
||||
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(HMM_Length(v2), 9.0553856f);
|
||||
EXPECT_FLOAT_EQ(HMM_Length(v3), 7.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Length(v4), 13.892444f);
|
||||
EXPECT_FLOAT_EQ(HMM_Len(v2), 9.0553856f);
|
||||
EXPECT_FLOAT_EQ(HMM_Len(v3), 7.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_Len(v4), 13.892444f);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(VectorOps, Normalize)
|
||||
{
|
||||
hmm_vec2 v2 = HMM_Vec2(1.0f, -2.0f);
|
||||
hmm_vec3 v3 = HMM_Vec3(1.0f, -2.0f, 3.0f);
|
||||
hmm_vec4 v4 = HMM_Vec4(1.0f, -2.0f, 3.0f, -1.0f);
|
||||
HMM_Vec2 v2 = HMM_V2(1.0f, -2.0f);
|
||||
HMM_Vec3 v3 = HMM_V3(1.0f, -2.0f, 3.0f);
|
||||
HMM_Vec4 v4 = HMM_V4(1.0f, -2.0f, 3.0f, -1.0f);
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_NormalizeVec2(v2);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec2(result), 1.0f);
|
||||
HMM_Vec2 result = HMM_NormV2(v2);
|
||||
EXPECT_NEAR(HMM_LenV2(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = HMM_NormalizeVec3(v3);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec3(result), 1.0f);
|
||||
HMM_Vec3 result = HMM_NormV3(v3);
|
||||
EXPECT_NEAR(HMM_LenV3(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
EXPECT_GT(result.Z, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = HMM_NormalizeVec4(v4);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec4(result), 1.0f);
|
||||
HMM_Vec4 result = HMM_NormV4(v4);
|
||||
EXPECT_NEAR(HMM_LenV4(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
EXPECT_GT(result.Z, 0.0f);
|
||||
@@ -64,21 +64,21 @@ TEST(VectorOps, Normalize)
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_Normalize(v2);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec2(result), 1.0f);
|
||||
HMM_Vec2 result = HMM_Norm(v2);
|
||||
EXPECT_NEAR(HMM_LenV2(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = HMM_Normalize(v3);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec3(result), 1.0f);
|
||||
HMM_Vec3 result = HMM_Norm(v3);
|
||||
EXPECT_NEAR(HMM_LenV3(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
EXPECT_GT(result.Z, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = HMM_Normalize(v4);
|
||||
EXPECT_FLOAT_EQ(HMM_LengthVec4(result), 1.0f);
|
||||
HMM_Vec4 result = HMM_Norm(v4);
|
||||
EXPECT_NEAR(HMM_LenV4(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
EXPECT_GT(result.Z, 0.0f);
|
||||
@@ -89,23 +89,23 @@ TEST(VectorOps, Normalize)
|
||||
|
||||
TEST(VectorOps, NormalizeZero)
|
||||
{
|
||||
hmm_vec2 v2 = HMM_Vec2(0.0f, 0.0f);
|
||||
hmm_vec3 v3 = HMM_Vec3(0.0f, 0.0f, 0.0f);
|
||||
hmm_vec4 v4 = HMM_Vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
HMM_Vec2 v2 = HMM_V2(0.0f, 0.0f);
|
||||
HMM_Vec3 v3 = HMM_V3(0.0f, 0.0f, 0.0f);
|
||||
HMM_Vec4 v4 = HMM_V4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_NormalizeVec2(v2);
|
||||
HMM_Vec2 result = HMM_NormV2(v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = HMM_NormalizeVec3(v3);
|
||||
HMM_Vec3 result = HMM_NormV3(v3);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = HMM_NormalizeVec4(v4);
|
||||
HMM_Vec4 result = HMM_NormV4(v4);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
@@ -114,118 +114,18 @@ TEST(VectorOps, NormalizeZero)
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_Normalize(v2);
|
||||
HMM_Vec2 result = HMM_Norm(v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = HMM_Normalize(v3);
|
||||
HMM_Vec3 result = HMM_Norm(v3);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = HMM_Normalize(v4);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(VectorOps, FastNormalize)
|
||||
{
|
||||
hmm_vec2 v2 = HMM_Vec2(1.0f, -2.0f);
|
||||
hmm_vec3 v3 = HMM_Vec3(1.0f, -2.0f, 3.0f);
|
||||
hmm_vec4 v4 = HMM_Vec4(1.0f, -2.0f, 3.0f, -1.0f);
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_FastNormalizeVec2(v2);
|
||||
EXPECT_NEAR(HMM_LengthVec2(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = HMM_FastNormalizeVec3(v3);
|
||||
EXPECT_NEAR(HMM_LengthVec3(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
EXPECT_GT(result.Z, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = HMM_FastNormalizeVec4(v4);
|
||||
EXPECT_NEAR(HMM_LengthVec4(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
EXPECT_GT(result.Z, 0.0f);
|
||||
EXPECT_LT(result.W, 0.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_FastNormalize(v2);
|
||||
EXPECT_NEAR(HMM_LengthVec2(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = HMM_FastNormalize(v3);
|
||||
EXPECT_NEAR(HMM_LengthVec3(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
EXPECT_GT(result.Z, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = HMM_FastNormalize(v4);
|
||||
EXPECT_NEAR(HMM_LengthVec4(result), 1.0f, 0.001f);
|
||||
EXPECT_GT(result.X, 0.0f);
|
||||
EXPECT_LT(result.Y, 0.0f);
|
||||
EXPECT_GT(result.Z, 0.0f);
|
||||
EXPECT_LT(result.W, 0.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(VectorOps, FastNormalizeZero)
|
||||
{
|
||||
hmm_vec2 v2 = HMM_Vec2(0.0f, 0.0f);
|
||||
hmm_vec3 v3 = HMM_Vec3(0.0f, 0.0f, 0.0f);
|
||||
hmm_vec4 v4 = HMM_Vec4(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
{
|
||||
hmm_vec2 result = HMM_FastNormalizeVec2(v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = HMM_FastNormalizeVec3(v3);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = HMM_FastNormalizeVec4(v4);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.W, 0.0f);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
hmm_vec2 result = HMM_FastNormalize(v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec3 result = HMM_FastNormalize(v3);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
}
|
||||
{
|
||||
hmm_vec4 result = HMM_FastNormalize(v4);
|
||||
HMM_Vec4 result = HMM_Norm(v4);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.0f);
|
||||
@@ -236,10 +136,10 @@ TEST(VectorOps, FastNormalizeZero)
|
||||
|
||||
TEST(VectorOps, Cross)
|
||||
{
|
||||
hmm_vec3 v1 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 v2 = HMM_Vec3(4.0f, 5.0f, 6.0f);
|
||||
HMM_Vec3 v1 = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 v2 = HMM_V3(4.0f, 5.0f, 6.0f);
|
||||
|
||||
hmm_vec3 result = HMM_Cross(v1, v2);
|
||||
HMM_Vec3 result = HMM_Cross(v1, v2);
|
||||
|
||||
EXPECT_FLOAT_EQ(result.X, -3.0f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 6.0f);
|
||||
@@ -248,10 +148,10 @@ TEST(VectorOps, Cross)
|
||||
|
||||
TEST(VectorOps, DotVec2)
|
||||
{
|
||||
hmm_vec2 v1 = HMM_Vec2(1.0f, 2.0f);
|
||||
hmm_vec2 v2 = HMM_Vec2(3.0f, 4.0f);
|
||||
HMM_Vec2 v1 = HMM_V2(1.0f, 2.0f);
|
||||
HMM_Vec2 v2 = HMM_V2(3.0f, 4.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(HMM_DotVec2(v1, v2), 11.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_DotV2(v1, v2), 11.0f);
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(HMM_Dot(v1, v2), 11.0f);
|
||||
#endif
|
||||
@@ -259,10 +159,10 @@ TEST(VectorOps, DotVec2)
|
||||
|
||||
TEST(VectorOps, DotVec3)
|
||||
{
|
||||
hmm_vec3 v1 = HMM_Vec3(1.0f, 2.0f, 3.0f);
|
||||
hmm_vec3 v2 = HMM_Vec3(4.0f, 5.0f, 6.0f);
|
||||
HMM_Vec3 v1 = HMM_V3(1.0f, 2.0f, 3.0f);
|
||||
HMM_Vec3 v2 = HMM_V3(4.0f, 5.0f, 6.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(HMM_DotVec3(v1, v2), 32.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_DotV3(v1, v2), 32.0f);
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(HMM_Dot(v1, v2), 32.0f);
|
||||
#endif
|
||||
@@ -270,23 +170,85 @@ TEST(VectorOps, DotVec3)
|
||||
|
||||
TEST(VectorOps, DotVec4)
|
||||
{
|
||||
hmm_vec4 v1 = HMM_Vec4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
hmm_vec4 v2 = HMM_Vec4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
HMM_Vec4 v1 = HMM_V4(1.0f, 2.0f, 3.0f, 4.0f);
|
||||
HMM_Vec4 v2 = HMM_V4(5.0f, 6.0f, 7.0f, 8.0f);
|
||||
|
||||
EXPECT_FLOAT_EQ(HMM_DotVec4(v1, v2), 70.0f);
|
||||
EXPECT_FLOAT_EQ(HMM_DotV4(v1, v2), 70.0f);
|
||||
#ifdef __cplusplus
|
||||
EXPECT_FLOAT_EQ(HMM_Dot(v1, v2), 70.0f);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(VectorOps, LerpV2)
|
||||
{
|
||||
HMM_Vec2 v1 = HMM_V2(1.0f, 0.0f);
|
||||
HMM_Vec2 v2 = HMM_V2(0.0f, 1.0f);
|
||||
|
||||
{
|
||||
HMM_Vec2 result = HMM_LerpV2(v1, 0.5, v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.5f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Vec2 result = HMM_Lerp(v1, 0.5, v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 0.5f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(VectorOps, LerpV3)
|
||||
{
|
||||
HMM_Vec3 v1 = HMM_V3(1.0f, 1.0f, 0.0f);
|
||||
HMM_Vec3 v2 = HMM_V3(0.0f, 1.0f, 1.0f);
|
||||
|
||||
{
|
||||
HMM_Vec3 result = HMM_LerpV3(v1, 0.5, v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.5f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Vec3 result = HMM_Lerp(v1, 0.5, v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.5f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(VectorOps, LerpV4)
|
||||
{
|
||||
HMM_Vec4 v1 = HMM_V4(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
HMM_Vec4 v2 = HMM_V4(0.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
||||
{
|
||||
HMM_Vec4 result = HMM_LerpV4(v1, 0.5, v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.W, 1.0f);
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
HMM_Vec4 result = HMM_Lerp(v1, 0.5, v2);
|
||||
EXPECT_FLOAT_EQ(result.X, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.Y, 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Z, 0.5f);
|
||||
EXPECT_FLOAT_EQ(result.W, 1.0f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* MatrixOps tests
|
||||
*/
|
||||
|
||||
TEST(MatrixOps, Transpose)
|
||||
TEST(MatrixOps, TransposeM4)
|
||||
{
|
||||
hmm_mat4 m4 = HMM_Mat4(); // will have 1 - 16
|
||||
HMM_Mat4 m4 = HMM_M4(); // will have 1 - 16
|
||||
|
||||
// Fill the matrix
|
||||
int Counter = 1;
|
||||
@@ -300,7 +262,7 @@ TEST(MatrixOps, Transpose)
|
||||
}
|
||||
|
||||
// Test the matrix
|
||||
hmm_mat4 result = HMM_Transpose(m4);
|
||||
HMM_Mat4 result = HMM_TransposeM4(m4);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][0], 1.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][1], 5.0f);
|
||||
EXPECT_FLOAT_EQ(result.Elements[0][2], 9.0f);
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "HandmadeTest.h"
|
||||
#include "hmm_test.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
return hmt_run_all_tests();
|
||||
int tests_failed = hmt_run_all_tests();
|
||||
int coverage_failed = hmt_check_all_coverage();
|
||||
|
||||
return tests_failed || coverage_failed;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
#include <float.h>
|
||||
|
||||
#define HANDMADE_TEST_IMPLEMENTATION
|
||||
#include "HandmadeTest.h"
|
||||
|
||||
#undef COVERAGE // Make sure we don't double-define initializers from the header part
|
||||
#include "../HandmadeMath.h"
|
||||
|
||||
#include "categories/ScalarMath.h"
|
||||
#include "categories/Initialization.h"
|
||||
#include "categories/VectorOps.h"
|
||||
#include "categories/MatrixOps.h"
|
||||
#include "categories/QuaternionOps.h"
|
||||
#include "categories/Addition.h"
|
||||
#include "categories/Subtraction.h"
|
||||
|
||||
18
test/run_test_clang.bat
Normal file
18
test/run_test_clang.bat
Normal file
@@ -0,0 +1,18 @@
|
||||
@echo off
|
||||
|
||||
if not exist "build" mkdir build
|
||||
pushd build
|
||||
|
||||
clang-cl /Fehmm_test_c.exe ..\HandmadeMath.c ..\hmm_test.c
|
||||
hmm_test_c
|
||||
|
||||
clang-cl /Fehmm_test_c_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.c ..\hmm_test.c
|
||||
hmm_test_c_no_sse
|
||||
|
||||
clang-cl /Fehmm_test_cpp.exe ..\HandmadeMath.cpp ..\hmm_test.cpp
|
||||
hmm_test_cpp
|
||||
|
||||
clang-cl /Fehmm_test_cpp_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.cpp ..\hmm_test.cpp
|
||||
hmm_test_cpp_no_sse
|
||||
|
||||
popd
|
||||
27
test/run_test_msvc.bat
Normal file
27
test/run_test_msvc.bat
Normal file
@@ -0,0 +1,27 @@
|
||||
@echo off
|
||||
|
||||
if "%1%"=="travis" (
|
||||
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\Tools\VsDevCmd.bat" -host_arch=amd64 -arch=amd64
|
||||
) else (
|
||||
where /q cl
|
||||
if ERRORLEVEL 1 (
|
||||
for /f "delims=" %%a in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -find VC\Auxiliary\Build\vcvarsall.bat') do (%%a x64)
|
||||
)
|
||||
)
|
||||
|
||||
if not exist "build" mkdir build
|
||||
pushd build
|
||||
|
||||
cl /Fehmm_test_c.exe ..\HandmadeMath.c ..\hmm_test.c
|
||||
hmm_test_c
|
||||
|
||||
cl /Fehmm_test_c_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.c ..\hmm_test.c
|
||||
hmm_test_c_no_sse
|
||||
|
||||
cl /Fehmm_test_cpp.exe ..\HandmadeMath.cpp ..\hmm_test.cpp
|
||||
hmm_test_cpp
|
||||
|
||||
cl /Fehmm_test_cpp_no_sse.exe /DHANDMADE_MATH_NO_SSE ..\HandmadeMath.cpp ..\hmm_test.cpp
|
||||
hmm_test_cpp_no_sse
|
||||
|
||||
popd
|
||||
24
update/README.md
Normal file
24
update/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
# Handmade Math 2.0 Update Tool
|
||||
|
||||
Due to the large number of breaking naming changes in Handmade Math 2, we provide a small Python script to update your programs automatically. It can run on individual files or on all files in a directory (recursively).
|
||||
|
||||
**Warning!** This tool is not very smart! Please ensure that your work is committed and backed up, in case you have to revert this tool's changes.
|
||||
|
||||
```
|
||||
# see usage info and options
|
||||
> python3 update_hmm.py -h
|
||||
usage: update_hmm [-h] [--exts .foo [.foo ...]] filename [filename ...]
|
||||
...
|
||||
|
||||
# run on individual files
|
||||
> python3 update_hmm.py MyPlatformLayer.c MyPlatformLayer.h
|
||||
Updating: MyPlatformLayer.c
|
||||
Updating: MyPlatformLayer.h
|
||||
Updated 2 files with 0 warnings.
|
||||
|
||||
# run on a whole directory
|
||||
> python3 update_hmm.py projects/MyCoolGame
|
||||
Updating: projects/MyCoolGame/src/MyPlatformLayer.c
|
||||
Updating: projects/MyCoolGame/include/MyPlatformLayer.h
|
||||
...
|
||||
```
|
||||
166
update/update_hmm.py
Executable file
166
update/update_hmm.py
Executable file
@@ -0,0 +1,166 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
|
||||
typeReplacements = [
|
||||
('hmm_', 'HMM_'),
|
||||
|
||||
('vec', 'Vec'),
|
||||
('mat', 'Mat'),
|
||||
('quaternion', 'Quaternion'),
|
||||
('bool', 'Bool'),
|
||||
('.InternalElementsSSE', '.SSE'),
|
||||
]
|
||||
|
||||
funcReplacements = [
|
||||
('HMM_', 'HMM_'),
|
||||
|
||||
('Vec', 'V'),
|
||||
('Mat', 'M'),
|
||||
('Quaternion', 'Q'),
|
||||
('Equals', 'Eq'),
|
||||
('Subtract', 'Sub'),
|
||||
('Multiply', 'Mul'),
|
||||
('Divide', 'Div'),
|
||||
('Inverse', 'Inv'),
|
||||
('RSquareRoot', 'InvSqrt'),
|
||||
('SquareRoot', 'Sqrt'),
|
||||
('Squared', 'Sqr'),
|
||||
('Length', 'Len'),
|
||||
|
||||
('Slerp', 'SLerp'),
|
||||
('By', ''),
|
||||
('LinearCombineSSE', 'LinearCombineV4M4'),
|
||||
('Transpose', 'TransposeM4'),
|
||||
('Fast', ''), # TODO(port): emit warning, lower precision
|
||||
('Normalize', 'Norm'),
|
||||
('ToRadians', 'ToRad')
|
||||
]
|
||||
|
||||
handedFuncs = [
|
||||
'Perspective',
|
||||
'Rotate',
|
||||
'Orthographic',
|
||||
'LookAt',
|
||||
'FromAxisAngle',
|
||||
'ToQuaternion',
|
||||
]
|
||||
|
||||
projectionFuncs = [
|
||||
'Perspective',
|
||||
'Orthographic',
|
||||
]
|
||||
|
||||
numFiles = 0
|
||||
numWarnings = 0
|
||||
|
||||
def printWarning(msg):
|
||||
global numWarnings
|
||||
numWarnings += 1
|
||||
print('WARNING: {}'.format(msg))
|
||||
|
||||
def updateFile(filename):
|
||||
global numFiles
|
||||
print('Updating: {}'.format(filename))
|
||||
numFiles += 1
|
||||
result = ''
|
||||
with open(filename, 'r', newline='') as f:
|
||||
for lineNo, line in enumerate(f):
|
||||
updatedLine = line
|
||||
|
||||
def printLineWarning(msg):
|
||||
printWarning(' Line {}: {}'.format(lineNo + 1, msg))
|
||||
|
||||
def replaceName(m):
|
||||
name = m.group()
|
||||
if name.startswith('hmm_'):
|
||||
# do type replacements
|
||||
for before, after in typeReplacements:
|
||||
if before not in name:
|
||||
continue
|
||||
name = name.replace(before, after)
|
||||
else:
|
||||
# do func replacements
|
||||
for before, after in funcReplacements:
|
||||
if before not in name:
|
||||
continue
|
||||
name = name.replace(before, after)
|
||||
|
||||
if after == 'LinearCombineV4M4':
|
||||
printLineWarning('HMM_LinearCombineSSE is now HMM_LinearCombineV4M4, and will now use a fallback method when SSE is not available. You no longer need to check for the availability of SSE.')
|
||||
if after == 'V' or after == 'M':
|
||||
# uppercase the modifier, if any
|
||||
name = re.sub(
|
||||
r'[VM]\d[ivfd]?',
|
||||
lambda m: m.group().upper(),
|
||||
name
|
||||
)
|
||||
# and also nuke the integer constructors
|
||||
vecIntMatch = re.search(r'(V\d)I', name)
|
||||
if vecIntMatch:
|
||||
name = name.replace(vecIntMatch.group(), vecIntMatch.group(1))
|
||||
|
||||
# add handedness / NDC modifiers
|
||||
if not any(x in name for x in ['RH', 'LH', 'NO', 'ZO']):
|
||||
for handedFunc in handedFuncs:
|
||||
suffixed = handedFunc + '_RH'
|
||||
if handedFunc in projectionFuncs:
|
||||
suffixed += '_NO'
|
||||
name = name.replace(handedFunc, suffixed)
|
||||
return name
|
||||
|
||||
def wrapDegrees(m):
|
||||
name = m.group('name')
|
||||
arg = m.group('arg')
|
||||
if '(' in arg:
|
||||
# all bets are off, don't wrap the argument
|
||||
printLineWarning('{} now takes radians, but we were unable to automatically wrap the first argument with HMM_AngleDeg().'.format(name))
|
||||
return m.group()
|
||||
return '{}(HMM_AngleDeg({}),'.format(name, arg)
|
||||
|
||||
updatedLine = re.sub(r'(hmm_|HMM_)\w+', replaceName, updatedLine)
|
||||
updatedLine = re.sub(r'(?P<name>HMM_Perspective_RH_NO|HMM_Rotate_RH)\((?P<arg>.*?),', wrapDegrees, updatedLine)
|
||||
|
||||
result += updatedLine
|
||||
|
||||
with open(filename, 'w', newline='') as f:
|
||||
f.write(result)
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog = 'update_hmm',
|
||||
description = 'Updates C and C++ source code to use Handmade Math 2.0.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'filename', nargs='+',
|
||||
help='A file or directory to update to HMM 2.0. If a directory, all files with extensions from --exts will be processed.',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--exts', nargs='+', default=['.c', '.cpp', '.h', '.hpp'],
|
||||
help='File extensions to run the script on, when targeting a directory. Default: .c, .cpp, .h, .hpp.',
|
||||
metavar='.foo',
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
for path in args.filename:
|
||||
filenames = []
|
||||
if os.path.isfile(path):
|
||||
filenames = [path]
|
||||
else:
|
||||
for root, dirs, files in os.walk(path):
|
||||
for file in files:
|
||||
if file == 'HandmadeMath.h':
|
||||
printWarning('HandmadeMath.h will not be replaced by this script.')
|
||||
elif file.endswith(tuple(args.exts)):
|
||||
filenames.append(os.path.join(root, file))
|
||||
|
||||
for filename in filenames:
|
||||
try:
|
||||
updateFile(filename)
|
||||
except UnicodeDecodeError:
|
||||
pass
|
||||
|
||||
print('Updated {} files with {} warnings.'.format(numFiles, numWarnings))
|
||||
Reference in New Issue
Block a user