Skip to content

Spheya/StarMath

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⭐ StarMath ⭐

StarMath is a fast single-header C++ math library build for game development and real-time graphics.

✨ Little Star Math

There are two versions of the library: starmath.hpp and littlestarmath.hpp. starmath.hpp is a feature rich version of the library, which includes component-wise math functions and usage of bitwise and boolean operators on vectors. While littlestarmath.hpp is a smaller version of the library, providing only basic maths functions and operators.

✨ Supported Types

Currently the library implements vec2, vec3, vec4, mat2, mat3, and mat4. With future plans for quaternions. By default, floats will be used, but you can prefix the type names with i to use integers, u to use unsigned integers, b for booleans, etc. (like this: ivec2, uvec2, bvec2).

✨ How to Use

For setup: take either starmath.hpp or littlestarmath.hpp and include it into your project.

Every type and function in the library is in the star namespace. The naming conventions and usage of the library should be very similar to GLSL. Below is a little code sample showing what the basic syntax looks like.

#include <stdio.h>

#define STAR_USE_INTRINSICS // Make use of compiler intrinsics (may not work on all compilers/platforms)
#include "starmath.hpp"

int main() {
    star::vec3 a(1.0f, 1.0f, 1.0f);

    star::mat4 b(
        1.0f, 0.0f, 0.0f, 0.0f, // Column 0
        0.0f, 2.0f, 0.0f, 0.0f, // Column 1
        0.0f, 0.0f, 1.0f, 0.0f, // Column 2
        8.0f, 4.0f, 0.0f, 1.0f, // Column 3
    );

    // Basic maths functions
    star::vec3 c = b * star::vec4(a, 1.0f);
    star::vec3 d = star::normalize(c);

    // Using star::min component-wise on a vec3 is only supported in StarMath, not in LittleStarMath
    star::vec3 e = star::min(c, star::vec3(10.0f, 8.0f, -3.0f));

    printf("c = [%f, %f, %f]", c.x, c.y, c.z);
    printf("d = [%f, %f, %f]", d.x, d.y, d.z);
    printf("e = [%f, %f, %f]", e.x, e.y, e.z);
}

About

A tiny maths library

Resources

License

Stars

Watchers

Forks

Packages

No packages published