00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXVEC4F_H
00022 #define FXVEC4F_H
00023
00024
00025 namespace FX {
00026
00027
00029 class FXAPI FXVec4f {
00030 public:
00031 FXfloat x;
00032 FXfloat y;
00033 FXfloat z;
00034 FXfloat w;
00035 public:
00036
00038 FXVec4f(){}
00039
00041 FXVec4f(const FXVec3f& v,FXfloat s=0.0f):x(v.x),y(v.y),z(v.z),w(s){}
00042
00044 FXVec4f(const FXVec4f& v):x(v.x),y(v.y),z(v.z),w(v.w){}
00045
00047 FXVec4f(const FXfloat v[]):x(v[0]),y(v[1]),z(v[2]),w(v[3]){}
00048
00050 FXVec4f(FXfloat xx,FXfloat yy,FXfloat zz,FXfloat ww):x(xx),y(yy),z(zz),w(ww){}
00051
00053 FXfloat& operator[](FXint i){return (&x)[i];}
00054
00056 const FXfloat& operator[](FXint i) const {return (&x)[i];}
00057
00059 FXVec4f& operator=(const FXVec4f& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;}
00060
00062 FXVec4f& operator=(const FXfloat v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;}
00063
00065 FXVec4f& set(const FXVec4f& v){x=v.x;y=v.y;z=v.z;w=v.w;return *this;}
00066
00068 FXVec4f& set(const FXfloat v[]){x=v[0];y=v[1];z=v[2];w=v[3];return *this;}
00069
00071 FXVec4f& set(FXfloat xx,FXfloat yy,FXfloat zz,FXfloat ww){x=xx;y=yy;z=zz;w=ww;return *this;}
00072
00074 FXVec4f& operator*=(FXfloat n){ return set(x*n,y*n,z*n,w*n); }
00075 FXVec4f& operator/=(FXfloat n){ return set(x/n,y/n,z/n,w/n); }
00076 FXVec4f& operator+=(const FXVec4f& v){ return set(x+v.x,y+v.y,z+v.z,w+v.w); }
00077 FXVec4f& operator-=(const FXVec4f& v){ return set(x-v.x,y-v.y,z-v.z,w-v.w); }
00078
00080 operator FXfloat*(){return &x;}
00081 operator const FXfloat*() const {return &x;}
00082 operator FXVec3f&(){return *reinterpret_cast<FXVec3f*>(this);}
00083 operator const FXVec3f&() const {return *reinterpret_cast<const FXVec3f*>(this);}
00084
00086 FXbool operator!() const { return x==0.0f && y==0.0f && z==0.0f && w==0.0f; }
00087
00089 FXVec4f operator+() const { return *this; }
00090 FXVec4f operator-() const { return FXVec4f(-x,-y,-z,-w); }
00091
00093 FXfloat length2() const { return x*x+y*y+z*z+w*w; }
00094 FXfloat length() const { return sqrtf(length2()); }
00095
00097 FXVec4f& clamp(FXfloat lo,FXfloat hi){ return set(FXCLAMP(lo,x,hi),FXCLAMP(lo,y,hi),FXCLAMP(lo,z,hi),FXCLAMP(lo,w,hi)); }
00098
00100 FXfloat distance(const FXVec3f& p) const;
00101
00103 FXbool crosses(const FXVec3f& a,const FXVec3f& b) const;
00104
00106 ~FXVec4f(){}
00107 };
00108
00109
00111 inline FXfloat operator*(const FXVec4f& a,const FXVec4f& b){ return a.x*b.x+a.y*b.y+a.z*b.z+a.w*b.w; }
00112
00114 inline FXVec4f operator*(const FXVec4f& a,FXfloat n){return FXVec4f(a.x*n,a.y*n,a.z*n,a.w*n);}
00115 inline FXVec4f operator*(FXfloat n,const FXVec4f& a){return FXVec4f(n*a.x,n*a.y,n*a.z,n*a.w);}
00116 inline FXVec4f operator/(const FXVec4f& a,FXfloat n){return FXVec4f(a.x/n,a.y/n,a.z/n,a.w/n);}
00117 inline FXVec4f operator/(FXfloat n,const FXVec4f& a){return FXVec4f(n/a.x,n/a.y,n/a.z,n/a.w);}
00118
00120 inline FXVec4f operator+(const FXVec4f& a,const FXVec4f& b){ return FXVec4f(a.x+b.x,a.y+b.y,a.z+b.z,a.w+b.w); }
00121 inline FXVec4f operator-(const FXVec4f& a,const FXVec4f& b){ return FXVec4f(a.x-b.x,a.y-b.y,a.z-b.z,a.w-b.w); }
00122
00124 inline FXbool operator==(const FXVec4f& a,FXfloat n){return a.x==n && a.y==n && a.z==n && a.w==n;}
00125 inline FXbool operator!=(const FXVec4f& a,FXfloat n){return a.x!=n || a.y!=n || a.z!=n || a.w!=n;}
00126 inline FXbool operator==(FXfloat n,const FXVec4f& a){return n==a.x && n==a.y && n==a.z && n==a.w;}
00127 inline FXbool operator!=(FXfloat n,const FXVec4f& a){return n!=a.x || n!=a.y || n!=a.z || n!=a.w;}
00128
00130 inline FXbool operator==(const FXVec4f& a,const FXVec4f& b){ return a.x==b.x && a.y==b.y && a.z==b.z && a.w==b.w; }
00131 inline FXbool operator!=(const FXVec4f& a,const FXVec4f& b){ return a.x!=b.x || a.y!=b.y || a.z!=b.z || a.w!=b.w; }
00132
00134 inline FXbool operator<(const FXVec4f& a,FXfloat n){return a.x<n && a.y<n && a.z<n && a.w<n;}
00135 inline FXbool operator<=(const FXVec4f& a,FXfloat n){return a.x<=n && a.y<=n && a.z<=n && a.w<=n;}
00136 inline FXbool operator>(const FXVec4f& a,FXfloat n){return a.x>n && a.y>n && a.z>n && a.w>n;}
00137 inline FXbool operator>=(const FXVec4f& a,FXfloat n){return a.x>=n && a.y>=n && a.z>=n && a.w>=n;}
00138
00140 inline FXbool operator<(FXfloat n,const FXVec4f& a){return n<a.x && n<a.y && n<a.z && n<a.w;}
00141 inline FXbool operator<=(FXfloat n,const FXVec4f& a){return n<=a.x && n<=a.y && n<=a.z && n<=a.w;}
00142 inline FXbool operator>(FXfloat n,const FXVec4f& a){return n>a.x && n>a.y && n>a.z && n>a.w;}
00143 inline FXbool operator>=(FXfloat n,const FXVec4f& a){return n>=a.x && n>=a.y && n>=a.z && n>=a.w;}
00144
00146 inline FXbool operator<(const FXVec4f& a,const FXVec4f& b){ return a.x<b.x && a.y<b.y && a.z<b.z && a.w<b.w; }
00147 inline FXbool operator<=(const FXVec4f& a,const FXVec4f& b){ return a.x<=b.x && a.y<=b.y && a.z<=b.z && a.w<=b.w; }
00148 inline FXbool operator>(const FXVec4f& a,const FXVec4f& b){ return a.x>b.x && a.y>b.y && a.z>b.z && a.w>b.w; }
00149 inline FXbool operator>=(const FXVec4f& a,const FXVec4f& b){ return a.x>=b.x && a.y>=b.y && a.z>=b.z && a.w>=b.w; }
00150
00152 inline FXVec4f lo(const FXVec4f& a,const FXVec4f& b){return FXVec4f(FXMIN(a.x,b.x),FXMIN(a.y,b.y),FXMIN(a.z,b.z),FXMIN(a.w,b.w));}
00153 inline FXVec4f hi(const FXVec4f& a,const FXVec4f& b){return FXVec4f(FXMAX(a.x,b.x),FXMAX(a.y,b.y),FXMAX(a.z,b.z),FXMAX(a.w,b.w));}
00154
00156 extern FXAPI FXVec4f plane(const FXVec4f& vec);
00157 extern FXAPI FXVec4f plane(const FXVec3f& vec,FXfloat dist);
00158 extern FXAPI FXVec4f plane(const FXVec3f& vec,const FXVec3f& p);
00159 extern FXAPI FXVec4f plane(const FXVec3f& a,const FXVec3f& b,const FXVec3f& c);
00160
00162 extern FXAPI FXColor colorFromVec4f(const FXVec4f& vec);
00163
00165 extern FXAPI FXVec4f colorToVec4f(FXColor clr);
00166
00168 extern FXAPI FXVec4f normalize(const FXVec4f& v);
00169 extern FXAPI FXVec4f fastnormalize(const FXVec4f& v);
00170
00172 extern FXAPI FXVec4f lerp(const FXVec4f& u,const FXVec4f& v,FXdouble f);
00173
00175 extern FXAPI FXStream& operator<<(FXStream& store,const FXVec4f& v);
00176
00178 extern FXAPI FXStream& operator>>(FXStream& store,FXVec4f& v);
00179
00180 }
00181
00182 #endif