Math 3D - A simple vector and matrix library for C - Arkanis DevelopmentStuff about programming, technology, life… err… how about the universe?http://arkanis.de/weblog.xml2017-09-03T18:26:44+02:00Comment by matheusmatheushttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2017-09-03-18-26-44-matheus2017-09-03T18:26:44+02:00
<p>I've past the past day making a similar library till I realized that even though it's pretty fun to create one, I don't need to. So THANK YOU!</p>
Comment by foobarfoobarhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2017-08-12-01-35-08-foobar2017-08-12T01:35:08+02:00
<p>(Part 2)
My apologies. I was scratching my head and the moment I posted the previous comment - alarm bells started ringing. I was looking at the math_3d.h file and realised I needed to define MATH_3D_IMPLEMENTATION</p>
<p>(Holding my head in shame)</p>
Comment by foobarfoobarhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2017-08-12-01-27-56-foobar2017-08-12T01:27:56+02:00
<p>Hi there.
I am playing about with OpenGL 4 (familiar with OpenGL1-2 series 10 years ago) and I came across this library to help get me started.</p>
<p>I am using C99.</p>
<p>However, I get an undefined symbol error for any m4_* functions. With these single header files, how do I add them into the makefile? I tried variations like treating math_3d.h as a header file as well as a source file, but no luck.</p>
<p>I am using Linux and gcc.</p>
Comment by SegmentedSegmentedhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2017-07-03-16-45-37-segmented2017-07-03T16:45:37+02:00
<p>I have a similar problem with C++; For some reason whenever I use it I end up solving non-problems at the expense of my actual goal. I suspect it is because the language promotes generic, reusable code, which while itself can be a good thing, can also be too much of a good thing. C is down to earth; things like global state which are often held against it actually help to keep the scope of the problem grounded.</p>
Comment by StephanStephanhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2017-03-09-09-13-52-stephan2017-03-09T09:13:52+01:00
<p>Thanks for using and improving the library Sébastien. Especially for sharing your experience and improvements! You can send me a push request on GitHub or send me the new file directly via mail (see 3rd line of the file for my mail address).</p>
<p>Regarding the m4_invert_affine() determinant threshold: Can you send me the matrix that triggered the error so I can reproduce it and put it into the test case? It would also be great if you can send me how you constructed the matrix (what kind of rotations, translations, etc. you used to create it). That way Tobias and I can verify analytically if the function works correctly or not.</p>
<p>While we researched pretty much every other aspect of that function we haven't given the 0.00001 value much thought and it's unfortunate that you ran into a bug because of it. We'll have to do a bit more research to figure out what a proper threshold should be in that case. Or to put it in another way how the determinant looks like when the matrix can't be inverted.</p>
<p>I'm also not very happy that the function returns an identity matrix in that case. Maybe it's best to return a matrix full of NaNs so you at least know that something is broken. What would have helped you to catch the bug more easily?</p>
<p>Regarding the quaternions: We didn't include vec4_t because it makes matrix multiplication more confusing. More specifically the perspective division. But quaternions really do make sense. I haven't used them much but Tobias uses them, too. I'm curious what operations you implemented for them. <span class="smiley smile">:)</span></p>
<p>m4_frustum() sounds useful. Now that you mentioned it… kind of funny I forgot to put it in. <span class="smiley grin">:D</span></p>
Comment by Sébastien Le RouxSébastien Le Rouxhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2017-02-26-14-04-16-sebastien-le-roux2017-02-26T14:04:16+01:00
<p>Hello there,
first of all thanks for this library, that is a great tool indeed !
I write first to let you know that I think that there is an error in your file,
I pointed it in the 'm4_invert_affine(mat4_t matrix)' calculation:
The following condition is not accurate enough:</p>
<pre><code>if (fabsf(det) < 0.00001)
return m4_identity();</code></pre>
<p>You should write instead:</p>
<pre><code>if (fabsf(det) == 0.00000)
return m4_identity();</code></pre>
<p>I actually came up with the error case and I struggled to find out that error was coming from this, and it does.</p>
<p>Also I came up with few improvements of the file, like the 'vec4_t' type (in particular for quaternions), 'm4_quat_rotation (vec4_t q)' for quaternion rotation, 'm4_frustum' … I will be happy to share it with you, but I think this message box is too small for that.
If you are interested just let me know how to contact you.</p>
<p>Best.</p>
Comment by bartekbartekhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2016-12-15-17-30-27-bartek2016-12-15T17:30:27+01:00
<p>Thank you so much - exactly what I was looking for <span class="smiley wink">;)</span></p>
Comment by SkandarSkandarhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2016-07-12-14-16-52-skandar2016-07-12T14:16:52+02:00
<p>You saved me too. I was looking exactly for this a vector math for C. I was using C++ but I got tired of it, As you said just fighting the language instead getting job done.</p>
Comment by StephanStephanhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2016-06-04-12-26-20-stephan2016-06-04T12:26:20+02:00
<p>Thanks for the comment. It's always good to know that the work is useful to someone else, too. <span class="smiley smile">:)</span></p>
<p>Have a good time with the library and don't hessitate to let me know if something isn't like you expect it to be.</p>
Comment by PatrickPatrickhttp://arkanis.de/weblog/2016-02-16-math-3d-a-simple-vector-and-matrix-library-for-c#comment-2016-05-23-16-31-43-patrick2016-05-23T16:31:43+02:00
<p>oh man, you saved my life. there are, as you already said, only overly complex and overloaded c math libraries around. I have been searching for something like your for quite some time. c ist also my favorite, but not very popular around other devs, as it seems. thank your very much, that lib will be part of my routine as soon as I am finished writing this comment.
really great work <span class="smiley smile">:)</span></p>