Git Product home page Git Product logo

mathfu's Introduction

MathFu Version 1.1.0 {#mathfu_readme}

MathFu is a C++ math library developed primarily for games focused on simplicity and efficiency.

It provides a suite of vector, matrix and quaternion classes to perform basic geometry suitable for game developers. This functionality can be used to construct geometry for graphics libraries like OpenGL or perform calculations for animation or physics systems.

The library is written in portable C++ with SIMD compiler intrinsics and has been tested on the following platforms:

Go to our landing page to browse our documentation and see some examples.

Important: MathFu uses submodules to reference other components it depends upon so download the source using:

git clone --recursive https://github.com/google/mathfu.git

To contribute to this project see CONTRIBUTING.

For applications on Google Play that integrate this tool, usage is tracked. This tracking is done automatically using the embedded version string (kMathFuVersionString), and helps us continue to optimize it. Aside from consuming a few extra bytes in your application binary, it shouldn't affect your application at all. We use this information to let us know if MathFu is useful and if we should continue to invest in it. Since this is open source, you are free to remove the version string but we would appreciate if you would leave it in.

mathfu's People

Contributors

0x8000-0000 avatar a-maurice avatar billhsu avatar chaoren avatar ckennelly avatar ggfan avatar hak avatar hardik0307 avatar haroonq avatar herculesjr avatar jonsimantov avatar joshperry avatar jsanmiya avatar kiranchhetri1 avatar mrhappyasthma avatar purplemunster avatar renfengliu avatar rokn avatar spacekitty avatar stewartmiles avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mathfu's Issues

When building Google_MathFu emits warning C2220 on MSVC

Hi, all
Google_MathFu fails to build on MSVC due to warning C2220 Could you help look?
Environment:
Windows: windows server 2019
VS: 2019

Repro steps:
1.git clone https://github.com/google/mathfu F:\gitP\google\mathfu
2. mkdir build_amd64 & cd F:\gitP\google\mathfu\build_amd64
3. set VSCMD_SKIP_SENDTELEMETRY=1 & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\Tools\VsDevCmd.bat" -host_arch=amd64 -arch=amd64
4. cd F:\gitP\google\mathfu\build_amd64
5. msbuild /p:Platform=x64 /p:Configuration=Release mathfu.sln /t:Rebuild 2>&1
Expected
build successfully.

Source
No response

Custom changes or Modules
the commit of Google_MathFu we use is da23a12

error message:
F:\gitP\google\mathfu\unit_tests\quaternion_test\quaternion_test.cpp(117,32): error C2220: the following warning is treated as an error [F:\gitP\google\mathfu\build_amd64\unit_tests\quaternion_no_simd_tests.vcxproj]
F:\gitP\google\mathfu\unit_tests\quaternion_test\quaternion_test.cpp(117,32): error C2220: the following warning is treated as an error [F:\gitP\google\mathfu\build_amd64\unit_tests\quaternion_simd_no_padding_tests.vcxproj]
F:\gitP\google\mathfu\unit_tests\quaternion_test\quaternion_test.cpp(117,32): error C2220: the following warning is treated as an error [F:\gitP\google\mathfu\build_amd64\unit_tests\quaternion_simd_padding_tests.vcxproj]
F:\gitP\google\mathfu\unit_tests\quaternion_test\quaternion_test.cpp(117,32): error C2220: the following warning is treated as an error [F:\gitP\google\mathfu\build_amd64\unit_tests\quaternion_tests.vcxproj]

method HadamardProduct of Matrix can not compile

static inline Matrix<T, Rows, Cols> HadamardProduct( const Matrix<T, Rows, Cols>& m1, const Matrix<T, Rows, Cols>& m2) {
MATHFU_MAT_OPERATOR(m1[i] * m2[i]);
}

this function can not compile because MATHFU_MAT_OPERATOR expand as :
Matrix<T, Rows, Cols> result;
MATHFU_TOOL_MAT_OPERATION(result.data_[i] = (OP));

where result.data_[i] is a vector and m1[i] * m2[i] is a scalar

this shoud be implemented as below:
static inline Matrix<T, Rows, Cols> HadamardProduct( const Matrix<T, Rows, Cols>& m1, const Matrix<T, Rows, Cols>& m2) {
Matrix<T, Rows, Cols> result;
for (int i = 0; i < kElements;++i) {
result[i] = (m1[i] * m2[i]);
}
return result;
}

Can't seem to properly clone library

The instructions regarding the recursive cloning fails on fetching on fplutil: "Connection reset by peer".
What is my mistake on this? Tried on Ubuntu Linux 14.04 and OSX Yosemite.
(BTW, I'm able to clone fplutil's HEAD)

Why LookAt from mathfu differs from GLM?

mat4::LookAt(vec3(0, 0, 0), vec3(0, 0, 1), vec3(0, 1, 0)):

-1,  0,  0,  0
 0,  1,  0,  0
 0,  0, -1,  0
 0,  0,  1,  1

glm::lookAt(glm::vec3(0, 0, 1), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)):

 1,  0,  0,  0
 0,  1,  0,  0
 0,  0,  1,  0
 0,  0, -1,  1

