MathFu
An open source project by
FPL.
|
MathFu is designed as a C++ header only library to simplify the process of including the library in projects. MathFu provides the following options for using it in a project:
Before diving into using MathFu in your project, we recommend you spend some time building and running the unit tests for each platform you wish to target by working through the following sections:
The following directories need to be added to the include paths of a project to build the default configuration:
mathfu/include
vectorial/include
In addition, to compile with SIMD enabled an architecture specific flag must be specified:
Architecture | Compiler | Flag |
---|---|---|
x86 | Android GCC / Clang | -msse |
x86_64 | Android GCC / Clang | -msse4.1 |
x86 | GCC / Clang | -msse4.1 |
ARM | GCC / Clang | -mfpu=neon |
x86 | Visual Studio | /arch:SSE2 |
For example, to compile the following file test.cpp
against MathFu with gcc for x86:
requires the following command line (assuming vectorial is in the mathfu/dependencies
directory):
In addition, MathFu provides a set of build configuration options that are controlled using preprocessor symbols described by Build Configuration.
MathFu uses a CMake project to build unit tests and benchmarks for Linux, OS X and Windows.
CMake is used to generate a platform projects for each target platform:
If you're not familiar with CMake, see the following sections to learn how to build on each platform:
In addition to building the MathFu unit tests and benchmarks, the MathFu CMake project can be used in developers own projects by:
mathfu_build_benchmarks
mathfu_build_tests
mathfu_configure_flags
function to add the appropriate include directories and compiler flags for the project.For example, in a CMakeLists.txt project file which contains the executable mygame
:
MathFu build options (see Build Configuration) can be configured with the mathfu_configure_flags
function using the optional arguments enable_simd
and force_padding
. For example:
Function Call | Build Configuration |
---|---|
mathfu_configure_flags(mygame) | Default, SIMD & padding enabled. |
mathfu_configure_flags(mygame TRUE FALSE) | SIMD enabled & padding disabled. |
mathfu_configure_flags(mygame FALSE) | SIMD disabled. |
See the function comment in the CMakeLists.txt file for more information.
If you're not familiar developing applications with the Android NDK, see Building for Android first.
To use MathFu with an Android NDK makefile project, add the following lines to your project's Android.mk
file.
MathFu build options (see Build Configuration) can be configured by linking against the different static libraries the MathFu project builds:
Library | Build Configuration |
---|---|
libmathfu | Default configuration, SIMD and padding enabled. |
libmathfu_no_padding | SIMD enabled (if supported), padding disabled. |
libmathfu_no_simd | SIMD disabled, padding disabled. |