Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: SFML Maths & Iterators utility  (Read 6505 times)

0 Members and 1 Guest are viewing this topic.

Xiaohu

  • Newbie
  • *
  • Posts: 6
    • View Profile
SFML Maths & Iterators utility
« 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

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 ^^
« Last Edit: April 22, 2021, 06:06:54 pm by Xiaohu »

pvigier

  • Newbie
  • *
  • Posts: 17
    • View Profile
    • pvigier's blog
Re: SFML Maths & Iterators utility
« Reply #1 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:
  • Upload your code to a GitHub repo, it will be easier to share it with fellow developers.
  • Use a clear license for your code such as MIT license.
  • You can use constexpr keyword at various places in your code
  • Do not use names that start with "__" it is reserved for compiler implementers.
  • Instead of using an array to store homogeneous member types you can use a tuple to store heterogeneous member types. It is not useful for Vector2, Vector3 and Color types but it may allow you to use these templates with more types.

Keep up the good work!

Xiaohu

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: SFML Maths & Iterators utility
« Reply #2 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.

 

anything