Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 #ifndef _VRENDER_VECTOR3_H
00046 #define _VRENDER_VECTOR3_H
00047 
00048 #include <stdexcept>
00049 
00050 #ifndef FLT_MAX
00051 # define FLT_MAX 9.99E20f
00052 #endif
00053 
00054 namespace vrender
00055 {
00056   class NVector3;
00057 
00058         class Vector3
00059         {
00060                 public:
00061                         
00063 
00064                         static const Vector3 inf;
00066 
00067                         
00069 
00070                         Vector3 ();
00071                         ~Vector3 ();
00072                         Vector3 (const Vector3&);
00073                         Vector3 (const NVector3&);
00074                         Vector3 (double, double, double);
00075 
00077 
00078                         
00080 
00081                         inline double  x() const { return _xyz[0]; }
00082                         inline double  y() const { return _xyz[1]; }
00083                         inline double  z() const { return _xyz[2]; }
00084                         inline void  setX(double r) { _xyz[0] = r; }
00085                         inline void  setY(double r) { _xyz[1] = r; }
00086                         inline void  setZ(double r) { _xyz[2] = r; }
00087                         inline void  setXYZ (double x,double y,double z) { _xyz[0] = x; _xyz[1] = y; _xyz[2] = z; }
00089 
00090                         
00092 
00093                         inline Vector3& operator= (const Vector3& u)  { _xyz[0] = u._xyz[0]; _xyz[1] = u._xyz[1]; _xyz[2] = u._xyz[2]; return *this; }
00094                         Vector3& operator= (const NVector3& u);
00096 
00097                         
00099 
00100                         friend bool operator== (const Vector3&,const Vector3&);
00101                         friend bool operator!= (const Vector3&,const Vector3&);
00103 
00104                         
00106 
00107                         inline Vector3& operator+= (const Vector3& v)
00108                         {
00109                                 _xyz[0] += v._xyz[0];
00110                                 _xyz[1] += v._xyz[1];
00111                                 _xyz[2] += v._xyz[2];
00112                                 return *this;
00113                         }
00114 
00115                         inline Vector3& operator-= (const Vector3& v)
00116                         {
00117                                 _xyz[0] -= v._xyz[0];
00118                                 _xyz[1] -= v._xyz[1];
00119                                 _xyz[2] -= v._xyz[2];
00120                                 return *this;
00121                         }
00122 
00123                         inline Vector3& operator*= (double f) { _xyz[0] *= f; _xyz[1] *= f; _xyz[2] *= f; return *this;}
00124                         inline Vector3& operator/= (double f) { _xyz[0] /= f; _xyz[1] /= f; _xyz[2] /= f; return *this;}
00125 
00126                         static Vector3 mini(const Vector3&,const Vector3&) ;
00127                         static Vector3 maxi(const Vector3&,const Vector3&) ;
00128 
00129                         Vector3& operator-= (const NVector3&);
00130                         Vector3& operator+= (const NVector3&);
00131 
00132                         friend Vector3 operator- (const Vector3& u) { return Vector3(-u[0], -u[1], -u[2]); }
00133 
00134                         inline Vector3 operator+(const Vector3& u) const
00135                         {
00136                                 return Vector3(_xyz[0]+u._xyz[0],_xyz[1]+u._xyz[1],_xyz[2]+u._xyz[2]);
00137                         }
00138                         inline Vector3 operator-(const Vector3& u) const
00139                         {
00140                                 return Vector3(_xyz[0]-u._xyz[0],_xyz[1]-u._xyz[1],_xyz[2]-u._xyz[2]);
00141                         }
00142 
00143                         inline double    operator*(const Vector3& u) const
00144                         {
00145                                 return _xyz[0]*u._xyz[0] + _xyz[1]*u._xyz[1] + _xyz[2]*u._xyz[2];
00146                         }
00147 
00148                         inline Vector3 operator^(const Vector3& v) const
00149                         {
00150                                 return Vector3( _xyz[1]*v._xyz[2] - _xyz[2]*v._xyz[1],
00151                                                                                         _xyz[2]*v._xyz[0] - _xyz[0]*v._xyz[2],
00152                                                                                         _xyz[0]*v._xyz[1] - _xyz[1]*v._xyz[0]);
00153                         }
00154 
00155                         Vector3 operator/ (double v) { return Vector3(_xyz[0]/v,_xyz[1]/v,_xyz[2]/v); }
00156                         Vector3 operator* (double v) { return Vector3(_xyz[0]*v,_xyz[1]*v,_xyz[2]*v); }
00157 
00158                         friend Vector3 operator* (double,const Vector3&);
00160 
00161                         
00163 
00164                         double norm       () const;
00165                         double squareNorm () const;
00166                         double infNorm    () const; 
00167 
00168                         
00170 
00171                         friend std::ostream& operator<< (std::ostream&,const Vector3&);
00173 
00174                         double  operator[] (int i) const
00175                         {
00176                                 if((i < 0)||(i > 2))
00177                                         throw std::runtime_error("Out of bounds in Vector3::operator[]") ;
00178 
00179                                 return _xyz[i];
00180                         }
00181 
00182                         double& operator[] (int i)
00183                         {
00184                                 if((i < 0)||(i > 2))
00185                                         throw std::runtime_error("Out of bounds in Vector3::operator[]") ;
00186 
00187                                 return _xyz[i];
00188                         }
00189 
00190                 private:
00191                         double _xyz[3];  
00192 
00193         }; 
00194 }
00195 #endif // _VECTOR3_H