Giter Club home page Giter Club logo

mmath's Introduction

MMath

Last updated: Apr 11th, 2021

As mentioned in the description, this is my highly-optimized, C99 header-only/matrix vector math library, fully compatible with OpenGL / GLSL 3+ (I personally use 4.5).

Reasons for writing my own library (when plenty out there already exist):

1. Support for C

GLM is one of the more commonly used libraries (which I will focus on here), is also header-only, but it is only compatible with C++. One of the most confusing things I faced when first learning OpenGL was the fact that I never saw a single tutorial/guide/reference that covered OpenGL using C, despite the fact that it's a C API. The reason for this, as I have come to learn, is that almost all of these resources use GLM as their vector/matrix math library, which immediately forces you to use C++ whether you like it or not. It also doesn't help that GLM, reasonably so, uses C++ features, ie, classes, namespaces, operator/function overloading, and templates (ESPECIALLY templates - I'll get to these later). As a result, you really don't have a choice when it comes to what language to use if you choose to use GLM. Now of course you can always just opt to write C-style C++, but the limitation on what language you have to use is still present.

2. Size / simplicity

GLM is a VERY big library (over 400 files!) because it supports numerous mathematical constructs, such as complex numbers and quaternions. Many of these constructs aren't required in my case, so it's a waste of space having to include them all in my project. Furthermore, many of these files are either i) empty ii) filled with blank declarations iii) just more #includes. This results in increased compile times, a polluted console output, and an unneccessary amount of bloat in my projects, which I'd like to minimize as much as possible. By comparison, my library is only ~500 lines and only supports what I need (vec2, vec3, mat4, utility funcs). Yes, of course this makes it a less powerful library, but the key point here is simplicity and ease of expansion when necessary. I also don't really like the syntax/naming schemes that GLM uses for its functions.

3. GLM's complexity and template abuse

These two points tie together so I will address them as one. Simply put, GLM has some of the ugliest C++ template abuse I've ever seen, and I encourage anyone reading this to open up the GLM source code and just have a read through the code. This makes the code unnecessarily bloated in my case since I only using floats for my vectors/matrices. That being said, there are cases in which it's more ideal/efficient to have vectors/matrices that use ints instead of floats, but I have yet to ever find myself in such a position.

Now, there is another library called CGLM that addresses many of the issues I've outlined above: it's written in C, it's much smaller and conciser, and it's easier to understand. However, there is still additional, unneccessary overhead in my opinion, and it supports a lot more mathematical constructs that I don't need. But regardless of these improvements that CGLM makes, it will NEVER change the final reason I have below.

4. Do it yourself

I like writing C code, and I find enjoyment in developing my own libraries/tools/utilities etc. Writing my own library means I have full control over it, so I can optimize it as I see fit, and I can design it the way I want (ie. syntax/naming conventions that I mentioned earlier). It's been a very rewarding experience so far and it's taught me a lot about how to develop my own libraries. It's also nice having something that I can easily integrate into future projects, as well as the understanding all the code that I write/use.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.