SFML community forums

General => SFML projects => Topic started by: Xiaohu on October 28, 2019, 01:20:36 am

Title: SFML Maths & Iterators utility
Post by: Xiaohu on October 28, 2019, 01:20:36 am
[Update] Github link: https://github.com/Eren121/SFML-Math
Previous download link https://www.dropbox.com/s/tp0w90qd1mj0ul1/SFMLMath.zip?dl=0 (https://www.dropbox.com/s/tp0w90qd1mj0ul1/SFMLMath.zip?dl=0)

Hello all!

To debug and avoid repeated stuff, Ii coded a tiny header only lib in C++11.
It add basic math stuff and printable Vectors and Color of the form (X, Y [, Z] ) or (R, G, B, A) to debug better :)

And Vectors/Colors are now... iterables!

Sample :

#include <SFML/Math.h>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    sf::Vector3f myVec3(1, 1, 0);
    sf::Vector2f myVec2(1, 1);

    cout << myVec2 << endl;
    cout << length(myVec2) << ", " << length(myVec3) << endl;
    cout << length2(myVec2) << endl;
    cout << distance({1, 2}, myVec2) << endl;
    cout << dot(myVec3, {0, 0, 1}) << endl;

    for(float & f : myVec2) {
        f += 1;
    }

    cout << myVec2 << endl;

    return 0;
}
 

Output :

Code: [Select]
(1, 1)
1.41421, 1.41421
2
1
0
(2, 2)



If you have any suggestion ^^
Title: Re: SFML Maths & Iterators utility
Post by: pvigier on November 18, 2019, 11:44:36 am
Hi!

This is nice work! Especially your templates for introspection and iteration. I am using the same kind of techniques for automatic serialization in my game.

I have some suggestions:

Keep up the good work!
Title: Re: SFML Maths & Iterators utility
Post by: Xiaohu on April 22, 2021, 06:06:06 pm
Done!

For simplification, I removed most of the template lookup for a simpler function overload. It is more redondant, but the compilation time may be less long and it's also simpler. I rewrited the code so the iterators utilities are done for the moment (and they are not that useful).

Github link: https://github.com/Eren121/SFML-Math

The functions are for simple use. For most complex use, I recommand GLM.