8 Vector2::Vector2(float x, float y)
12 Vector2::Vector2(const Vector2& vec)
30 float Vector2::angle() const
35 float Vector2::length() const
37 return sqrt(x*x + y*y);
41 string Vector2::toString() const
43 char* strX = new char[50]; // long just to be safe
44 char* strY = new char[50]; // long just to be safe
45 sprintf(strX, "%f", x);
46 sprintf(strY, "%f", y);
48 string val = (string)"Vector2 x: " + strX + ", y: " + strY;
49 delete []strX; // deletes the memory allocated, not just what is used by sprintf
50 delete []strY; // deletes the memory allocated, not just what is used by sprintf
54 void Vector2::print() const
56 printf("%s\n",toString().c_str());
60 Vector2 Vector2::add(const Vector2& vec) const
62 return Vector2(x+vec.x, y+vec.y);
64 Vector2 Vector2::subtract(const Vector2& vec) const
66 return Vector2(x-vec.x, y-vec.y);
68 Vector2 Vector2::multiply(float c) const
70 return Vector2(x*c, y*c);
72 Vector2 Vector2::divide(float c) const
74 return Vector2(x/c, y/c);
78 Vector2 operator+(const Vector2& vec1, const Vector2& vec2)
80 return vec1.add(vec2);
82 Vector2 operator-(const Vector2& vec1, const Vector2& vec2)
84 return vec1.subtract(vec2);
86 Vector2 operator*(float c, const Vector2& vec)
88 return vec.multiply(c);
90 Vector2 operator*(const Vector2& vec, float c)
92 return vec.multiply(c);
94 Vector2 operator/(const Vector2& vec, float c)
100 void operator+=(Vector2& vec1, const Vector2& vec2)
105 void operator-=(Vector2& vec1, const Vector2& vec2)
110 void operator*=(Vector2& vec, float c)
115 void operator/=(Vector2& vec, float c)