inlib  1.2.0
/Users/barrand/private/dev/softinex/old/inexlib-1.2/inlib/inlib/vec3f
Go to the documentation of this file.
00001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
00002 // See the file inlib.license for terms.
00003 
00004 #ifndef inlib_vec3f
00005 #define inlib_vec3f
00006 
00007 #include "a3"
00008 
00009 //#include "fmath"
00010 
00011 namespace inlib {
00012 
00013 class vec3f : public inlib::a3::vec<float> {
00014 public:
00015   vec3f(): inlib::a3::vec<float>() {}
00016   vec3f(const float a_vec[3]): inlib::a3::vec<float>(a_vec) {}
00017   vec3f(float a0,float a1,float a2)
00018   : inlib::a3::vec<float>(a0,a1,a2){}
00019   virtual ~vec3f() {}
00020 public:
00021   vec3f(const vec3f& a_from): inlib::a3::vec<float>(a_from){}
00022   vec3f& operator=(const vec3f& a_from){
00023     inlib::a3::vec<float>::operator=(a_from);
00024     return *this;
00025   }
00026 
00027   vec3f(const inlib::a3::vec<float>& a_from)
00028   : inlib::a3::vec<float>(a_from){}
00029 
00030 public: //operators
00031   float& operator[](unsigned int a_index) {
00032     //WARNING : no check on a_index.
00033     return m_vector[a_index];
00034   }
00035   const float& operator[](unsigned int a_index) const {
00036     //WARNING : no check on a_index.
00037     return m_vector[a_index];
00038   }
00039   vec3f operator*(float a_v) const {
00040     return vec3f(m_vector[0]*a_v,
00041                  m_vector[1]*a_v,
00042                  m_vector[2]*a_v);
00043   }    
00044   vec3f operator+(const vec3f& a_v) const {
00045     return vec3f(m_vector[0]+a_v[0],
00046                  m_vector[1]+a_v[1],
00047                  m_vector[2]+a_v[2]);
00048   }    
00049   vec3f operator-(const vec3f& a_v) const {
00050     return vec3f(m_vector[0]-a_v[0],
00051                  m_vector[1]-a_v[1],
00052                  m_vector[2]-a_v[2]);
00053   }    
00054   vec3f& operator+=(const vec3f& a_v) {   
00055     m_vector[0] += a_v[0];
00056     m_vector[1] += a_v[1];
00057     m_vector[2] += a_v[2];
00058     return *this;
00059   }    
00060   vec3f& operator*=(float a_v) {   
00061     m_vector[0] *= a_v;
00062     m_vector[1] *= a_v;
00063     m_vector[2] *= a_v;
00064     return *this;
00065   }    
00066   vec3f operator-() const {
00067     return vec3f(-m_vector[0],-m_vector[1],-m_vector[2]);
00068   }
00069   bool operator==(const vec3f& a_v) const {return equal(a_v);}
00070   bool operator!=(const vec3f& a_v) const {return !operator==(a_v);}
00071 public:
00072   float x() const {return m_vector[0];}
00073   float y() const {return m_vector[1];}
00074   float z() const {return m_vector[2];}
00075   /*float length() const {
00076     return fsqrt(m_vector[0] * m_vector[0] + 
00077                  m_vector[1] * m_vector[1] + 
00078                  m_vector[2] * m_vector[2]); 
00079   }
00080   float normalize() {
00081     float norme = length();
00082     if(norme==0) return 0;
00083     divide(norme);
00084     return norme;
00085   }*/
00086   vec3f cross(const vec3f& aV) const {
00087     return vec3f(m_vector[1] * aV.m_vector[2] - m_vector[2] * aV.m_vector[1],
00088                  m_vector[2] * aV.m_vector[0] - m_vector[0] * aV.m_vector[2],
00089                  m_vector[0] * aV.m_vector[1] - m_vector[1] * aV.m_vector[0]);
00090   }    
00091   float dot(const vec3f& aV) const {
00092     return (m_vector[0] * aV.m_vector[0] + 
00093             m_vector[1] * aV.m_vector[1] + 
00094             m_vector[2] * aV.m_vector[2]);
00095   }    
00096 public:
00097   //NOTE : don't handle a static object because of mem balance.
00098   //static const vec3f& x_axis() {
00099   //  static const vec3f s_v(1,0,0);
00100   //  return s_v;
00101   //}
00102   //static const vec3f& y_axis() {
00103   //  static const vec3f s_v(0,1,0);
00104   //  return s_v;
00105   //}
00106   //static const vec3f& z_axis() {
00107   //  static const vec3f s_v(0,0,1);
00108   //  return s_v;
00109   //}
00110 private:
00111   static void check_instantiation() {
00112     vec3f dummy(0,0,0);
00113     dummy.set_value(1,1,1);
00114   }
00115 };
00116 
00117 inline vec3f operator*(float a_f,const vec3f& a_v) {
00118   vec3f res(a_v);
00119   res *= a_f;
00120   return res;
00121 }
00122 
00123 inline std::ostream& operator<<(std::ostream& a_out,const vec3f& a_this){
00124   a_out << "x = " << a_this[0]
00125         << ",y = " << a_this[1]
00126         << ",z = " << a_this[2]
00127         << std::endl;
00128   return a_out;
00129 }
00130 
00131 }
00132 
00133 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines