Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

utilityfuncs.h

00001 #ifndef __UTILITYFUNCS_H__
00002 #define __UTILITYFUNCS_H__
00003 
00004 #include <math.h>
00005 
00006 
00012 class sPoint3f
00013 {
00014 public:
00015 
00016     sPoint3f() { x = 0; y = 0; z = 0; }
00017     sPoint3f( float i, float j, float k) { x = i; y = j; z = k; }
00018     void Init(float i, float j, float k) { x = i; y = j; z = k; }
00019     sPoint3f operator= (sPoint3f v); 
00020     float x, y, z;
00021 };
00022 
00023 class sVector3f
00024 {
00025 public:
00026 
00027     sVector3f() { x = 0; y = 0; z = 0; }
00028     sVector3f( float i, float j, float k) { x = i; y = j; z = k; }
00029     Init( float i, float j, float k) { x = i; y = j; z = k; }
00030     sVector3f operator= (sVector3f v); 
00031     float x, y, z;
00032 };
00033 
00034 class sGrad
00035 {
00036 public:
00037     sGrad() {}
00038     sGrad(float i, float j, float k) { x = i; y = j; z = k; }
00039 
00040     sGrad operator= (sVector3f v);
00041     float x,y,z;
00042 };
00043 
00044 class sRGBA
00045 {
00046 public:
00047 
00048     sRGBA operator+= (sRGBA v);
00049     float r;
00050     float g;
00051     float b;
00052     float a;
00053 };
00054 
00055 
00056 class  CVector3f
00057 {
00058 public:
00059     CVector3f()
00060     {
00061         _mag = 0;
00062         _vec.x = 0;         _vec.y = 0;         _vec.z = 0, 
00063         _normalized.x = 0;  _normalized.y = 0;  _normalized.z = 0;
00064     };
00065 
00066     CVector3f(float x, float y, float z)
00067     {
00068         Set(x,y,z);
00069     }
00070 
00071     void Set(sPoint3f sPoint)
00072     {
00073         Set(sPoint.x, sPoint.y, sPoint.z);
00074     }
00075 
00076     void Set(float x, float y, float z)
00077     {
00078         _vec.x = x; _vec.y = y; _vec.z = z;
00079 
00080         _mag = sqrt( _vec.x * _vec.x + _vec.y * _vec.y + _vec.z * _vec.z );
00081 
00082         if ( 0 != _mag )
00083         {
00084             _normalized.x = x / _mag;
00085             _normalized.y = y / _mag;
00086             _normalized.z = z / _mag;
00087         }
00088         else
00089         {
00090             _normalized.x = 0;
00091             _normalized.y = 0;
00092             _normalized.z = 0;
00093         }
00094     }
00095 
00096     float     GetMagnitude()    { return _mag; }
00097     sVector3f GetNormalized()   { return _normalized; }
00098     sPoint3f  GetPoint()        
00099     { 
00100         sPoint3f point; 
00101         
00102         point.x = _vec.x; 
00103         point.y = _vec.y;
00104         point.z = _vec.z;
00105 
00106         return point;
00107     }
00108     
00109 private:
00110     sVector3f  _vec, _normalized;
00111     float      _mag;
00112 };
00113 
00114 /*
00115  * 
00116  *
00117  */
00118 
00119 sPoint3f operator + (sPoint3f c1, sVector3f c2);
00120 sPoint3f operator - (sPoint3f c2, sPoint3f c1);
00121 
00122 float dot(sVector3f v1, sVector3f v2);
00123 
00124 sGrad operator + (sGrad g1, sGrad g2);
00125 sGrad operator / (sGrad g1, float k);
00126 sGrad operator * (sGrad g1, float k);
00127 
00128 #endif

Generated on Mon Dec 12 15:20:26 2005 for CCube by  doxygen 1.4.1