Vector3.h
Go to the documentation of this file.
00001 /*
00002  This file is part of the VRender library.
00003  Copyright (C) 2005 Cyril Soler (Cyril.Soler@imag.fr)
00004  Version 1.0.0, released on June 27, 2005.
00005 
00006  http://artis.imag.fr/Members/Cyril.Soler/VRender
00007 
00008  VRender is free software; you can redistribute it and/or modify
00009  it under the terms of the GNU General Public License as published by
00010  the Free Software Foundation; either version 2 of the License, or
00011  (at your option) any later version.
00012 
00013  VRender is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  GNU General Public License for more details.
00017 
00018  You should have received a copy of the GNU General Public License
00019  along with VRender; if not, write to the Free Software Foundation, Inc.,
00020  51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
00021 */
00022 
00023 /****************************************************************************
00024 
00025  Copyright (C) 2002-2013 Gilles Debunne. All rights reserved.
00026 
00027  This file is part of the QGLViewer library version 2.4.0.
00028 
00029  http://www.libqglviewer.com - contact@libqglviewer.com
00030 
00031  This file may be used under the terms of the GNU General Public License 
00032  versions 2.0 or 3.0 as published by the Free Software Foundation and
00033  appearing in the LICENSE file included in the packaging of this file.
00034  In addition, as a special exception, Gilles Debunne gives you certain 
00035  additional rights, described in the file GPL_EXCEPTION in this package.
00036 
00037  libQGLViewer uses dual licensing. Commercial/proprietary software must
00038  purchase a libQGLViewer Commercial License.
00039 
00040  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00041  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
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         }; // interface of Vector3
00194 }
00195 #endif // _VECTOR3_H


octovis
Author(s): Kai M. Wurm , Armin Hornung
autogenerated on Thu Feb 11 2016 23:51:20