In C++, is there a Vector2 class and if so, what do I need to include to use it?
I want to use this to store 2-dimensional vectors such as position or velocity of a particle.
Here you go.
struct Vector2
{
float x;
float y;
};
Or alternatively you can use std::pair<float, float>
.
Then you'll want to learn more about Structure Of Arrays (SOA) vs Arrays of Structures (AOS) and how it impacts the performance of your code.
Particle systems would typically go SOA.
Finally here is a series of blog posts on AOS & SOA applied to the implementation of a particle system.
EDIT: there are nice math libraries out there like Eigen or glm that would define such types for you along with many useful algorithms (with performant implementations).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With