MathLib

MathLib

The code is hosted here

A simple, header-only C++20 math library with utilities primarily for computer graphics and gamedev.

Example

#include <Math/Vector.hpp>
#include <Math/Matrix.hpp>

int main()
{
    // All values initialized to 4.0f
    Math::Vector3f v1(4.0f);

    // Explicit initialization of all values
    Math::Vector3f v2(1.0f, 2.0f, 3.0f);

    // Arithmetic operations are supported
    Math::Vector3f v3 = v1 + v2;

    // Initializes the diagonal to 1.0f
    Math::Matrix3f m1(1.0f);

    // Explicit initialization of all values
    Math::Matrix3f m2(
        1.0f, 2.0f, 3.0f,
        4.0f, 5.0f, 6.0f,
        7.0f, 8.0f, 9.0f
    );

    // One of the supported arithmetic operations
    Math::Matrix3f m3 = m1 * m2;

    Math::Vector3f v4 = m3 * v3; // Preferred
    Math::Vector3f v5 = v3 * m3; // Also possible

    // f32 is a custom wrapper for floats,
    // use ToUnderlying(cosAngle) to convert to float.
    // Many other utilities are also present.
    Math::f32 cosAngle = Dot(v4, v5);
}

Usage

You can include the library either by downloading it and putting the Include directory into your project's include path or by using CMake's FetchContent module.

if(NOT TARGET MathLib)
    include(FetchContent)

    FetchContent_Declare(
        MathLib
        GIT_REPOSITORY https://github.com/3O11/MathLib
    #   GIT_TAG        vX.X.X # - This will be relevant then there are actual releases
    )

    FetchContent_MakeAvailable(
        MathLib
    )
endif()