8 Vector2::Vector2(float x, float y)
12 Vector2::Vector2(const Vector2& vec)
30 float Vector2::angle() const
34 float Vector2::length() const
36 return sqrt(x*x + y*y);
40 string Vector2::toString() const
42 char* strX = new char[50]; // long just to be safe
43 char* strY = new char[50]; // long just to be safe
44 sprintf(strX, "%f", x);
45 sprintf(strY, "%f", y);
47 string val = (string)"Vector2 x: " + strX + ", y: " + strY;
48 delete []strX; // deletes the memory allocated, not just what is used by sprintf
49 delete []strY; // deletes the memory allocated, not just what is used by sprintf
53 void Vector2::print() const
55 printf("%s\n",toString().c_str());
59 Vector2 Vector2::add(const Vector2& vec) const
61 return Vector2(x+vec.x, y+vec.y);
63 Vector2 Vector2::subtract(const Vector2& vec) const
65 return Vector2(x-vec.x, y-vec.y);
67 Vector2 Vector2::multiply(float c) const
69 return Vector2(x*c, y*c);
71 Vector2 Vector2::divide(float c) const
73 return Vector2(x/c, y/c);
77 Vector2 operator+(const Vector2& vec1, const Vector2& vec2)
79 return vec1.add(vec2);
81 Vector2 operator-(const Vector2& vec1, const Vector2& vec2)
83 return vec1.subtract(vec2);
85 Vector2 operator*(float c, const Vector2& vec)
87 return vec.multiply(c);
89 Vector2 operator*(const Vector2& vec, float c)
91 return vec.multiply(c);
93 Vector2 operator/(const Vector2& vec, float c)
99 void operator+=(Vector2& vec1, const Vector2& vec2)
104 void operator-=(Vector2& vec1, const Vector2& vec2)
109 void operator*=(Vector2& vec, float c)
114 void operator/=(Vector2& vec, float c)