Convert Figma logo to code with AI

google logomathfu

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

1,396
189
1,396
24

Top Related Projects

The C# math library used in Unity providing vector types and math functions with a shader like syntax

9,089

OpenGL Mathematics (GLM)

12,540

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps

20,408

A modern formatting library

Quick Overview

MathFu is a C++ math library developed by Google for use in games and other applications requiring fast vector and matrix operations. It provides optimized implementations of common mathematical operations, supporting various platforms and SIMD instruction sets.

Pros

  • Highly optimized for performance, utilizing SIMD instructions where available
  • Cross-platform support, including mobile devices
  • Comprehensive set of vector and matrix operations
  • Designed with game development in mind

Cons

  • Limited documentation and examples
  • Not actively maintained (last commit was in 2020)
  • Steep learning curve for beginners due to template-heavy implementation
  • Lack of higher-level mathematical functions compared to some other libraries

Code Examples

  1. Vector operations:
#include "mathfu/vector.h"

mathfu::Vector<float, 3> v1(1.0f, 2.0f, 3.0f);
mathfu::Vector<float, 3> v2(4.0f, 5.0f, 6.0f);
auto result = v1.CrossProduct(v2);
  1. Matrix operations:
#include "mathfu/matrix.h"

mathfu::Matrix<float, 4, 4> m1 = mathfu::Matrix<float, 4, 4>::Identity();
mathfu::Matrix<float, 4, 4> m2 = mathfu::Matrix<float, 4, 4>::FromScaleVector(
    mathfu::Vector<float, 3>(2.0f, 2.0f, 2.0f));
auto result = m1 * m2;
  1. Quaternion operations:
#include "mathfu/quaternion.h"

mathfu::Quaternion<float> q1 = mathfu::Quaternion<float>::FromEulerAngles(
    mathfu::Vector<float, 3>(0.1f, 0.2f, 0.3f));
mathfu::Quaternion<float> q2 = mathfu::Quaternion<float>::FromAngleAxis(
    0.5f, mathfu::Vector<float, 3>(1.0f, 0.0f, 0.0f));
auto result = q1 * q2;

Getting Started

  1. Clone the repository:

    git clone https://github.com/google/mathfu.git
    
  2. Add the MathFu include directory to your project's include path.

  3. Include the necessary headers in your code:

    #include "mathfu/vector.h"
    #include "mathfu/matrix.h"
    #include "mathfu/quaternion.h"
    
  4. Compile your project with C++11 support or later.

  5. If using SIMD optimizations, make sure to enable the appropriate compiler flags for your target architecture (e.g., -msse4.1 for SSE4.1 on x86).

Competitor Comparisons

The C# math library used in Unity providing vector types and math functions with a shader like syntax

Pros of Unity.Mathematics

  • Designed specifically for Unity, ensuring seamless integration with the game engine
  • Utilizes SIMD intrinsics for improved performance on supported platforms
  • Offers a more comprehensive set of mathematical functions tailored for game development

Cons of Unity.Mathematics

  • Limited to C# and Unity ecosystem, reducing portability to other platforms
  • May have a steeper learning curve for developers not familiar with Unity's conventions

Code Comparison

MathFu (C++):

vec3 result = vec3::CrossProduct(vec1, vec2);
float dot = vec1.DotProduct(vec2);