I'm trying to setup a simple OpenGL sample using the mat4::LookAt function, but while I had no problems with GLM, this LookAt matrix is strange and I just get a black screen.

Support for double vectors/matrices (with SIMD)?

Although this library is geared more towards graphics / game development than numeric computation, I think double-typed SIMD vectors will be very useful for implementing various physics simulations (for example, a lot of the fluid simulations tend to use doubles instead of floats because of numerical stability.)

One caveat is that we would have to write special code for SIMD for this feature, as the library only provides SIMD wrapper operations for floats. Maybe if I have the time I would try working on it...

Matrix vector product question.

Hello, i was looking at the source of Matrix and found that the product with a vector use a macro and not call the DotProduct function. Why this choice as it disable SIMD dot support for 2/3/4 size vector ?

Vector and matrix copy to C array.

I'm trying to use mathfu in this project: https://github.com/UPBGE/blender, but i could not find a simple way to copy data from a vector or matrix to a C array.
The current library we use has a function named getValue which is used as below:

float a[3];
vec.getValue(a); // content of vec is copied to the a array

But i can't found a way to do similar work using VectorPack and Vector::Pack.

So, what is the simple way to copy the vector content to an array assuming this array could not be replaced by VectorPack ?

Google_MathFu failed to build due to error C1083 with MSVC on windows

Environment:
Windows Server 2016 + VS2017 + Google_MathFu master branch latest srouce code.

Google_MathFu failed to build due to error C1083: Cannot open include file: 'third_party/mathfu/include/mathfu/constants.h': No such file or directory with MSVC on windows. It can be first reproduced on master revision d66be09. Could you help have a look about this issue? Thanks in advance!

log_x86_build.log

Steps to reproduce the behavior:
1.git clone --recursive https://github.com/google/mathfu.git D:\Google-MathFu\src
2.Open a VS 2017 command prompt and browse to D:\Google-MathFu
3.mkdir build_x86 && pushd build_x86
4.cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 ..\src
5.msbuild /p:Configuration=Release;Platform=Win32 build_x86\mathfu.sln /t:Rebuild

Actual result:
D:\Google-Mathfu\src\unit_tests\quaternion_test\quaternion_test.cpp(25,10): error C1083: Cannot open include file: 'third_party/mathfu/include/mathfu/constants.h': No such file or directory (d:\agent_work\1\s\src\vctools\Compiler\CxxFE\sl\p1\c\p0prepro.c:1722) [D:\Google-Mathfu\build_x86\unit_tests\quaternion_no_simd_tests.vcxproj]
D:\Google-Mathfu\src\unit_tests\quaternion_test\quaternion_test.cpp(25,10): error C1083: #include "third_party/mathfu/include/mathfu/constants.h" [D:\Google-Mathfu\build_x86\unit_tests\quaternion_no_simd_tests.vcxproj]
D:\Google-Mathfu\src\unit_tests\quaternion_test\quaternion_test.cpp(25,10): error C1083: ^ [D:\Google-Mathfu\build_x86\unit_tests\quaternion_no_simd_tests.vcxproj]
Done Building Project "D:\Google-Mathfu\build_x86\unit_tests\quaternion_no_simd_tests.vcxproj" (Rebuild target(s)) -- FAILED.
Done Building Project "D:\Google-Mathfu\build_x86\unit_tests\quaternion_no_simd_tests.vcxproj.metaproj" (Rebuild target(s)) -- FAILED.

