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