Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

RainVector.h

Go to the documentation of this file.
00001 #ifndef __GXVECTOR_H
00002 #define __GXVECTOR_H
00003 
00004 
00005 #include "math.h"
00006 
00007 
00008 
00010 //vector
00012 template<unsigned int count>
00013 class CRainVector
00014 {
00015 public:
00016         float m_fPoints[count];
00017 
00018         inline void Normalize()
00019         {
00020                 float fLen=GetLength();
00021 
00022                 if(0==fLen)
00023                 {
00024                         return;
00025                 }
00026 
00027                 operator/= (fLen);
00028         }
00029 
00030 
00031         //todo, add an [] (returns float&) operator here instead of using m_fpoints, and update in the other ones dummy (like the CGXVector)
00032         inline float GetLength()
00033         {
00034                 float fLen=0;
00035 
00036                 for(UINT uCtr=0;uCtr<count;uCtr++)
00037                 {
00038                         fLen+=(m_fPoints[uCtr]*m_fPoints[uCtr]);
00039                 }
00040 
00041                 return (float)sqrt(fLen);
00042         }
00043 
00044         inline float operator[] (UINT uIndex)
00045         {
00046                 return m_fPoints[uIndex];
00047         }
00048 
00049 
00050         inline void operator*= (float fMul)
00051         {
00052                 for(UINT uCtr=0;uCtr<count;uCtr++)
00053                 {
00054                         m_fPoints[uCtr]*=fMul;
00055                 }
00056         }
00057 
00058         inline void operator+= (float fAdd)
00059         {
00060                 for(UINT uCtr=0;uCtr<count;uCtr++)
00061                 {
00062                         m_fPoints[uCtr]+=fAdd;
00063                 }
00064         }
00065 
00066 
00067         inline CRainVector<count> operator* (float fAmt)
00068         {
00069                 CRainVector<count> vRet;
00070                 memcpy(&vRet,this,sizeof(CRainVector<count>));
00071                 vRet*=fAmt;
00072                 return vRet;
00073         }
00074 
00075         inline CRainVector<count> operator+ (CRainVector<count>& vIn)
00076         {
00077                 CRainVector<count> vRet;
00078                 
00079                 for(UINT uCtr=0;uCtr<count;uCtr++)
00080                 {
00081                         vRet.m_fPoints[uCtr]=m_fPoints[uCtr]+vIn.m_fPoints[uCtr];
00082                 }
00083 
00084                 return vRet;
00085         }
00086 
00087         inline CRainVector<count> operator* (CRainVector<count>& vIn)
00088         {
00089                 CRainVector<count> vRet;
00090                 
00091                 for(UINT uCtr=0;uCtr<count;uCtr++)
00092                 {
00093                         vRet.m_fPoints[uCtr]=m_fPoints[uCtr]*vIn.m_fPoints[uCtr];
00094                 }
00095 
00096                 return vRet;
00097         }
00098 
00099 
00100         inline CRainVector<count> operator/ (CRainVector<count>& vIn)
00101         {
00102                 CRainVector<count> vRet;
00103                 
00104                 for(UINT uCtr=0;uCtr<count;uCtr++)
00105                 {
00106                         vRet.m_fPoints[uCtr]=m_fPoints[uCtr]/vIn.m_fPoints[uCtr];
00107                 }
00108 
00109                 return vRet;
00110         }
00111 
00112 
00113         inline void operator/= (float fDiv)
00114         {
00115                 for(UINT uCtr=0;uCtr<count;uCtr++)
00116                 {
00117                         m_fPoints[uCtr]/=fDiv;
00118                 }
00119         }
00120 
00121         inline void operator-= (CRainVector<count>& vSub)
00122         {
00123                 for(UINT uCtr=0;uCtr<count;uCtr++)
00124                 {
00125                         m_fPoints[uCtr]-=vSub.m_fPoints[uCtr];
00126                 }
00127         }
00128 
00129         inline void operator+= (CRainVector<count>& vAdd)
00130         {
00131                 for(UINT uCtr=0;uCtr<count;uCtr++)
00132                 {
00133                         m_fPoints[uCtr]+=vAdd.m_fPoints[uCtr];
00134                 }
00135         }
00136 
00137         inline void operator*= (CRainVector<count>& vMul)
00138         {
00139                 for(UINT uCtr=0;uCtr<count;uCtr++)
00140                 {
00141                         m_fPoints[uCtr]*=vMul.m_fPoints[uCtr];
00142                 }
00143         }
00144 
00145         inline void operator/= (CRainVector<count>& vDiv)
00146         {
00147                 for(UINT uCtr=0;uCtr<count;uCtr++)
00148                 {
00149                         m_fPoints[uCtr]/=vDiv.m_fPoints[uCtr];
00150                 }
00151         }
00152 
00153 
00154 
00155 
00156         inline CRainVector operator- (CRainVector<count>& vSub)
00157         {
00158                 CRainVector vOut=*this;
00159                 vOut-=vSub;
00160                 return vOut;
00161         }
00162         
00163 
00164         inline float Dot(CRainVector<count>& vRightSide)
00165         {
00166                 float fResult=0;
00167 
00168                 for(UINT uCtr=0;uCtr<count;uCtr++)
00169                 {
00170                         fResult+=m_fPoints[uCtr]*(vRightSide.m_fPoints[uCtr]);
00171                 }
00172 
00173                 return fResult;
00174         }
00175 
00176         /*      CBlakeUtil3DVector returnVal;
00177         returnVal.m_x=(m_y*vArg.m_z)-(m_z*vArg.m_y);
00178         returnVal.m_y=(m_z*vArg.m_x)-(m_x*vArg.m_z);
00179         returnVal.m_z=(m_x*vArg.m_y)-(m_y*vArg.m_x);*/
00180 
00181 
00182         inline bool Cross(CRainVector<count>& vOut, CRainVector<count>& vRightSide)
00183         {
00184                 if(3==count)
00185                 {
00186                         vOut.m_fPoints[0]=(m_fPoints[1]*vRightSide.m_fPoints[2])-(m_fPoints[2]*vRightSide.m_fPoints[1]);
00187                         vOut.m_fPoints[1]=(m_fPoints[2]*vRightSide.m_fPoints[0])-(m_fPoints[0]*vRightSide.m_fPoints[2]);
00188                         vOut.m_fPoints[2]=(m_fPoints[0]*vRightSide.m_fPoints[1])-(m_fPoints[1]*vRightSide.m_fPoints[0]);
00189                         return true;
00190                 }
00191 
00192                 return false;
00193         }
00194 
00195 };
00196 
00197 
00198 
00199 
00200 
00201 #endif

Generated on Thu May 23 17:51:00 2002 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001