All Projects → dangmoody → HLML

dangmoody / HLML

Licence: other
Auto-generated maths library for C and C++ based on HLSL/Cg

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to HLML

hlml
vectorized high-level math library
Stars: ✭ 42 (+82.61%)
Mutual labels:  math, sse, simd, hlsl
Xsimd
C++ wrappers for SIMD intrinsics and parallelized, optimized mathematical functions (SSE, AVX, NEON, AVX512)
Stars: ✭ 964 (+4091.3%)
Mutual labels:  sse, simd, vectorization
Boost.simd
Boost SIMD
Stars: ✭ 238 (+934.78%)
Mutual labels:  sse, simd, vectorization
SCNMathExtensions
Math extensions for SCNVector3, SCNQuaternion, SCNMatrix4
Stars: ✭ 32 (+39.13%)
Mutual labels:  math, simd, math-library
Vc
SIMD Vector Classes for C++
Stars: ✭ 985 (+4182.61%)
Mutual labels:  sse, simd, vectorization
Hlslpp
Math library using hlsl syntax with SSE/NEON support
Stars: ✭ 153 (+565.22%)
Mutual labels:  math, sse, hlsl
Ugm
Ubpa Graphics Mathematics
Stars: ✭ 178 (+673.91%)
Mutual labels:  math, sse, simd
Simde
Implementations of SIMD instruction sets for systems which don't natively support them.
Stars: ✭ 1,012 (+4300%)
Mutual labels:  sse, simd, vectorization
Cglm
📽 Highly Optimized Graphics Math (glm) for C
Stars: ✭ 887 (+3756.52%)
Mutual labels:  math, sse, simd
simd-byte-lookup
SIMDized check which bytes are in a set
Stars: ✭ 23 (+0%)
Mutual labels:  sse, simd
pyGameMath
Math library for game programming in python.
Stars: ✭ 20 (-13.04%)
Mutual labels:  math, math-library
zig-gamedev
Building game development ecosystem for @ziglang!
Stars: ✭ 1,059 (+4504.35%)
Mutual labels:  math, simd
Oscar.jl
A comprehensive open source computer algebra system for computations in algebra, geometry, and number theory.
Stars: ✭ 182 (+691.3%)
Mutual labels:  math, maths
abacus
📐 C# cross precision 3D maths library.
Stars: ✭ 35 (+52.17%)
Mutual labels:  math, maths
Guided Missile Simulation
Guided Missile, Radar and Infrared EOS Simulation Framework written in Fortran.
Stars: ✭ 33 (+43.48%)
Mutual labels:  simd, vectorization
Mango
mango fun framework
Stars: ✭ 343 (+1391.3%)
Mutual labels:  math, simd
Mipp
MIPP is a portable wrapper for SIMD instructions written in C++11. It supports NEON, SSE, AVX and AVX-512.
Stars: ✭ 253 (+1000%)
Mutual labels:  sse, simd
finmath
The collections of simple, weighted, exponential, smoothed moving averages.
Stars: ✭ 49 (+113.04%)
Mutual labels:  math, math-library
Rtm
Realtime Math
Stars: ✭ 373 (+1521.74%)
Mutual labels:  math, simd
Thermite
Thermite SIMD: Melt your CPU
Stars: ✭ 141 (+513.04%)
Mutual labels:  math, simd

HLML

(High Level Maths Library).

CI

HLML is a maths library for C and C++ focused on games/graphics programming which is loosely styled on HLSL syntax where all vector/matrix types are generated by a tool. This means that there are zero templates in the generated code, which gives the following advantages:

  • Shorter compile times.
  • Easier to read and debug.
  • Ability to forward declare types.

As well as the above, HLML also offers the following:

  • SIMD maths functions (functionality is experimental and still potentially subject to change).
  • Non-uniform matrix types.
  • Boolean vectors/matrices to aid equality checking of vector types.

Currently HLML is written to produce optimised assembly for Clang. If you use another compiler then YMMV.

HLML does not override any maths functions that are a part of C99.

See the "Licenses" section below for details about what licenses HLML uses.

Installation

  1. Go to the releases page and download the latest version.
  2. Unzip the header files into your project (you can use either the C or C++ files, NOT both).

Usage

