Hay all. At the moment I am trying to make my own 2D vector library just to get a better understanding of vectors, I like the <Vector.h> standard library in Microsoft visual studios 2010 but I would like to be able to make my own version of it. The features I want from it are functions like Dot product,magnitude and the four basic operators like +, -, * ,/. Any way I am stuck on how to do it so I was wondering if anyone knows any where I can learn some more about it or give me some of your own knowledge =D
i figured they were wrong thus the post and i have written a few things and most of my stuff works but I don't particularly understand vectors and operators.
That's why I wanna write my own library to understand them better but I believe I am doing it wrong. so to under what I am stuck on i would say most of it lol >.<.
I cant find anywhere they teaches me about vectors except for the standard std/stl library one
If I were you, I would leverage complex numbers in your code -- if you store complex<float> instead of two different floats, you get all arithmetic, and magnitude, and some other stuff for free.
Otherwise, remember that binary ops are almost always implemented as non-member functions, and since you provide compound assignments as well, binary ops should be implemented in terms of compounds:
1 2 3 4
Vector2 operator + (Vector2 left, const Vector2& right)
{
return left += right; // the canonical addition operator is done this way
}
PS: oh, and of course length and returnValue should not be in your class