Unity.Mathematics (C#):

float3 result = math.cross(vec1, vec2);
float dot = math.dot(vec1, vec2);

Both libraries provide similar functionality, but Unity.Mathematics uses a more functional approach with static methods, while MathFu uses object-oriented member functions.

MathFu is written in C++ and focuses on being lightweight and portable, making it suitable for various platforms and projects. Unity.Mathematics, on the other hand, is tailored specifically for Unity development in C#, offering optimizations and features that align closely with Unity's ecosystem.

9,089

OpenGL Mathematics (GLM)

Pros of GLM

  • More comprehensive, supporting a wider range of mathematical operations and types
  • Better documentation and examples
  • Closer adherence to GLSL syntax, making it easier for OpenGL developers

Cons of GLM

  • Larger codebase, potentially leading to longer compile times
  • Header-only library, which may increase build times for large projects
  • Steeper learning curve due to its extensive feature set

Code Comparison

MathFu:

#include "mathfu/vector.h"
using namespace mathfu;
Vector<float, 3> v1(1.0f, 2.0f, 3.0f);
Vector<float, 3> v2(4.0f, 5.0f, 6.0f);
Vector<float, 3> result = v1 + v2;

GLM:

#include <glm/glm.hpp>
glm::vec3 v1(1.0f, 2.0f, 3.0f);
glm::vec3 v2(4.0f, 5.0f, 6.0f);
glm::vec3 result = v1 + v2;

Both libraries provide similar functionality for basic vector operations, but GLM offers a syntax closer to GLSL. MathFu uses templates for vector dimensions, while GLM provides specific types like vec3. GLM's extensive feature set and GLSL-like syntax make it popular among graphics programmers, while MathFu's simplicity and performance focus appeal to game developers and other performance-critical applications.

12,540

Bullet Physics SDK: real-time collision detection and multi-physics simulation for VR, games, visual effects, robotics, machine learning etc.

Pros of Bullet3

  • Comprehensive physics simulation library with advanced features
  • Active development and large community support
  • Extensive documentation and examples

Cons of Bullet3

  • Steeper learning curve due to complexity
  • Larger codebase and potentially higher resource usage
  • May be overkill for simple math operations

Code Comparison

MathFu (Vector3 addition):

Vector<float, 3> a(1, 2, 3);
Vector<float, 3> b(4, 5, 6);
Vector<float, 3> result = a + b;

Bullet3 (Vector3 addition):

btVector3 a(1, 2, 3);
btVector3 b(4, 5, 6);
btVector3 result = a + b;

Summary

MathFu is a lightweight math library focused on game development and computer graphics, while Bullet3 is a full-featured physics engine. MathFu is simpler and more suitable for basic math operations, whereas Bullet3 offers advanced physics simulation capabilities at the cost of increased complexity. The choice between the two depends on the specific requirements of your project, with MathFu being ideal for simple math tasks and Bullet3 better suited for complex physics simulations.

DirectXMath is an all inline SIMD C++ linear algebra library for use in games and graphics apps

Pros of DirectXMath

  • Optimized for DirectX and Windows platforms
  • Extensive documentation and support from Microsoft
  • Wider range of mathematical functions and utilities

Cons of DirectXMath

  • Platform-specific (primarily for Windows)
  • Steeper learning curve due to its comprehensive nature
  • Less portable compared to MathFu

Code Comparison

MathFu:

#include "mathfu/vector.h"
using namespace mathfu;
Vector<float, 3> v1(1.0f, 2.0f, 3.0f);
Vector<float, 3> v2(4.0f, 5.0f, 6.0f);
Vector<float, 3> result = v1 + v2;

DirectXMath:

#include <DirectXMath.h>
using namespace DirectX;
XMVECTOR v1 = XMVectorSet(1.0f, 2.0f, 3.0f, 0.0f);
XMVECTOR v2 = XMVectorSet(4.0f, 5.0f, 6.0f, 0.0f);
XMVECTOR result = XMVectorAdd(v1, v2);

Both libraries provide efficient vector math operations, but MathFu offers a more straightforward syntax with operator overloading. DirectXMath uses SIMD-optimized functions, which may provide better performance on supported hardware but requires explicit function calls for operations.

20,408

A modern formatting library

Pros of fmt

  • More active development with frequent updates and releases
  • Broader functionality, focusing on string formatting and I/O operations
  • Extensive documentation and examples

Cons of fmt

  • Larger codebase and potentially higher memory footprint
  • May have a steeper learning curve for basic usage

Code Comparison

fmt:

#include <fmt/core.h>

std::string result = fmt::format("Hello, {}!", "world");
fmt::print("The answer is {}.", 42);

MathFu:

#include "mathfu/vector.h"

mathfu::Vector<float, 3> vec(1.0f, 2.0f, 3.0f);
float length = vec.Length();

Key Differences

  • MathFu focuses on mathematical operations and linear algebra, while fmt specializes in string formatting and I/O
  • MathFu is tailored for game development and 3D graphics, whereas fmt has broader applications in general-purpose programming
  • fmt offers more flexibility in string manipulation, while MathFu provides optimized math operations

Use Cases

  • Choose MathFu for projects requiring efficient vector and matrix calculations, especially in game development
  • Opt for fmt when working with string formatting, logging, or general I/O operations in C++ applications

Community and Support

  • fmt has a larger community and more frequent updates
  • MathFu, being a Google project, has strong backing but less frequent updates

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

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.