00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef __CS_VECTOR2_H__
00021 #define __CS_VECTOR2_H__
00022
00032 class csVector2
00033 {
00034 public:
00036 float x;
00038 float y;
00039
00041 csVector2 () {}
00042
00044 csVector2 (float x, float y) { csVector2::x = x; csVector2::y = y; }
00045
00047 inline void Set (float ix, float iy)
00048 { x = ix; y = iy; }
00049
00051 inline void Set (const csVector2& v)
00052 { x = v.x; y = v.y; }
00053
00055 static float Norm (const csVector2& v);
00056
00058 float Norm () const;
00059
00061 float SquaredNorm () const
00062 { return x * x + y * y; }
00063
00065 void Rotate (float angle);
00066
00068 csVector2& operator+= (const csVector2& v)
00069 { x += v.x; y += v.y; return *this; }
00070
00072 csVector2& operator-= (const csVector2& v)
00073 { x -= v.x; y -= v.y; return *this; }
00074
00076 csVector2& operator*= (float f) { x *= f; y *= f; return *this; }
00077
00079 csVector2& operator/= (float f) { f = 1.0f / f; x *= f; y *= f; return *this; }
00080
00082 inline csVector2 operator+ () const { return *this; }
00083
00085 inline csVector2 operator- () const { return csVector2(-x,-y); }
00086
00088 friend csVector2 operator+ (const csVector2& v1, const csVector2& v2);
00090 friend csVector2 operator- (const csVector2& v1, const csVector2& v2);
00092 friend float operator* (const csVector2& v1, const csVector2& v2);
00094 friend csVector2 operator* (const csVector2& v, float f);
00096 friend csVector2 operator* (float f, const csVector2& v);
00098 friend csVector2 operator/ (const csVector2& v, float f);
00100 friend bool operator== (const csVector2& v1, const csVector2& v2);
00102 friend bool operator!= (const csVector2& v1, const csVector2& v2);
00103
00105 inline friend bool operator< (const csVector2& v, float f)
00106 { return ABS(v.x)<f && ABS(v.y)<f; }
00107
00109 inline friend bool operator> (float f, const csVector2& v)
00110 { return ABS(v.x)<f && ABS(v.y)<f; }
00111 };
00112
00115 #endif // __CS_VECTOR2_H__