What is static_cast used for, it's a type of conversion from what I understand but what difference does it do to using ( sf::Vector2f ), or does that not work?
static_cast is the preferred way of casting, go read
this stackoverflow answer on the differences.
I can't see anything wrong with just using the vector's constructor here:
I had forgotten about the
conversion constructor, hence the explicit cast.
is 2u supposed to be something specific or just half the window size?
Yes, just half the window size. The 'u' on the end explicitly makes the value an unsigned integer.
I did this because sf::Window::getSize() returns a sf::Vector2
u, an unsigned integer vector, not a float vector.
From what I understand constexpr is like const used for objects and functions, does it have purpose for a simple data type?
Eh, I just like using it when I can, since it's sure to enforce compile-time constants, rather than possible run-time constants.
This captures the position of the mouse as the mousebutton is pressed and doesn't update right?
Correct, that will only update when a mouse button was pressed or released. I made the assumption that most projectiles don't change direction much after being fired.
As for using CENTER as a whole, what does it do?
I just used the center of the window as the starting point for the projectiles. You could just replace this with the position of your player or whatnot as needed, it will work the same. Though, if your player ends up changing position, that could pose an issue. So you'd have to store the starting point of the projectile. Or:
line[0].position += -unitVec(line[0].position - line[1].position) * VELOCITY * dt.asSeconds();
line[1].position += unitVec(line[1].position - line[0].position) * VELOCITY * dt.asSeconds();
This way, the projectile will just reuse it's current direction to calculate its movement. Don't forget the negative in front of the first "unitVec",
line[0].position - line[1].position will be the opposite direction of the movement, so you have to negate the result to get the opposite of the opposite. Hehe.
I probably should just read up a lot more til I understand, but vectors, are they just positions for dots right, with x, y , z, etc and the normal is the product of two or more vectors, or does vectors always have a magnitude / normal include together with the position?
Sort of, yes. I like to think of them as: "a displacement from the origin". And oh, wow. My bad. I name the function "vecNormal" when it should have been named "unitVec" or something. (I'll edit that in)
So, the unit vector of a vector, is itself divided by its magnitude.