Difference in perspective matrix between GLM & MathFu

When I create a perspective matrix with MathFu like perspective(45.0f, 1280.0f / 720.0f, 0.1f, 100.0f)
I get:

 1.01,  0.00,  0.00,  0.00
 0.00,  1.79,  0.00,  0.00
 0.00,  0.00, -1.00, -0.10
 0.00,  0.00, -1.00,  0.00

Using GLM, I get:

 1.01,  0.00,  0.00,  0.00
 0.00,  1.79,  0.00,  0.00
 0.00,  0.00, -1.00, -0.20
 0.00,  0.00, -1.00,  0.00

Wondering why there is a difference?

Projection function

Hi. The library contains the "UnProjectHelper" to convert a 2D screen point to 3D world point. Would be hard to implement a "ProjectHelper" function, to convert from 3D to 2D screen point?

Compile flag Not Updated

For target architecture = ARM c flags is not updated -mfpu=neon in CMakeLists.txt and Android.mk.

In both files, by default, flag "-msse4.1" is passed for the ARM platform on which I tried to build.

Linux ubuntu 5.4.0-1046-raspi #50-Ubuntu SMP PREEMPT Thu Oct 28 05:32:10 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

matrix_4x4_simd.h is not included by default

It appears that the SIMD specialization for the Matrix 4x4 isn't included by default which means it defaults to scalar code. This differs from the Vector types which include the SIMD specializations by default.

How about let `xy()` and `xyz()` functions return references instead of values.

I had noticed that mathfu::Vector<T, 3> has homogeneous memory representation with mathfu::Vector<T, 3>.
It means that mathfu::vec3 can be safely casted to mathfu::vec2 via reinterpret_cast<mathfu::vec2&>( vec3_inst ).
And same situation i see for mathfu::vec4 and mathfu::vec3 classes.

So how about making mathfu::vec3::xy(), mathfu::vec4::xy() and mathfu::vec4::xyz() return references instead of values?

Smth like:

inline Vector<T, 2>& xy() { return *reinterpret_cast<Vector<T, 2>*>( this ); };
inline const Vector<T, 2>& xy() const { return *reinterpret_cast<const Vector<T, 2>*>( this ); };

Such conversion is much helpful!

Google_Mathfu failed with warning C4305 when build with MSVC

Hi All,

I tried to build Mathfu with Visual studio 2017 update 5 on Windows Server 2016, but it failed with warning C4305: 'argument': truncation from 'double' to 'const T'. This issue can be reproduced from master revision d036807. Could you help have a look about this issue? Thanks in advance!

Steps to Reproduce:

  1. git clone --recursive https://github.com/google/mathfu.git D:\Google-MathFu\src
  2. Open a VS 2017 command prompt and browse to D:\Google-MathFu
  3. mkdir build_x86 && pushd build_x86
  4. cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_VERSION=10.0.16299.0 ..\src
  5. msbuild /p:Configuration=Release;Platform=Win32 .\mathfu.sln /t:Rebuild

Actual result:
The whole log file please see attachment.
log_x86_build.log
D:\Google-Mathfu\src\unit_tests\quaternion_test\quaternion_test.cpp(468,1): error C2220: warning treated as error - no 'object' file generated [D:\Google-Mathfu\build_x86\unit_tests\quaternion_no_simd_tests.vcxproj]
mathfu::Vector<T, 3> eulers(0.1, 0.2, 0.3);
^
D:\Google-Mathfu\src\unit_tests\quaternion_test\quaternion_test.cpp(475): note: see reference to function template instantiation 'void FromEulerAnglesSplit_Test(const T &)' being compiled
with
[
T=float
]
TEST_ALL_F(FromEulerAnglesSplit);
D:\Google-Mathfu\src\unit_tests\quaternion_test\quaternion_test.cpp(468,1): warning C4305: 'argument': truncation from 'double' to 'const T' [D:\Google-Mathfu\build_x86\unit_tests\quaternion_no_simd_tests.vcxproj]
with
[
T=float
]
mathfu::Vector<T, 3> eulers(0.1, 0.2, 0.3);
^

