vec3_inl.h
Go to the documentation of this file.
00001 /*******************************************************************************
00002  *  vec3_inl.h
00003  *
00004  *  (C) 2006 AG Aktives Sehen <agas@uni-koblenz.de>
00005  *           Universitaet Koblenz-Landau
00006  *
00007  * Author: Frank Neuhaus
00008  *******************************************************************************/
00009 
00010 #define THIS Vector3D
00011 
00012 #include <sstream>
00013 
00014 //----------------------------------------------------------------------------------------------------------
00015 inline THIS::THIS()
00016 {}
00017 //----------------------------------------------------------------------------------------------------------
00018 inline THIS::THIS ( float x, float y, float z )
00019 {
00020   m_X = x; m_Y = y; m_Z = z;
00021 };
00022 //----------------------------------------------------------------------------------------------------------
00023 inline THIS::THIS ( const Vector3D& v2 )
00024 {
00025   m_X=v2[0];
00026   m_Y=v2[1];
00027   m_Z=v2[2];
00028 };
00029 //----------------------------------------------------------------------------------------------------------
00030 inline THIS::THIS ( const CVec2& v, float z)
00031 {
00032   m_X=v[0];
00033   m_Y=v[1];
00034   m_Z=z;
00035 }
00036 //----------------------------------------------------------------------------------------------------------
00037 inline Vector3D THIS::operator+ ( const Vector3D& vVector ) const
00038 {
00039   return Vector3D ( vVector[0] + m_X, vVector[1] + m_Y, vVector[2] + m_Z );
00040 };
00041 //----------------------------------------------------------------------------------------------------------
00042 inline Vector3D THIS::operator-() const
00043 {
00044   return Vector3D ( -m_X,-m_Y,-m_Z );
00045 };
00046 //----------------------------------------------------------------------------------------------------------
00047 inline Vector3D THIS::operator+() const
00048 {
00049   return Vector3D ( m_X,m_Y,m_Z );
00050 };
00051 //----------------------------------------------------------------------------------------------------------
00052 inline Vector3D THIS::operator- ( const Vector3D& vVector ) const
00053 {
00054   return Vector3D ( m_X-vVector[0],m_Y-vVector[1],m_Z-vVector[2] );
00055 };
00056 //----------------------------------------------------------------------------------------------------------
00057 inline Vector3D THIS::operator* ( const float num ) const
00058 {
00059   return Vector3D ( m_X * num, m_Y * num, m_Z * num );
00060 };
00061 //----------------------------------------------------------------------------------------------------------
00062 inline Vector3D& THIS::operator*= ( const float num )
00063 {
00064   m_X*=num; m_Y*=num; m_Z*=num;
00065   return *this;
00066 }
00067 //----------------------------------------------------------------------------------------------------------
00068 inline Vector3D& THIS::operator/= ( const float num )
00069 {
00070   m_X/=num; m_Y/=num; m_Z/=num;
00071   return *this;
00072 }
00073 //----------------------------------------------------------------------------------------------------------
00074 inline float THIS::operator* ( const Vector3D& vVector ) const
00075 {
00076   return vVector[0]*m_X+vVector[1]*m_Y+vVector[2]*m_Z;
00077 };
00078 //----------------------------------------------------------------------------------------------------------
00079 inline Vector3D& THIS::operator+= ( const Vector3D& vVector )
00080 {
00081   m_X+=vVector[0];
00082   m_Y+=vVector[1];
00083   m_Z+=vVector[2];
00084   return *this;
00085 }
00086 //----------------------------------------------------------------------------------------------------------
00087 inline bool THIS::operator < ( const Vector3D& vVec ) const
00088 {
00089   if ( m_X<vVec[0] ) return true;
00090   if ( m_X>vVec[0] ) return false;
00091   if ( m_Y<vVec[1] ) return true;
00092   if ( m_Y>vVec[1] ) return false;
00093   return ( m_Z<vVec[2] );
00094 }
00095 //----------------------------------------------------------------------------------------------------------
00096 inline bool THIS::operator > ( const Vector3D& vVec ) const
00097 {
00098   if ( m_X<vVec[0] ) return false;
00099   if ( m_X>vVec[0] ) return true;
00100   if ( m_Y<vVec[1] ) return false;
00101   if ( m_Y>vVec[1] ) return true;
00102   return ( m_Z>vVec[2] );
00103 }
00104 //----------------------------------------------------------------------------------------------------------
00105 inline Vector3D& THIS::operator-= ( const Vector3D& vVector )
00106 {
00107   m_X-=vVector[0];
00108   m_Y-=vVector[1];
00109   m_Z-=vVector[2];
00110   return *this;
00111 }
00112 //----------------------------------------------------------------------------------------------------------
00113 inline Vector3D THIS::operator^ ( const Vector3D& vVector2 ) const
00114 {
00115   Vector3D vNormal;
00116 
00117   // Calculate the cross product with the non communitive equation
00118   vNormal[0] = ( ( m_Y * vVector2[2] ) - ( m_Z * vVector2[1] ) );
00119   vNormal[1] = ( ( m_Z * vVector2[0] ) - ( m_X * vVector2[2] ) );
00120   vNormal[2] = ( ( m_X * vVector2[1] ) - ( m_Y * vVector2[0] ) );
00121 
00122   // Return the cross product
00123   return vNormal;
00124 };
00125 //----------------------------------------------------------------------------------------------------------
00126 inline bool THIS::operator== ( const Vector3D& v1 ) const
00127 {
00128   // this is evil!
00129   assert ( 0 );
00130 
00131   static const float EPS=1.0f/100.0f;
00132   if ( fabs ( v1[0]-m_X ) >EPS ) return false;
00133   if ( fabs ( v1[1]-m_Y ) >EPS ) return false;
00134   if ( fabs ( v1[2]-m_Z ) >EPS ) return false;
00135 
00136   return true;
00137 };
00138 //----------------------------------------------------------------------------------------------------------
00139 inline Vector3D THIS::operator/ ( float num ) const
00140 {
00141   return Vector3D ( m_X / num, m_Y / num, m_Z / num );
00142 };
00143 //----------------------------------------------------------------------------------------------------------
00144 inline float THIS::operator [] ( const unsigned int i ) const
00145 {
00146   return ( ( float* ) this ) [i];
00147 }
00148 //----------------------------------------------------------------------------------------------------------
00149 inline float& THIS::operator [] ( const unsigned int i )
00150 {
00151   return ( ( float* ) this ) [i];
00152 }
00153 //----------------------------------------------------------------------------------------------------------
00154 inline void THIS::set ( float fx, float fy, float fz )
00155 {
00156   m_X=fx; m_Y=fy; m_Z=fz;
00157 }
00158 //----------------------------------------------------------------------------------------------------------
00159 inline void THIS::lerp ( const Vector3D& v1, const Vector3D& v2,float f )
00160 {
00161   ( *this ) =v1* ( 1-f ) +v2*f;
00162 }
00163 //----------------------------------------------------------------------------------------------------------
00164 inline float THIS::magnitude() const
00165 {
00166   return sqrtf ( m_X*m_X+m_Y*m_Y+m_Z*m_Z );
00167 }
00168 //----------------------------------------------------------------------------------------------------------
00169 //----------------------------------------------------------------------------------------------------------
00170 //----------------------------------------------------------------------------------------------------------
00171 inline Vector3D operator* ( const float n,const Vector3D& v )
00172 {
00173   return Vector3D ( v[0]*n,v[1]*n,v[2]*n );
00174 };
00175 //----------------------------------------------------------------------------------------------------------
00176 
00177 
00178 #undef THIS
00179 


robbie_architecture
Author(s): Viktor Seib
autogenerated on Mon Oct 6 2014 02:53:09