MATHC - a pure C math library for 2D and 3D programming

MATHC - a pure C math library for 2D and 3D programming

Postby ferreiradaselva » 10 Oct 2017, 22:14

Hello, everyone!

As I was working on my game development framework, I decided to decouple my math sources into a library itself.

It's an alternative to GLM (C++ library) and more complete than linmath.h (another C library).

It's licensed under ZLIB :zlib:

Github: https://github.com/ferreiradaselva/mathc
User avatar
ferreiradaselva
 
Posts: 18
Joined: 10 Oct 2017, 14:18
Location: The Tropics

Re: MATHC - a pure C math library for 2D and 3D programming

Postby Lyberta » 12 Oct 2017, 19:30

Deleted.
Last edited by Lyberta on 01 Oct 2021, 10:10, edited 1 time in total.
Lyberta
 
Posts: 765
Joined: 19 Jun 2013, 10:45

Re: MATHC - a pure C math library for 2D and 3D programming

Postby ferreiradaselva » 13 Oct 2017, 04:35

> It's strange that you use vec for both 2d and 3d, seems wasteful.

It's actually very common to use a single structure to represent all the type of vectors. Using the same structures for all kind of vectors allow more flexibility with OpenGL operations. For example, if you are making a 2D game, you will often use the functions vector2_*(), but you still have the Z component to use to specify depth.

> It would also be great if you rewrote it in C++ and templates

I don't have intentions to support C++. There's already a complete math library for C++ (https://github.com/g-truc/glm). Afik, this library I made is the most complete there is for C.

> so people could use double instead of float.

Is there any specific reason for the need of doubles? Physics can run nicely with float (e.g. Chipmunk2D) and everything sent to the rendering pipeline will be converted to float, anyway.
User avatar
ferreiradaselva
 
Posts: 18
Joined: 10 Oct 2017, 14:18
Location: The Tropics

Re: MATHC - a pure C math library for 2D and 3D programming

Postby imaZighen » 13 Oct 2017, 19:23

This is remarkable, If it was in c++ I wouldn't use it btw, this library gave me a lot of help, thanks mate!
ⵉⵎⴰⵣⵉⵖⴻⵏ / imaZighen
User avatar
imaZighen
 
Posts: 8
Joined: 13 Oct 2017, 18:31
Location: Thamzgha / North Africa

Re: MATHC - a pure C math library for 2D and 3D programming

Postby Lyberta » 14 Oct 2017, 00:28

Deleted.
Last edited by Lyberta on 01 Oct 2021, 10:10, edited 1 time in total.
Lyberta
 
Posts: 765
Joined: 19 Jun 2013, 10:45

Re: MATHC - a pure C math library for 2D and 3D programming

Postby imaZighen » 14 Oct 2017, 14:13

By the way, most of the game engines uses floating point arithmetic, mainly increasing performances, including my own physics engine, Chipmunk and many other alternatives, and they do work very fine and reliable, as for doubles, it could cause issues in performances is many hardware, and mostly used for real life simulations, which isn't the case in games for that precision to be needed.
ⵉⵎⴰⵣⵉⵖⴻⵏ / imaZighen
User avatar
imaZighen
 
Posts: 8
Joined: 13 Oct 2017, 18:31
Location: Thamzgha / North Africa

Re: MATHC - a pure C math library for 2D and 3D programming

Postby ferreiradaselva » 14 Oct 2017, 17:52

imaZighen {l Wrote}:This is remarkable, If it was in c++ I wouldn't use it btw, this library gave me a lot of help, thanks mate!

:D

Lyberta {l Wrote}:Float tends to have a very small precision when you start working with larger numbers.


For the reason @imaZighen mentioned, double isn't that suitable for games (the only thing I can think where it's really useful is for time precision). As for the imprecision of large numbers, it's actually a good practice to divide the world in chunks and translate the objects back to the chunk [0.0f, 0.0f, 0.0f]. For example, if the nearest object to the origin is [600.0f, 500.0f, 300.0f], translate everything with [-600.0f, -500.0f, -300.0f]. And use scale whenever you can, instead of large numbers.

If you were using double, your physics would work correctly with lager numbers, but the rendering still would shake, as the double values would be converted to float.
Last edited by ferreiradaselva on 15 Oct 2017, 17:40, edited 1 time in total.
User avatar
ferreiradaselva
 
Posts: 18
Joined: 10 Oct 2017, 14:18
Location: The Tropics

Re: MATHC - a pure C math library for 2D and 3D programming

Postby Lyberta » 15 Oct 2017, 15:07

Deleted.
Last edited by Lyberta on 01 Oct 2021, 10:11, edited 1 time in total.
Lyberta
 
Posts: 765
Joined: 19 Jun 2013, 10:45

Re: MATHC - a pure C math library for 2D and 3D programming

Postby imaZighen » 15 Oct 2017, 16:48

We are not saying it's impossible, it's just bloody awful for games. And thought you can have a define for the floats to be changed to doubles, not that hard. Just like Chipmunk 2D and ODE and many others, but whose going to use it, thanks, peace.

@ferriera btw check your mail please, thanks.
ⵉⵎⴰⵣⵉⵖⴻⵏ / imaZighen
User avatar
imaZighen
 
Posts: 8
Joined: 13 Oct 2017, 18:31
Location: Thamzgha / North Africa

Who is online

Users browsing this forum: No registered users and 1 guest