Google_Mathfu failed with warning C4100 when build with MSVC

Hi All,

I tried to build Mathfu with Visual studio 2017 on Windows Server 2016, but it failed with warning C4100: 'precision': unreferenced formal parameter. This issue can be reproduced from master revision a120edf. Could you help have a look about this issue? Thanks in advance!

We have made workaround for this: google_mathfu_warning_c4100.patch.txt

Steps to Reproduce:

  1. git clone --recursive https://github.com/google/mathfu.git D:\Google-MathFu\src
  2. Open a VS 2017 command prompt and browse to D:\Google-MathFu
  3. mkdir build_x86 && pushd build_x86
  4. cmake -G "Visual Studio 15 2017" -DCMAKE_SYSTEM_VERSION=10.0.17134.0 ..\src
  5. msbuild /p:Configuration=Release;Platform=Win32 .\mathfu.sln /t:Rebuild

Actual result:
D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(117): error C2220: warning treated as error - no 'object' file generated
D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(117): warning C4100: 'precision': unreferenced formal parameter
D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(130): note: see reference to function template instantiation 'void anonymous-namespace'::TestHelpers_Test<float>(const T &)' being compiled with [ T=float ] D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(338): warning C4100: 'precision': unreferenced formal parameter D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(367): note: see reference to function template instantiation 'void anonymous-namespace'::MultQuatFloatFlipsQuat_Test(const T &)' being compiled
with
[
T=float
]
D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(437): warning C4100: 'precision': unreferenced formal parameter
D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(470): note: see reference to function template instantiation 'void anonymous-namespace'::ToAngleAxisReturnsSmallQuat_Test<float>(const T &)' being compiled with [ T=float ] D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(625): warning C4100: 'precision': unreferenced formal parameter D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(645): note: see reference to function template instantiation 'void anonymous-namespace'::SlerpResultIsUnit_Test(const T &)' being compiled
with
[
T=float
]
D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(688): warning C4100: 'precision': unreferenced formal parameter
D:\Google-MathFu\src\unit_tests\quaternion_test\quaternion_test.cpp(715): note: see reference to function template instantiation 'void `anonymous-namespace'::Slerp_Test(const T &)' being compiled
with
[
T=float
]

Ortho/Perspective matrices are different than from DirectX 9 Math library.

Hi there.
Currently i have working on some test and found some unclear moments between Mathfu and DirectX Math.
I know how the canonical perspective and orthographic matrices looks like. What i wondering is why DirectX Math uses different calculations for perspective and orthographic matrices?
I work with DirectX Math almost 10 years and never had a problems with projection matrices.

For example i had run tests from 'matrix_test.cpp' for DirectX 9 Math and get next results.

Right-handed perspective
   ( atan( 1.0 ) * 2.0, 1.0, -2.0, 2.0 )
        Mathfu              DirectX9
| 1.0  0.0  0.0  0.0 | 1.0  0.0  0.0  0.0 |
| 0.0  1.0  0.0  0.0 | 0.0  1.0  0.0  0.0 |
| 0.0  0.0 -0.5 -1.0 | 0.0  0.0 -0.5 -1.0 |
| 0.0  0.0  2.0  0.0 | 0.0  0.0  1.0  0.0 |

Left-handed perspective
   ( atan( 1.0 ) * 2.0, 1.0, -2.0, 2.0 )
        Mathfu              DirectX9
| 1.0  0.0  0.0  0.0 | 1.0  0.0  0.0  0.0 |
| 0.0  1.0  0.0  0.0 | 0.0  1.0  0.0  0.0 |
| 0.0  0.0  0.5  1.0 | 0.0  0.0  0.5  1.0 |
| 0.0  0.0  2.0  0.0 | 0.0  0.0  1.0  0.0 |

