Closed ghost closed 9 years ago
Sounds like a good idea, then we can just use the (Vectorf)_var conversion for SFML parameters.
On Tue, Nov 18, 2014 at 10:48 AM, Sherushe notifications@github.com wrote:
To avoid confusion, we should use VectorLN wherever we can.
— Reply to this email directly or view it on GitHub https://github.com/Sherushe/tanks/issues/35.
Doing this at the same time.
I just looked at the VectorLN code. Pass by reference more often, I know it's technically just 4 bytes of additionnal copy but it's a question of good sense.
For example:
VectlorLN VectorLN::operator+(VectorLN _vec) { ... }
and passing by reference:
VectlorLN VectorLN::operator+(VectorLN& _vec) { ... }
with const
it would be even better because _vec is not changed in the function.
I will fix the normalize function. I'm not sure what it is doing. Normalizing is just dviding by its length to have a unit vector.
I will fix the normalize function. I'm not sure what it is doing.
I didn't take vector algebra, so I had to re-invent the formula for normalization myself. Does it work? I tested and it worked... I think. Is it efficient? Heck no - and that is an understatement.
Sometimes I wish more knowledge in mathematics for these kind of stuff.
So a vector is this:
A vector is definied by its x component and y component. So what we want is a vector with a length of 1 with the same "slope" ( direction actually ). So the x and y ratio must stay the same. So the same number must be multiplied ( or divided ) to x and y. Until that point you got it I suppose but now the next part. The exact amount is not the maximum between x and y.
It's the vector's length, pythagoras.
By the way, do you mind if I change the name of the class VectorLN, because a vector is linear by defintion. There are no curved vectors.
Another linear algebra trick which you must know. The scalar product which is
x1 * x2 + y1 * y2
if v1 = (x1, y1) and v2 = (x2, y2)
And it's equal to 0 when both vectors are perpendicular.
Oh that makes sense.
I fixed most of them.
To avoid confusion, we should use VectorLN wherever we can.