00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXVEC2F_H
00022 #define FXVEC2F_H
00023
00024
00025 namespace FX {
00026
00027
00028
00029 class FXAPI FXVec2f {
00030 public:
00031 FXfloat x;
00032 FXfloat y;
00033 public:
00034
00035
00036 FXVec2f(){}
00037
00038
00039 FXVec2f(const FXVec2f& v):x(v.x),y(v.y){}
00040
00041
00042 FXVec2f(const FXfloat v[]):x(v[0]),y(v[1]){}
00043
00044
00045 FXVec2f(FXfloat xx,FXfloat yy):x(xx),y(yy){}
00046
00047
00048 FXfloat& operator[](FXint i){return (&x)[i];}
00049
00050
00051 const FXfloat& operator[](FXint i) const {return (&x)[i];}
00052
00053
00054 FXVec2f& operator=(const FXVec2f& v){x=v.x;y=v.y;return *this;}
00055
00056
00057 FXVec2f& operator=(const FXfloat v[]){x=v[0];y=v[1];return *this;}
00058
00059
00060 FXVec2f& set(const FXVec2f& v){x=v.x;y=v.y;return *this;}
00061
00062
00063 FXVec2f& set(const FXfloat v[]){x=v[0];y=v[1];return *this;}
00064
00065
00066 FXVec2f& set(FXfloat xx,FXfloat yy){x=xx;y=yy;return *this;}
00067
00068
00069 FXVec2f& operator*=(FXfloat n){ return set(x*n,y*n); }
00070 FXVec2f& operator/=(FXfloat n){ return set(x/n,y/n); }
00071 FXVec2f& operator+=(const FXVec2f& v){ return set(x+v.x,y+v.y); }
00072 FXVec2f& operator-=(const FXVec2f& v){ return set(x-v.x,y-v.y); }
00073
00074
00075 operator FXfloat*(){return &x;}
00076 operator const FXfloat*() const {return &x;}
00077
00078
00079 FXbool operator!() const { return x==0.0f && y==0.0f; }
00080
00081
00082 FXVec2f operator+() const { return *this; }
00083 FXVec2f operator-() const { return FXVec2f(-x,-y); }
00084
00085
00086 FXfloat length2() const { return x*x+y*y; }
00087 FXfloat length() const { return sqrtf(length2()); }
00088
00089
00090 FXVec2f& clamp(FXfloat lo,FXfloat hi){ return set(FXCLAMP(lo,x,hi),FXCLAMP(lo,y,hi)); }
00091 };
00092
00093
00094
00095 inline FXfloat operator*(const FXVec2f& a,const FXVec2f& b){ return a.x*b.x+a.y*b.y; }
00096
00097
00098 inline FXVec2f operator*(const FXVec2f& a,FXfloat n){return FXVec2f(a.x*n,a.y*n);}
00099 inline FXVec2f operator*(FXfloat n,const FXVec2f& a){return FXVec2f(n*a.x,n*a.y);}
00100 inline FXVec2f operator/(const FXVec2f& a,FXfloat n){return FXVec2f(a.x/n,a.y/n);}
00101 inline FXVec2f operator/(FXfloat n,const FXVec2f& a){return FXVec2f(n/a.x,n/a.y);}
00102
00103
00104 inline FXVec2f operator+(const FXVec2f& a,const FXVec2f& b){ return FXVec2f(a.x+b.x,a.y+b.y); }
00105 inline FXVec2f operator-(const FXVec2f& a,const FXVec2f& b){ return FXVec2f(a.x-b.x,a.y-b.y); }
00106
00107
00108 inline FXbool operator==(const FXVec2f& a,FXfloat n){return a.x==n && a.y==n;}
00109 inline FXbool operator!=(const FXVec2f& a,FXfloat n){return a.x!=n || a.y!=n;}
00110 inline FXbool operator==(FXfloat n,const FXVec2f& a){return n==a.x && n==a.y;}
00111 inline FXbool operator!=(FXfloat n,const FXVec2f& a){return n!=a.x || n!=a.y;}
00112
00113
00114 inline FXbool operator==(const FXVec2f& a,const FXVec2f& b){ return a.x==b.x && a.y==b.y; }
00115 inline FXbool operator!=(const FXVec2f& a,const FXVec2f& b){ return a.x!=b.x || a.y!=b.y; }
00116
00117
00118 inline FXbool operator<(const FXVec2f& a,FXfloat n){return a.x<n && a.y<n;}
00119 inline FXbool operator<=(const FXVec2f& a,FXfloat n){return a.x<=n && a.y<=n;}
00120 inline FXbool operator>(const FXVec2f& a,FXfloat n){return a.x>n && a.y>n;}
00121 inline FXbool operator>=(const FXVec2f& a,FXfloat n){return a.x>=n && a.y>=n;}
00122
00123
00124 inline FXbool operator<(FXfloat n,const FXVec2f& a){return n<a.x && n<a.y;}
00125 inline FXbool operator<=(FXfloat n,const FXVec2f& a){return n<=a.x && n<=a.y;}
00126 inline FXbool operator>(FXfloat n,const FXVec2f& a){return n>a.x && n>a.y;}
00127 inline FXbool operator>=(FXfloat n,const FXVec2f& a){return n>=a.x && n>=a.y;}
00128
00129
00130 inline FXbool operator<(const FXVec2f& a,const FXVec2f& b){ return a.x<b.x && a.y<b.y; }
00131 inline FXbool operator<=(const FXVec2f& a,const FXVec2f& b){ return a.x<=b.x && a.y<=b.y; }
00132 inline FXbool operator>(const FXVec2f& a,const FXVec2f& b){ return a.x>b.x && a.y>b.y; }
00133 inline FXbool operator>=(const FXVec2f& a,const FXVec2f& b){ return a.x>=b.x && a.y>=b.y; }
00134
00135
00136 inline FXVec2f lo(const FXVec2f& a,const FXVec2f& b){return FXVec2f(FXMIN(a.x,b.x),FXMIN(a.y,b.y));}
00137 inline FXVec2f hi(const FXVec2f& a,const FXVec2f& b){return FXVec2f(FXMAX(a.x,b.x),FXMAX(a.y,b.y));}
00138
00139
00140 extern FXAPI FXVec2f normalize(const FXVec2f& v);
00141 extern FXAPI FXVec2f fastnormalize(const FXVec2f& v);
00142
00143
00144 extern FXAPI FXStream& operator<<(FXStream& store,const FXVec2f& v);
00145
00146
00147 extern FXAPI FXStream& operator>>(FXStream& store,FXVec2f& v);
00148
00149 }
00150
00151 #endif