Right-handed orthographic
      ( 1.0, 3.0, 1.0, 3.0, 1.0, 3.0 )
        Mathfu              DirectX9
| 1.0  0.0  0.0  0.0 | 1.0  0.0  0.0  0.0 |
| 0.0  1.0  0.0  0.0 | 0.0  1.0  0.0  0.0 |
| 0.0  0.0 -1.0  0.0 | 0.0  0.0 -0.5  0.0 |
|-2.0 -2.0 -2.0  1.0 |-2.0 -2.0 -0.5  1.0 |

Left-handed orthographic
      ( 1.0, 3.0, 1.0, 3.0, 1.0, 3.0 )
        Mathfu              DirectX9
| 1.0  0.0  0.0  0.0 | 1.0  0.0  0.0  0.0 |
| 0.0  1.0  0.0  0.0 | 0.0  1.0  0.0  0.0 |
| 0.0  0.0  1.0  0.0 | 0.0  0.0  0.5  0.0 |
|-2.0 -2.0 -2.0  1.0 |-2.0 -2.0 -0.5  1.0 |

This moment is crucial in cross-platform development perspective. In fact, the DirectX math library is good enough for using it on Windows desktop systems. But for portability purposes we need another math library. And Mathfu looks good enough to use it on other systems.

But that difference mixes the cards. Does the different calculations makes the real difference in results?

Expose GetColumn in Matrix

GetColumn is a very useful operation on matrices, and it is supported in matrix.h, but it is marked as MATHFU_INTERNAL.

Just wondering if it can be exposed to public.

Including quaternion.h after including vector.h can cause template errors

If you include quaternion.h after including vector.h and instantiating a Vector<float, 3>, you get template errors.

Here's a small example to illustrate this happening.

myheader.h

#pragma once

#include <mathfu/vector.h>

struct MyStruct {
    mathfu::Vector<float, 3> myVec;
};

main.cpp

#include "myheader.h"
#include <mathfu/quaternion.h>

int main() {
    return 0;
}

Trying to compile main.cpp with g++ will result in these errors:

$ g++ -I./include main.cpp 
In file included from ./include/mathfu/matrix.h:22:0,
                 from ./include/mathfu/quaternion.h:25,
                 from main.cpp:2:
./include/mathfu/vector_3.h:66:7: error: specialization of ‘mathfu::Vector<float, 3>’ after instantiation
 class Vector<float, 3> {
       ^
./include/mathfu/vector_3.h:66:7: error: redefinition of ‘class mathfu::Vector<float, 3>’
In file included from myheader.h:3:0,
                 from main.cpp:1:
./include/mathfu/vector.h:151:7: error: previous definition of ‘class mathfu::Vector<float, 3>’
 class Vector {
       ^
./include/mathfu/vector.h: In constructor ‘mathfu::Vector<float, 4>::Vector(const mathfu::Vector<float, 3>&, const float&)’:
./include/mathfu/vector.h:679:12: error: ‘float mathfu::Vector<float, 3>::data_ [3]’ is private
   T data_[d];
            ^
In file included from ./include/mathfu/matrix.h:23:0,
                 from ./include/mathfu/quaternion.h:25,
                 from main.cpp:2:
./include/mathfu/vector_4.h:73:26: error: within this context
     data_.simd = vector3.data_.simd;
                          ^
./include/mathfu/vector_4.h:73:32: error: request for member ‘simd’ in ‘vector3.mathfu::Vector<float, 3>::data_’, which is of non-class type ‘const float [3]’
     data_.simd = vector3.data_.simd;

[Feature Request] - Accessors

Hi dear mathfu contributors !

I'm happy to use mathfu for hobby project, It works like a charm.

Me and my teammates would request that mathfu Vector.x() and similar operations should work without parenthesis.

So in the current state of mathfu:
vec.x() = 5;
something = vec.x();

What we would like to make mathfu better
vec.x = 5;
something = vec.x;

I didn't looked at the source code, so if you really need to call functions when accessing x, there are several methods to make C# like property accesses for those, with ZERO overhead.

Please take this request seriously, keep up the good work though :)

Bug on Quaternion::LookAt()

use default handedness: LH
testcase:


Vector<float, 3> dir(0.615524292f,0,-1.49077988f);
dir.Normalize();

Vector<float, 3> up(0,1,0);
Quaternion<float> q = Quaternion<float>::LookAt(dir, up);

output q, the result is wrong:
q = (-0.194535, 0.000000, 0.980896, 0.000000);

right answer should be:
q = (0.194535, 0.000000, 0.980896, 0.000000);

Doesn't support iOS

Is iOS support planned? If not, would you accept a PR adding iOS support?

CMake gives error > Does work, didn't use --recursive when cloning

Update: it's working, I didn't use the --recursive flag when cloning. I'll leave this message if other people don't read the readme :)