Include hlml.h.

For more detailed documentation on how to use HLML's experimental SSE functionality, please refer to the SSE document.

Code Examples

C:

Adding 2 vectors:

float3 a = { 1.0f, 2.0f, 3.0f };
float3 b = { 4.0f, 5.0f, 6.0f };

// the "c" part means "component-wise"
// the "v" part means vector
// there are also component-wise arithmetic functions for scalar ("s"), and matrix ("m" - for matrix types only)
float3 c = float3_caddv( &a, &b );

printf( "c is: (%f, %f, %f)", c.x, c.y, c.z );

Creating a Model-View-Projection matrix:

float4x4 model = float4x4_translate( &player_transform, &position );

float4x4 view = float4x4_lookat_lh_zo( &eye, &forward, &world_up );

float4x4 projection = float4x4_perspective_lh_zo( fov, aspect, znear, zfar );

// "float4_mulm" will do matrix multiplication
// "float4_cmulm" will do component-wise multiplication
float4x4 view_projection = float4x4_mulm( &view, &projection );
float4x4 mvp = float4x4_mulm( &model, &view_projection );

C++:

Adding 2 vectors:

float3 a = { 1.0f, 2.0f, 3.0f }; // in C++ you can initialise math types like this
float3 b = float3( 4.0f, 5.0f, 6.0f ); // or like this

float3 c = a + b;

printf( "c is: (%f, %f, %f)", c.x, c.y, c.z );

Creating a Model-View-Projection matrix:

float4x4 model = translate( player_transform, position );

// lh = left handed, zo = zero-to-one depth
// there also exists rh (right-handed) and no (negative-one-to-one) combinations
float4x4 view = lookat_lh_zo( eye, forward, world_up );

float4x4 projection = perspective_lh_zo( fov, aspect, znear, zfar );

// in C++ the multiply operator performs matrix multiplication
// not per-component multiplication
float4x4 view_projection = mul( view, projection );
float4x4 mvp = mul( model, view_projection );

Vector Swizzling (C++ only):

// all possible combinations are automatically generated and available
float4 a = { 1.0f, 2.0f, 3.0f, 4.0f };
float4 b = a.xxyy();

Common Pitfalls

READ THIS BEFORE USING HLML:

  • Matrix types are row-major, so a float3x4 is a matrix that holds 3 float4s (or, in other words: a float4 array of size 3).
  • In C++ vector types are a union of struct/fixed-size array.
  • To avoid conflicts with Windows min/max macros, you can #define NOMINMAX before including HLML.

Contributing

If this is a project you'd like to contribute to then see the contribution document.

Credits

I'd like to extend credit to the following:

  • GLM - I use some of their solutions for a couple of functions, therefore I take no credit for those.
  • Unity.Mathematics - The idea of using a generator comes from this.

Contributors/Bug finders:

I'd also just like to give a special thanks to the following people:

  • Antony Bowler
  • Mike Young
  • Tom Whitcombe

Your help is very much appreciated. Thank you. =)

Motivation

I've always primarily used GLM as my maths library of choice, but there were a few things that always bugged me about it:

  • Sometimes had trouble reading past all of the templates.
  • Often have trouble debugging the templates.
  • Typing the namespace all the time got annoying.
  • Often found it frustrating to navigate the API files as everything is split into lots of little separate headers that weren't obviously named (IMO).

(This isn't an attack on GLM, just some of my personal gripes with it).

One day I stumbled upon the Unity.Mathematics library where I saw that all the maths types were being generated via a tool. I decided to try the same but for C and C++: Write a tool that generated maths types for me to see if there were any benefits of doing it that way, and I found that there were:

  • Compile times were shorter due to lack of templates.
  • Being able to just read plain, vanilla C/C++ code. No templates to read past, just very simple, minimal, and straightforward code.
  • Maintaining changes across multiple (if not all) types was a lot easier than imagined. Write the changes into the generator and watch it reflect the change across all the desired generated types automatically.

Licenses

HLML is dual licensed.

All code that is part of the generator is licensed under GNU GPL v3.

All of the generated code (found in the releases) are licensed under MIT license. Please see the respective license files (found in the root of this project) for details.

HLML's generator also makes use of the following libraries, which are under their own respective licenses:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].