ferreiradaselva
Pengo
12 posts
Biologist (genomics); C programmer; Game development and art as hobbies. 
#13545
MATHC  Pure C math library for 2D and 3D programming 1 year, 9 months ago Edited by Pengo on Nov. 19, 2017, 9:57 a.m.
As I was working on my own game framework, I decided to decouple the math source on its own library:
GitHub link Documentation: https://github.com/ferreiradaselva/mathc/blob/master/REFERENCE.md This is mainly for OpenGL. Features
Planned Features Currently the library reached the first major release, but I'm adding features that don't break compatibility, and suggestions for features that break compatibility are welcome, saved for the next major release (2.0.0). The next feature I'm planning is detection for 2D and 3D primitives (circles, lines and triangles, both 2D and 3D). Pointers vs. Values There are two versions of the same function, one that take pointer arguments and other that take value arguments:
Other examples in the GitHub page. Taking pointers is certainly faster, but you can use the function that take values if performance is not critical for you, as they are more readable. Single Vector Structure There's only one vector structure, used for 2D vectors, 3D vectors and quaternions. When I had to use 2D vectors, sometimes I would want to use them as 3D vectors and viceversa. So I decided to use the same structure to make this possible. Easing Functions The easing functions are great for animations: it makes easier to make smooth and organic motions. Why another math library? This is not intended to be a competitor with other math libraries, but a small and simple alternative. 
ratchetfreak
461 posts

#13547
MATHC  Pure C math library for 2D and 3D programming 1 year, 9 months ago
A few comments about the quaternion part:
The null quaternion is 0,0,0,1 instead of all 0. There is no construction function for that. The way to get the shortest rotation between 2 vectors can be faster if you skip the acos into sincos by doing:
Your quat to matrix codes expects normalized quaternions, if you replace the 1.0f with the length squared or divide the xx, yy, zz, etd. with that you can fix that. 
ferreiradaselva
Pengo
12 posts
Biologist (genomics); C programmer; Game development and art as hobbies. 
#13548
MATHC  Pure C math library for 2D and 3D programming 1 year, 9 months ago ratchetfreak Thanks for those inputs (and the ones on GitHub)! I will work on the fix for that :) 
ratchetfreak
461 posts

#13549
MATHC  Pure C math library for 2D and 3D programming 1 year, 9 months ago
one more comment, the reason most slerp implementations use 0.95 as the cutoff for switching to normalized lerp. Is because there is a pole of inaccuracy when the input of acos nears 1 and less bits have useful information.
I've derived that using the normalized lerp to 0.5 is the exact same as the slerp to 0.5. So you can binary search into that for up to 5 iterations and then lerp to finish off. The 5 is based on how quickly the 2 boundaries converge from nearly opposite (dot~1) to above the traditional cutoff (dot~0.95). 
mmozeiko
Mārtiņš Možeiko
1965 posts
/ 1 project

#13555
MATHC  Pure C math library for 2D and 3D programming 1 year, 9 months ago
I don't think this is link to what you want: http://reference.md/

raysan5
Ray
49 posts
/ 1 project
I love videogames development. 
#13570
MATHC  Pure C math library for 2D and 3D programming 1 year, 9 months ago 
ferreiradaselva
Pengo
12 posts
Biologist (genomics); C programmer; Game development and art as hobbies. 
#13575
MATHC  Pure C math library for 2D and 3D programming 1 year, 9 months ago ratchetfreak And I thought that was something arbitrary! :P Thanks for the info, I fixed that. mmozeiko Fixed. raysan5 Thanks! I will make some comparisons, indeed 😄 raysan5 We both used the same reference 😄 I'm really thinking about expanding that list of easing functions. I currently use some of the functions in a game I'm making and they are great to add some juicyness to the game! 
ferreiradaselva
Pengo
12 posts
Biologist (genomics); C programmer; Game development and art as hobbies. 
#13576
MATHC  Pure C math library for 2D and 3D programming 1 year, 9 months ago
UPDATE
Added some functions to test if a pointer is inside or outside a circle or triangle:
I will soon add some functions to test circlecircle, circletriangle, triangletriangle intersection both 2D and 3D (sphere in the case of 3D). That's how far I will go with intersections, because I want to provide only test with primitives. 
ferreiradaselva
Pengo
12 posts
Biologist (genomics); C programmer; Game development and art as hobbies. 
#15378
MATHC  Pure C math library for 2D and 3D programming 1 year, 2 months ago Edited by Pengo on May 24, 2018, 5:41 a.m.
I'm working on the second version of my library, if anyone is in need of a math library.
Github branch: https://github.com/ferreiradaselva/mathc/tree/mathc2 The updates are:
I covered almost all feedback that I got around, except for fixedpoint arithmetic. I probably will never add to the library, since it would escalate the maintenance requirements drastically. 
ferreiradaselva
Pengo
12 posts
Biologist (genomics); C programmer; Game development and art as hobbies. 
#15934
MATHC  Pure C math library for 2D and 3D programming 1 year ago Edited by Pengo on Aug. 6, 2018, 5:45 p.m.
Newer version out!
Github repo  Added integer vectors.  Function names more consistent.  Much, much more configurable, and you can change the type of `mfloat_t` and `mint_t`, which was something requested a lot.  That same scheme still exists: there are functions for working with arrays, structures or pointer to structures. You choose according with your preference.  The library now uses calendar versioning (CalVer). What isn't in:  I dropped the `euler` type, as working with matrices can give the same result and is better to maintain, since there are many euler conventions.  Dropped test unit. A burden to maintain as a solo developer.  No fixedpoint for representing real numbers. Another burden to maintain as a solo developer. (I have to prioritize my mental health :p) 