Trying to compile current master on Mac 10.10, gives:

cmake -DCMAKE_INSTALL_PREFIX=${PWD}/installed -DCMAKE_BUILD_TYPE=Release .

Gives:

CMake Error at unit_tests/CMakeLists.txt:16 (add_subdirectory):
  The source directory path/to/dir
  does not contain a CMakeLists.txt file.

SIMD detection doesn't work on MSVC x64 targets

The checks in mathfu/utilities.h to enable MATHFU_COMPILE_WITH_SIMD don't cover Visual Studio x64 targets. The code currently checks the existence (and value) of _M_IX86_FP, which is only defined for x86 (32-bit) targets. SSE and SSE2 support is implicit on x64 targets, which can be handled with the following addition (or similar):

#elif defined(_M_IX86_FP)
#if _M_IX86_FP >= 1        // SSE enabled
#define MATHFU_COMPILE_WITH_SIMD
#endif  // _M_IX86_FP >= 1
+ #elif (defined(_M_AMD64) || defined(_M_X64))
+ #define MATHFU_COMPILE_WITH_SIMD // MSVC targeting X64 implies SSE+SSE2
#endif
#endif  // !defined(MATHFU_COMPILE_WITHOUT_SIMD_SUPPORT)

Remove "vectorial" lib external dependency?

One of the good things about header-only libraries is that it can be trivially included in a project regardless of its build system (Visual Studio, cmake, make, ...). But having external dependencies can cause frustration for many people who just wanted an easy-to-include math library (Not everyone uses CMake.... Especially considering that a lot of the people in graphics / game development use Visual Studio)

It might be beneficial to move only the needed headers in the "vectorial" library inside the include folder to reduce this bloat. Or if having updateable submodules is still worth the bloat, then we can just do this only in the release distribution. (But as the external library isn't currently updated for about 3 years, I think it is safe to say that it wouldn't change over time.)

Perspective projection matrix (what device coordinates is it mapping to?)

Hi,

So I was looking to implement a simple frustum test when I realized I wasn't sure what device coordinates the mathfu perspective matrix was mapping to (most importantly in the Z axis as it differs between different graphics APIs).

Just out of curiosity, I looked at the implementation and attempted to map "z=-near" with a right hand matrix. After simplifying the equation I ended up with it being mapped to "f/(n-f)"? This isn't a normalized device coordinate and is especially problematic the larger n is.

I verified that it was indeed doing this (simply plug near = 1 and far = 3 or something to that effect into the perspective matrix function and multiply with (0, 0, -1, 1) and you'll see that the resulting (perspective divided) z coordinate is -1.5).

Just to be sure there wasn't some trickery going on in the view matrix, I also attempted the same test but in world space (using the view projection matrix) and got the same result.

I've traced it back to this line: "zfar_per_zdist * handedness, -1 * handedness, 0, 0," in PerspectiveHelper which conventionally (following how perspective matrices are typically calculated for OpenGL) would have been (n + f)/(n - f) instead of just f/(n - f), which would then map -n unto -1, the min z device coordinate for OpenGL. I haven't really done the math to figure out if that made sense in a left handed system (i.e. mapping n unto -1), but I figured I'd check here first.

Is this intentional?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.